2005-08-20 Carlos Alberto Cortez <calberto.cortez@gmail.com>
[mono.git] / libgc / os_dep.c
index 0e300f840eb20798b72d6af6fbab9dd8b1cdb4cd..e224af79d833c81125fccb8ee865ed8948f47486 100644 (file)
 # include <sys/uio.h>
 # include <malloc.h>   /* for locking */
 #endif
-#if defined(USE_MMAP) || defined(USE_MUNMAP)
+#if defined(USE_MUNMAP)
 # ifndef USE_MMAP
     --> USE_MUNMAP requires USE_MMAP
 # endif
+#endif
+#if defined(USE_MMAP) || defined(USE_MUNMAP) || defined(FALLBACK_TO_MMAP)
 # include <sys/types.h>
 # include <sys/mman.h>
 # include <sys/stat.h>
@@ -600,7 +602,7 @@ word GC_page_size;
 
 # else
 #   if defined(MPROTECT_VDB) || defined(PROC_VDB) || defined(USE_MMAP) \
-       || defined(USE_MUNMAP)
+       || defined(USE_MUNMAP) || defined(FALLBACK_TO_MMAP)
        void GC_setpagesize()
        {
            GC_page_size = GETPAGESIZE();
@@ -700,10 +702,10 @@ ptr_t GC_get_stack_base()
 #   endif
 
 #   if defined(SUNOS5SIGS) || defined(IRIX5) || defined(OSF1) \
-    || defined(HURD) || defined(NETBSD)
+    || defined(HURD) || defined(NETBSD) || defined(FREEBSD)
        static struct sigaction old_segv_act;
 #      if defined(_sigargs) /* !Irix6.x */ || defined(HPUX) \
-       || defined(HURD) || defined(NETBSD)
+       || defined(HURD) || defined(NETBSD) || defined(FREEBSD)
            static struct sigaction old_bus_act;
 #      endif
 #   else
@@ -718,7 +720,7 @@ ptr_t GC_get_stack_base()
 #   endif
     {
 #      if defined(SUNOS5SIGS) || defined(IRIX5)  \
-        || defined(OSF1) || defined(HURD) || defined(NETBSD)
+        || defined(OSF1) || defined(HURD) || defined(NETBSD) || defined(FREEBSD)
          struct sigaction      act;
 
          act.sa_handler        = h;
@@ -738,7 +740,7 @@ ptr_t GC_get_stack_base()
 #        else
                (void) sigaction(SIGSEGV, &act, &old_segv_act);
 #              if defined(IRIX5) && defined(_sigargs) /* Irix 5.x, not 6.x */ \
-                  || defined(HPUX) || defined(HURD) || defined(NETBSD)
+                  || defined(HPUX) || defined(HURD) || defined(NETBSD) || defined(FREEBSD)
                    /* Under Irix 5.x or HP/UX, we may get SIGBUS.      */
                    /* Pthreads doesn't exist under Irix 5.x, so we     */
                    /* don't have to worry in the threads case.         */
@@ -774,10 +776,10 @@ ptr_t GC_get_stack_base()
     void GC_reset_fault_handler()
     {
 #       if defined(SUNOS5SIGS) || defined(IRIX5) \
-          || defined(OSF1) || defined(HURD) || defined(NETBSD)
+          || defined(OSF1) || defined(HURD) || defined(NETBSD) || defined(FREEBSD)
          (void) sigaction(SIGSEGV, &old_segv_act, 0);
 #        if defined(IRIX5) && defined(_sigargs) /* Irix 5.x, not 6.x */ \
-            || defined(HPUX) || defined(HURD) || defined(NETBSD)
+            || defined(HPUX) || defined(HURD) || defined(NETBSD) || defined(FREEBSD)
              (void) sigaction(SIGBUS, &old_bus_act, 0);
 #        endif
 #       else
@@ -939,6 +941,7 @@ ptr_t GC_get_stack_base()
     /* since the correct value of __libc_stack_end never       */
     /* becomes visible to us.  The second test works around    */
     /* this.                                                   */  
+#if USE_LIBC_PRIVATE_SYMBOLS
       if (0 != &__libc_stack_end && 0 != __libc_stack_end ) {
 #       ifdef IA64
          /* Some versions of glibc set the address 16 bytes too        */
@@ -951,6 +954,7 @@ ptr_t GC_get_stack_base()
          return __libc_stack_end;
 #      endif
       }
+#endif
     f = open("/proc/self/stat", O_RDONLY);
     if (f < 0 || STAT_READ(f, stat_buf, STAT_BUF_SIZE) < 2 * STAT_SKIP) {
        ABORT("Couldn't read /proc/self/stat");
@@ -1533,7 +1537,7 @@ word bytes;
 
 #else  /* Not RS6000 */
 
-#if defined(USE_MMAP) || defined(USE_MUNMAP)
+#if defined(USE_MMAP) || defined(USE_MUNMAP) || defined(FALLBACK_TO_MMAP)
 
 #ifdef USE_MMAP_FIXED
 #   define GC_MMAP_FLAGS MAP_FIXED | MAP_PRIVATE
@@ -1557,14 +1561,18 @@ word bytes;
 
 #endif /* defined(USE_MMAP) || defined(USE_MUNMAP) */
 
-#if defined(USE_MMAP)
+#if defined(USE_MMAP) || defined(FALLBACK_TO_MMAP)
 /* Tested only under Linux, IRIX5 and Solaris 2 */
 
 #ifndef HEAP_START
 #   define HEAP_START 0
 #endif
 
+#ifdef FALLBACK_TO_MMAP
+static ptr_t GC_unix_get_mem_mmap(bytes)
+#else
 ptr_t GC_unix_get_mem(bytes)
+#endif
 word bytes;
 {
     void *result;
@@ -1601,7 +1609,10 @@ word bytes;
     return((ptr_t)result);
 }
 
-#else /* Not RS6000, not USE_MMAP */
+#endif
+
+#ifndef USE_MMAP
+
 ptr_t GC_unix_get_mem(bytes)
 word bytes;
 {
@@ -1620,7 +1631,13 @@ word bytes;
         if((ptr_t)sbrk(GC_page_size - lsbs) == (ptr_t)(-1)) return(0);
     }
     result = (ptr_t)sbrk((SBRK_ARG_T)bytes);
-    if (result == (ptr_t)(-1)) result = 0;
+    if (result == (ptr_t)(-1)) {
+#ifdef FALLBACK_TO_MMAP
+               result = GC_unix_get_mem_mmap (bytes);
+#else
+               result = 0;
+#endif
+       }
   }
 # ifdef IRIX5
     __UNLOCK_MALLOC();
@@ -2195,7 +2212,7 @@ GC_bool is_ptrfree;
     /* Using vm_protect (mach syscall) over mprotect (BSD syscall) seems to
        decrease the likelihood of some of the problems described below. */
     #include <mach/vm_map.h>
-    extern mach_port_t GC_task_self;
+    static mach_port_t GC_task_self;
     #define PROTECT(addr,len) \
         if(vm_protect(GC_task_self,(vm_address_t)(addr),(vm_size_t)(len), \
                 FALSE,VM_PROT_READ) != KERN_SUCCESS) { \