summaryrefslogtreecommitdiff
path: root/gcc/config/darwin.h
diff options
context:
space:
mode:
authorgeoffk <geoffk@138bc75d-0d04-0410-961f-82ee72b054a4>2006-09-28 07:03:59 +0000
committergeoffk <geoffk@138bc75d-0d04-0410-961f-82ee72b054a4>2006-09-28 07:03:59 +0000
commit6a53b02d23e554abfdbfbcaf2c0bd124e7ec47e9 (patch)
tree6ac634501bdaf2ff88e85b2b5941422ceb3a20fb /gcc/config/darwin.h
parent7e37d01e2e1f7f1546bffe6b4e0240831fcf6452 (diff)
downloadgcc-6a53b02d23e554abfdbfbcaf2c0bd124e7ec47e9.tar.gz
* config/darwin.h (ENABLE_EXECUTE_STACK): New, use getpagesize not
__sysctl. * config/rs6000/darwin.h (ENABLE_EXECUTE_STACK): Remove. * config/i386/darwin.h (ENABLE_EXECUTE_STACK): Remove. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@117274 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/config/darwin.h')
-rw-r--r--gcc/config/darwin.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h
index 328754e8aee..6817dc83442 100644
--- a/gcc/config/darwin.h
+++ b/gcc/config/darwin.h
@@ -886,4 +886,42 @@ void add_framework_path (char *);
#define TARGET_ASM_OUTPUT_ANCHOR NULL
#endif
+/* Attempt to turn on execute permission for the stack. This may be
+ used by INITIALIZE_TRAMPOLINE of the target needs it (that is,
+ if the target machine can change execute permissions on a page).
+
+ There is no way to query the execute permission of the stack, so
+ we always issue the mprotect() call.
+
+ Unfortunately it is not possible to make this namespace-clean.
+
+ Also note that no errors should be emitted by this code; it is
+ considered dangerous for library calls to send messages to
+ stdout/stderr. */
+
+#define ENABLE_EXECUTE_STACK \
+extern void __enable_execute_stack (void *); \
+void \
+__enable_execute_stack (void *addr) \
+{ \
+ extern int mprotect (void *, size_t, int); \
+ extern int getpagesize (void); \
+ static int size; \
+ static long mask; \
+ \
+ char *page, *end; \
+ \
+ if (size == 0) \
+ { \
+ size = getpagesize(); \
+ mask = ~((long) size - 1); \
+ } \
+ \
+ page = (char *) (((long) addr) & mask); \
+ end = (char *) ((((long) (addr + (TARGET_64BIT ? 48 : 40))) & mask) + size); \
+ \
+ /* 7 == PROT_READ | PROT_WRITE | PROT_EXEC */ \
+ (void) mprotect (page, end - page, 7); \
+}
+
#endif /* CONFIG_DARWIN_H */