2003-11-26  Ulrich Drepper  <drepper@redhat.com>

	* sysdeps/unix/sysv/linux/kernel-features.h
	(__ASSUME_PROT_GROWSUPDOWN): Define for 2.6.1 and up.
	* sysdeps/unix/sysv/linux/dl-execstack.c: Omit compatibility code
	if __ASSUME_PROT_GROWSUPDOWN is defined.

2003-11-26  Andreas Jaeger  <aj@suse.de>

	* sysdeps/unix/sysv/linux/dl-execstack.c
	(_dl_make_stack_executable): Set dl_stack_flags always for
	success.
This commit is contained in:
Ulrich Drepper 2003-11-27 05:24:58 +00:00
parent ab18a27d54
commit 5cb48b8492
6 changed files with 57 additions and 8 deletions

View File

@ -1,3 +1,16 @@
2003-11-26 Ulrich Drepper <drepper@redhat.com>
* sysdeps/unix/sysv/linux/kernel-features.h
(__ASSUME_PROT_GROWSUPDOWN): Define for 2.6.1 and up.
* sysdeps/unix/sysv/linux/dl-execstack.c: Omit compatibility code
if __ASSUME_PROT_GROWSUPDOWN is defined.
2003-11-26 Andreas Jaeger <aj@suse.de>
* sysdeps/unix/sysv/linux/dl-execstack.c
(_dl_make_stack_executable): Set dl_stack_flags always for
success.
2003-06-22 Petter Reinholdtsen <pere@hungry.com> 2003-06-22 Petter Reinholdtsen <pere@hungry.com>
* locale/program/ld-monetary.c: Only check the first three * locale/program/ld-monetary.c: Only check the first three

View File

@ -22,7 +22,7 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "pthreadP.h" #include "pthreadP.h"
#include <shlib-compat.h>
int int
__pthread_attr_destroy (attr) __pthread_attr_destroy (attr)
@ -33,6 +33,13 @@ __pthread_attr_destroy (attr)
assert (sizeof (*attr) >= sizeof (struct pthread_attr)); assert (sizeof (*attr) >= sizeof (struct pthread_attr));
iattr = (struct pthread_attr *) attr; iattr = (struct pthread_attr *) attr;
#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_1)
/* In old struct pthread_attr, neither next nor cpuset are
present. */
if (__builtin_expect ((iattr->flags & ATTR_FLAG_OLDATTR), 0))
return 0;
#endif
/* Enqueue the attributes to the list of all known variables. */ /* Enqueue the attributes to the list of all known variables. */
if (DEBUGGING_P) if (DEBUGGING_P)
{ {

View File

@ -80,12 +80,16 @@ __pthread_attr_init_2_0 (attr)
int inheritsched; int inheritsched;
int scope; int scope;
}; };
struct pthread_attr *iattr;
/* Many elements are initialized to zero so let us do it all at /* Many elements are initialized to zero so let us do it all at
once. This also takes care of clearing the bytes which are not once. This also takes care of clearing the bytes which are not
internally used. */ internally used. */
memset (attr, '\0', sizeof (struct old_attr)); memset (attr, '\0', sizeof (struct old_attr));
iattr = (struct pthread_attr *) attr;
iattr->flags |= ATTR_FLAG_OLDATTR;
/* We cannot enqueue the attribute because that member is not in the /* We cannot enqueue the attribute because that member is not in the
old attribute structure. */ old attribute structure. */
return 0; return 0;

View File

@ -47,6 +47,7 @@ struct pthread_attr
#define ATTR_FLAG_NOTINHERITSCHED 0x0002 #define ATTR_FLAG_NOTINHERITSCHED 0x0002
#define ATTR_FLAG_SCOPEPROCESS 0x0004 #define ATTR_FLAG_SCOPEPROCESS 0x0004
#define ATTR_FLAG_STACKADDR 0x0008 #define ATTR_FLAG_STACKADDR 0x0008
#define ATTR_FLAG_OLDATTR 0x0010
/* Mutex attribute data structure. */ /* Mutex attribute data structure. */

View File

