patch-gcc_config_exec-stack_h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. $OpenBSD: patch-gcc_config_exec-stack_h,v 1.1.1.1 2014/06/26 16:30:17 pascal Exp $
  2. --- gcc/config/exec-stack.h.orig Wed Oct 18 13:49:09 2006
  3. +++ gcc/config/exec-stack.h Wed Oct 18 13:49:04 2006
  4. @@ -0,0 +1,40 @@
  5. +/* Enable stack execute around trampoline address.
  6. + Copyright (C) 2002 Free Software Foundation, Inc.
  7. +
  8. +This file is part of GNU CC.
  9. +
  10. +GNU CC is free software; you can redistribute it and/or modify
  11. +it under the terms of the GNU General Public License as published by
  12. +the Free Software Foundation; either version 2, or (at your option)
  13. +any later version.
  14. +
  15. +GNU CC is distributed in the hope that it will be useful,
  16. +but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. +GNU General Public License for more details.
  19. +
  20. +You should have received a copy of the GNU General Public License
  21. +along with GNU CC; see the file COPYING. If not, write to
  22. +the Free Software Foundation, 59 Temple Place - Suite 330,
  23. +Boston, MA 02111-1307, USA. */
  24. +
  25. +#undef FINALIZE_TRAMPOLINE
  26. +#define FINALIZE_TRAMPOLINE(TRAMP) \
  27. + emit_library_call(gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"), \
  28. + 0, VOIDmode, 1, memory_address (SImode, (TRAMP)), Pmode)
  29. +
  30. +#undef TRANSFER_FROM_TRAMPOLINE
  31. +#define TRANSFER_FROM_TRAMPOLINE \
  32. +extern void __enable_execute_stack (void *); \
  33. +void \
  34. +__enable_execute_stack (addr) \
  35. + void *addr; \
  36. +{ \
  37. + long size = getpagesize (); \
  38. + long mask = ~(size-1); \
  39. + char *page = (char *) (((long) addr) & mask); \
  40. + char *end = (char *) ((((long) (addr + TRAMPOLINE_SIZE)) & mask) + size); \
  41. + \
  42. + if (mprotect (page, end - page, PROT_READ | PROT_WRITE | PROT_EXEC) < 0) \
  43. + perror ("mprotect of trampoline code"); \
  44. +}