Author: kib Date: Sat Jan 8 17:13:43 2011 New Revision: 217154 URL: http://svn.freebsd.org/changeset/base/217154
Log: Implement __pthread_map_stacks_exec() callback for libc, to change the stack protection to allow execution for single-threaded processes. Modified: head/lib/libc/gen/Symbol.map head/lib/libc/gen/dlfcn.c head/lib/libc/gen/elf_utils.c Modified: head/lib/libc/gen/Symbol.map ============================================================================== --- head/lib/libc/gen/Symbol.map Sat Jan 8 17:11:49 2011 (r217153) +++ head/lib/libc/gen/Symbol.map Sat Jan 8 17:13:43 2011 (r217154) @@ -453,6 +453,7 @@ FBSDprivate_1.0 { _rtld_atfork_pre; _rtld_atfork_post; _rtld_error; /* for private use */ + _rtld_get_stack_prot; _rtld_thread_init; /* for private use */ __elf_phdr_match_addr; _err; @@ -499,4 +500,5 @@ FBSDprivate_1.0 { _libc_sem_getvalue_compat; __elf_aux_vector; + __pthread_map_stacks_exec; }; Modified: head/lib/libc/gen/dlfcn.c ============================================================================== --- head/lib/libc/gen/dlfcn.c Sat Jan 8 17:11:49 2011 (r217153) +++ head/lib/libc/gen/dlfcn.c Sat Jan 8 17:13:43 2011 (r217154) @@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$"); /* * Linkage to services provided by the dynamic linker. */ +#include <sys/mman.h> #include <dlfcn.h> #include <link.h> #include <stddef.h> @@ -165,3 +166,12 @@ _rtld_addr_phdr(const void *addr, struct return (0); } + +#pragma weak _rtld_get_stack_prot +int +_rtld_get_stack_prot(void) +{ + + return (PROT_EXEC | PROT_READ | PROT_WRITE); +} + Modified: head/lib/libc/gen/elf_utils.c ============================================================================== --- head/lib/libc/gen/elf_utils.c Sat Jan 8 17:11:49 2011 (r217153) +++ head/lib/libc/gen/elf_utils.c Sat Jan 8 17:13:43 2011 (r217154) @@ -26,7 +26,12 @@ * $FreeBSD$ */ +#include <sys/types.h> +#include <sys/mman.h> +#include <sys/resource.h> +#include <sys/sysctl.h> #include <link.h> +#include <stddef.h> int __elf_phdr_match_addr(struct dl_phdr_info *phdr_info, void *addr) @@ -45,3 +50,25 @@ __elf_phdr_match_addr(struct dl_phdr_inf } return (i != phdr_info->dlpi_phnum); } + +#pragma weak __pthread_map_stacks_exec +void +__pthread_map_stacks_exec(void) +{ + int mib[2]; + struct rlimit rlim; + u_long usrstack; + size_t len; + + mib[0] = CTL_KERN; + mib[1] = KERN_USRSTACK; + len = sizeof(usrstack); + if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), &usrstack, &len, NULL, 0) + == -1) + return; + if (getrlimit(RLIMIT_STACK, &rlim) == -1) + return; + mprotect((void *)(uintptr_t)(usrstack - rlim.rlim_cur), + rlim.rlim_cur, _rtld_get_stack_prot()); +} + _______________________________________________ svn-src-head@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"