* sysdeps/unix/sysv/linux/dl-execstack.c
	(_dl_make_stack_executable): Remove some duplication.
This commit is contained in:
Ulrich Drepper 2004-09-21 02:30:50 +00:00
parent 3c12b91ade
commit 1658cb8036
2 changed files with 20 additions and 46 deletions

View File

@ -1,5 +1,8 @@
2004-09-20 Ulrich Drepper <drepper@redhat.com> 2004-09-20 Ulrich Drepper <drepper@redhat.com>
* sysdeps/unix/sysv/linux/dl-execstack.c
(_dl_make_stack_executable): Remove some duplication.
* nscd/nscd.c (options): Mark S option as hidden. * nscd/nscd.c (options): Mark S option as hidden.
(parse_opt): When S option is used, print warning message. (parse_opt): When S option is used, print warning message.
* nscd/grpcache.c (adgrptbyX): Don't handle secure mode. * nscd/grpcache.c (adgrptbyX): Don't handle secure mode.

View File

@ -45,25 +45,24 @@ _dl_make_stack_executable (void **stack_endp)
|| __builtin_expect (*stack_endp != __libc_stack_end, 0)) || __builtin_expect (*stack_endp != __libc_stack_end, 0))
return EPERM; return EPERM;
#if _STACK_GROWS_DOWN
/* Newer Linux kernels support a flag to make our job easy. */ /* Newer Linux kernels support a flag to make our job easy. */
# ifdef PROT_GROWSDOWN #if defined PROT_GROWSDOWN || defined PROT_GROWSUP
# if __ASSUME_PROT_GROWSUPDOWN == 0 # if __ASSUME_PROT_GROWSUPDOWN == 0
static bool no_growsdown; static bool no_growsupdown;
if (! no_growsdown) if (! no_growsupdown)
# endif # endif
{ {
if (__builtin_expect (__mprotect ((void *) page, GLRO(dl_pagesize), if (__builtin_expect (__mprotect ((void *) page, GLRO(dl_pagesize),
__stack_prot) == 0, 1)) __stack_prot) == 0, 1))
goto return_success; goto return_success;
# if __ASSUME_PROT_GROWSUPDOWN == 0 # if __ASSUME_PROT_GROWSUPDOWN == 0
if (errno == EINVAL) if (errno == EINVAL)
no_growsdown = true; no_growsupdown = true;
else else
# endif # endif
return errno; return errno;
} }
# endif #endif
/* There is always a hole in the address space below the bottom of the /* There is always a hole in the address space below the bottom of the
stack. So when we make an mprotect call that starts below the bottom stack. So when we make an mprotect call that starts below the bottom
@ -72,8 +71,10 @@ _dl_make_stack_executable (void **stack_endp)
We start with a random guess at how deep the stack might have gotten We start with a random guess at how deep the stack might have gotten
so as to have extended the GROWSDOWN mapping to lower pages. */ so as to have extended the GROWSDOWN mapping to lower pages. */
# if __ASSUME_PROT_GROWSUPDOWN == 0 #if __ASSUME_PROT_GROWSUPDOWN == 0
size_t size = GLRO(dl_pagesize) * 8; size_t size = GLRO(dl_pagesize) * 8;
# if _STACK_GROWS_DOWN
page = page + GLRO(dl_pagesize) - size; page = page + GLRO(dl_pagesize) - size;
while (1) while (1)
{ {
@ -97,41 +98,11 @@ _dl_make_stack_executable (void **stack_endp)
page += size; page += size;
} }
} }
# endif
#elif _STACK_GROWS_UP # elif _STACK_GROWS_UP
/* Newer Linux kernels support a flag to make our job easy. */
# ifdef PROT_GROWSUP
# if __ASSUME_PROT_GROWSUPDOWN == 0
static bool no_growsup;
if (! no_growsup)
# endif
{
if (__mprotect ((void *) page, GLRO(dl_pagesize),
PROT_READ|PROT_WRITE|PROT_EXEC|PROT_GROWSUP) == 0)
goto return_success;
# if __ASSUME_PROT_GROWSUPDOWN == 0
if (errno == EINVAL)
no_growsup = true;
else
# endif
return errno;
}
# endif
/* There is always a hole in the address space above the top of the
stack. So when we make an mprotect call that spans past the top
of the stack, it will include the hole and fail with ENOMEM.
We start with a random guess at how deep the stack might have gotten
so as to have extended the GROWSUP mapping to higher pages. */
# if __ASSUME_PROT_GROWSUPDOWN == 0
size_t size = GLRO(dl_pagesize) * 8;
while (1) while (1)
{ {
if (__mprotect ((void *) page, size, if (__mprotect ((void *) page, size, __stack_prot & ~PROT_GROWSUP) == 0)
PROT_READ|PROT_WRITE|PROT_EXEC) == 0)
/* We got this chunk changed; loop to do another chunk below. */ /* We got this chunk changed; loop to do another chunk below. */
page += size; page += size;
else else
@ -149,10 +120,10 @@ _dl_make_stack_executable (void **stack_endp)
size /= 2; size /= 2;
} }
} }
# endif
#else # else
# error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP" # error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP"
# endif
#endif #endif
return_success: return_success: