2010-08-14 Ivan Maidanski <ivmai@mail.ru>
authorivmai <ivmai>
Sat, 14 Aug 2010 13:59:21 +0000 (13:59 +0000)
committerIvan Maidanski <ivmai@mail.ru>
Tue, 26 Jul 2011 17:06:54 +0000 (21:06 +0400)
* 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
os_dep.c
pthread_support.c

index 8cbf0e9..6479d5b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2010-08-14  Ivan Maidanski <ivmai@mail.ru>
 
+       * 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 <ivmai@mail.ru>
+
        * dyn_load.c (GC_register_dynlib_callback): Adjust "start" pointer
        for 64-bit targets.
        * pthread_support.c (start_mark_threads): Expand PTHREAD_CREATE
index 1a0f794..4ff20b1 100644 (file)
--- 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
index 87bb09b..95fa15e 100644 (file)
@@ -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)