From e61fa5f9f270db9073abef2fc2bf573657b246e1 Mon Sep 17 00:00:00 2001 From: ivmai Date: Sat, 14 Aug 2010 13:59:21 +0000 Subject: [PATCH] 2010-08-14 Ivan Maidanski * os_dep.c (os2_alloc): Don't set PAG_EXECUTE unless pages_executable is on. * os_dep.c (os2_alloc): Add FIXME (for recursion). * os_dep.c (UNPROTECT): Abort with a more informative message if pages_executable is on ("mprotect" case). * os_dep.c (PROTECT, UNPROTECT): Set VM_PROT_EXEC if pages_executable is on (Darwin case). * pthread_support.c (GC_init_real_syms): Abort with an informative message if libgc is linked after libpthread. --- ChangeLog | 12 ++++++++++++ os_dep.c | 16 +++++++++++----- pthread_support.c | 5 +++++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8cbf0e92..6479d5b8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2010-08-14 Ivan Maidanski + + * os_dep.c (os2_alloc): Don't set PAG_EXECUTE unless + pages_executable is on. + * os_dep.c (os2_alloc): Add FIXME (for recursion). + * os_dep.c (UNPROTECT): Abort with a more informative message if + pages_executable is on ("mprotect" case). + * os_dep.c (PROTECT, UNPROTECT): Set VM_PROT_EXEC if + pages_executable is on (Darwin case). + * pthread_support.c (GC_init_real_syms): Abort with an informative + message if libgc is linked after libpthread. + 2010-08-14 Ivan Maidanski * dyn_load.c (GC_register_dynlib_callback): Adjust "start" pointer diff --git a/os_dep.c b/os_dep.c index 1a0f794f..4ff20b12 100644 --- a/os_dep.c +++ b/os_dep.c @@ -2114,11 +2114,13 @@ void * os2_alloc(size_t bytes) { void * result; - if (DosAllocMem(&result, bytes, PAG_EXECUTE | PAG_READ | - PAG_WRITE | PAG_COMMIT) + if (DosAllocMem(&result, bytes, (PAG_READ | PAG_WRITE | PAG_COMMIT) + | (pages_executable ? PAG_EXECUTE : 0)) != NO_ERROR) { return(0); } + /* FIXME: What's the purpose of this recursion? (Probably, if */ + /* DosAllocMem returns memory at 0 address then just retry once.) */ if (result == 0) return(os2_alloc(bytes)); return(result); } @@ -2864,7 +2866,9 @@ GC_INNER void GC_remove_protection(struct hblk *h, word nblocks, if (mprotect((caddr_t)(addr), (size_t)(len), \ (PROT_READ | PROT_WRITE) \ | (pages_executable ? PROT_EXEC : 0)) < 0) { \ - ABORT("un-mprotect failed"); \ + ABORT(pages_executable ? "un-mprotect executable page" \ + " failed (probably disabled by OS)" : \ + "un-mprotect failed"); \ } # undef IGNORE_PAGES_EXECUTABLE @@ -2877,12 +2881,14 @@ GC_INNER void GC_remove_protection(struct hblk *h, word nblocks, STATIC mach_port_t GC_task_self = 0; # define PROTECT(addr,len) \ if(vm_protect(GC_task_self,(vm_address_t)(addr),(vm_size_t)(len), \ - FALSE,VM_PROT_READ) != KERN_SUCCESS) { \ + FALSE, VM_PROT_READ \ + | (pages_executable ? VM_PROT_EXEC : 0)) != KERN_SUCCESS) { \ ABORT("vm_protect (PROTECT) failed"); \ } # define UNPROTECT(addr,len) \ if(vm_protect(GC_task_self,(vm_address_t)(addr),(vm_size_t)(len), \ - FALSE,VM_PROT_READ|VM_PROT_WRITE) != KERN_SUCCESS) { \ + FALSE, (VM_PROT_READ | VM_PROT_WRITE) \ + | (pages_executable ? VM_PROT_EXEC : 0)) != KERN_SUCCESS) { \ ABORT("vm_protect (UNPROTECT) failed"); \ } # else diff --git a/pthread_support.c b/pthread_support.c index 87bb09b5..95fa15ee 100644 --- a/pthread_support.c +++ b/pthread_support.c @@ -231,6 +231,11 @@ GC_INNER unsigned long GC_lock_holder = NO_THREAD; # endif REAL_FUNC(pthread_create) = (GC_pthread_create_t) dlsym(dl_handle, "pthread_create"); +# ifdef RTLD_NEXT + if (REAL_FUNC(pthread_create) == 0) + ABORT("pthread_create not found" + " (probably -lgc is specified after -lpthread)"); +# endif REAL_FUNC(pthread_sigmask) = (GC_pthread_sigmask_t) dlsym(dl_handle, "pthread_sigmask"); REAL_FUNC(pthread_join) = (GC_pthread_join_t) -- 2.40.0