@ -23,6 +23,9 @@
#include <stdbool.h> #include <stdbool.h>
#include <stackinfo.h> #include <stackinfo.h>
#include "kernel-features.h"
extern void *__libc_stack_end; extern void *__libc_stack_end;
int int
@ -35,15 +38,20 @@ _dl_make_stack_executable (void)
/* 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 # ifdef PROT_GROWSDOWN
# if __ASSUME_PROT_GROWSUPDOWN == 0
static bool no_growsdown; static bool no_growsdown;
if (! no_growsdown) if (! no_growsdown)
# endif
{ {
if (__mprotect ((void *) page, GL(dl_pagesize), if (__mprotect ((void *) page, GL(dl_pagesize),
PROT_READ|PROT_WRITE|PROT_EXEC|PROT_GROWSDOWN) == 0) PROT_READ|PROT_WRITE|PROT_EXEC|PROT_GROWSDOWN) == 0)
return 0; goto return_success;
if (errno != EINVAL) # if __ASSUME_PROT_GROWSUPDOWN == 0
if (errno == EINVAL)
no_growsdown = true;
else
# endif
return errno; return errno;
no_growsdown = true;
} }
# endif # endif
@ -54,6 +62,7 @@ _dl_make_stack_executable (void)
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
size_t size = GL(dl_pagesize) * 8; size_t size = GL(dl_pagesize) * 8;
page = page + GL(dl_pagesize) - size; page = page + GL(dl_pagesize) - size;
while (1) while (1)
@ -78,6 +87,7 @@ _dl_make_stack_executable (void)
page += size; page += size;
} }
} }
# endif
#elif _STACK_GROWS_UP #elif _STACK_GROWS_UP
@ -86,15 +96,20 @@ _dl_make_stack_executable (void)
/* Newer Linux kernels support a flag to make our job easy. */ /* Newer Linux kernels support a flag to make our job easy. */
# ifdef PROT_GROWSUP # ifdef PROT_GROWSUP
# if __ASSUME_PROT_GROWSUPDOWN == 0
static bool no_growsup; static bool no_growsup;
if (! no_growsup) if (! no_growsup)
# endif
{ {
if (__mprotect ((void *) page, GL(dl_pagesize), if (__mprotect ((void *) page, GL(dl_pagesize),
PROT_READ|PROT_WRITE|PROT_EXEC|PROT_GROWSUP) == 0) PROT_READ|PROT_WRITE|PROT_EXEC|PROT_GROWSUP) == 0)
return 0; goto return_success;
if (errno != EINVAL) # if __ASSUME_PROT_GROWSUPDOWN == 0
if (errno == EINVAL)
no_growsup = true;
else
# endif
return errno; return errno;
no_growsup = true;
} }
# endif # endif
@ -105,6 +120,7 @@ _dl_make_stack_executable (void)
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 GROWSUP mapping to higher pages. */ so as to have extended the GROWSUP mapping to higher pages. */
# if __ASSUME_PROT_GROWSUPDOWN == 0
size_t size = GL(dl_pagesize) * 8; size_t size = GL(dl_pagesize) * 8;
while (1) while (1)
{ {
@ -127,11 +143,13 @@ _dl_make_stack_executable (void)
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
return_success:
/* Remember that we changed the permission. */ /* Remember that we changed the permission. */
GL(dl_stack_flags) |= PF_X; GL(dl_stack_flags) |= PF_X;

View File

@ -376,6 +376,12 @@
/* The fixed version of the posix_fadvise64 syscall appeared in /* The fixed version of the posix_fadvise64 syscall appeared in
2.6.0-test3. At least for x86. */ 2.6.0-test3. At least for x86. */
#if __LINUX_KERNEL_VERSION >= 132609 && (defined __i386__) #if __LINUX_KERNEL_VERSION >= 132609 && defined __i386__
# define __ASSUME_FADVISE64_64_SYSCALL 1 # define __ASSUME_FADVISE64_64_SYSCALL 1
#endif #endif
/* The PROT_GROWSDOWN/PROT_GROWSUP flags were introduced in the 2.6.0-test
series. */
#if __LINUX_KERNEL_VERSION >= 132609
# define __ASSUME_PROT_GROWSUPDOWN 1
#endif