darwin.h (ENABLE_EXECUTE_STACK): New, use getpagesize not __sysctl.

* 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.

From-SVN: r117274
This commit is contained in:
Geoffrey Keating 2006-09-28 07:03:59 +00:00 committed by Geoffrey Keating
parent f3ed85f6eb
commit c6c621d415
4 changed files with 45 additions and 94 deletions

View File

@ -1,3 +1,10 @@
2006-09-27 Geoffrey Keating <geoffk@apple.com>
* 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.
2006-09-28 Kaz Kojima <kkojima@gcc.gnu.org>
* config/sh/sh.md (divsi_inv_m0): Remove unused variable.

View File

@ -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 */

View File

@ -204,53 +204,6 @@ extern void darwin_x86_file_end (void);
: (n) >= 11 && (n) <= 18 ? (n) + 1 \
: (n))
/* 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.
Note that we go out of our way to use namespace-non-invasive calls
here. Unfortunately, there is no libc-internal name for mprotect().
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 __sysctl (int *, unsigned int, void *, size_t *, \
void *, size_t); \
\
static int size; \
static long mask; \
\
char *page, *end; \
\
if (size == 0) \
{ \
int mib[2]; \
size_t len; \
\
mib[0] = 6; /* CTL_HW */ \
mib[1] = 7; /* HW_PAGESIZE */ \
len = sizeof (size); \
(void) __sysctl (mib, 2, &size, &len, NULL, 0); \
mask = ~((long) size - 1); \
} \
\
page = (char *) (((long) addr) & mask); \
end = (char *) ((((long) (addr + TRAMPOLINE_SIZE)) & mask) + size); \
\
/* 7 == PROT_READ | PROT_WRITE | PROT_EXEC */ \
(void) mprotect (page, end - page, 7); \
}
#undef REGISTER_TARGET_PRAGMAS
#define REGISTER_TARGET_PRAGMAS() DARWIN_REGISTER_TARGET_PRAGMAS()

View File

@ -441,50 +441,3 @@ do { \
(TARGET_64BIT \
|| (darwin_macosx_version_min \
&& strverscmp (darwin_macosx_version_min, "10.3") >= 0))
/* 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.
Note that we go out of our way to use namespace-non-invasive calls
here. Unfortunately, there is no libc-internal name for mprotect().
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 __sysctl (int *, unsigned int, void *, size_t *, \
void *, size_t); \
\
static int size; \
static long mask; \
\
char *page, *end; \
\
if (size == 0) \
{ \
int mib[2]; \
size_t len; \
\
mib[0] = 6; /* CTL_HW */ \
mib[1] = 7; /* HW_PAGESIZE */ \
len = sizeof (size); \
(void) __sysctl (mib, 2, &size, &len, NULL, 0); \
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); \
}