NaCl runtime fixes
authorElijah Taylor <elijahtaylor@google.com>
Thu, 31 Jan 2013 20:04:20 +0000 (12:04 -0800)
committerIvan Maidanski <ivmai@mail.ru>
Tue, 6 Oct 2015 08:07:37 +0000 (11:07 +0300)
(Apply commit b328e88 from 'mono_libgc' branch.)

* fix compile/runtime issues caused by upstream changes
* add NaCl glibc support
* various changes to support running tests in NaCl glibc
from 'make check'

Conflicts:
* dyn_load.c
* include/private/gcconfig.h
* misc.c
* pthread_stop_world.c
* pthread_support.c

dyn_load.c
include/private/gcconfig.h
misc.c
pthread_stop_world.c
pthread_support.c

index 326bd2d..381e945 100644 (file)
@@ -52,18 +52,16 @@ STATIC GC_has_static_roots_func GC_has_static_roots = 0;
 #if (defined(DYNAMIC_LOADING) || defined(MSWIN32) || defined(MSWINCE) \
     || defined(CYGWIN32)) && !defined(PCR)
 
-#if !defined(SOLARISDL) && !defined(IRIX5) && \
-    !defined(MSWIN32) && !defined(MSWINCE) && !defined(CYGWIN32) && \
-    !(defined(ALPHA) && defined(OSF1)) && \
-    !defined(HPUX) && !(defined(LINUX) && defined(__ELF__)) && \
-    !defined(AIX) && !defined(SCO_ELF) && !defined(DGUX) && \
-    !(defined(FREEBSD) && defined(__ELF__)) && \
-    !(defined(OPENBSD) && (defined(__ELF__) || defined(M68K))) && \
-    !(defined(NETBSD) && defined(__ELF__)) && !defined(HURD) && \
-    !defined(DARWIN) && !defined(CYGWIN32)
+#if !defined(DARWIN) && !defined(SCO_ELF) && !defined(SOLARISDL) \
+    && !defined(AIX) && !defined(DGUX) && !defined(IRIX5) && !defined(HPUX) \
+    && !defined(CYGWIN32) && !defined(MSWIN32) && !defined(MSWINCE) \
+    && !(defined(ALPHA) && defined(OSF1)) \
+    && !(defined(FREEBSD) && defined(__ELF__)) \
+    && !((defined(LINUX) || defined(NACL)) && defined(__ELF__)) \
+    && !(defined(NETBSD) && defined(__ELF__)) && !defined(HURD) \
+    && !(defined(OPENBSD) && (defined(__ELF__) || defined(M68K)))
  --> We only know how to find data segments of dynamic libraries for the
- --> above.  Additional SVR4 variants might not be too
- --> hard to add.
+ --> above.  Additional SVR4 variants might not be too hard to add.
 #endif
 
 #include <stdio.h>
@@ -89,7 +87,8 @@ STATIC GC_has_static_roots_func GC_has_static_roots = 0;
 
 #if defined(SCO_ELF) || defined(DGUX) || defined(HURD) \
     || (defined(__ELF__) && (defined(LINUX) || defined(FREEBSD) \
-                             || defined(NETBSD) || defined(OPENBSD)))
+                             || defined(NACL) || defined(NETBSD) \
+                             || defined(OPENBSD)))
 # include <stddef.h>
 # if !defined(OPENBSD) && !defined(PLATFORM_ANDROID)
     /* OpenBSD does not have elf.h file; link.h below is sufficient.    */
@@ -257,7 +256,8 @@ GC_INNER void GC_register_dynamic_libraries(void)
 
 #if defined(SCO_ELF) || defined(DGUX) || defined(HURD) \
     || (defined(__ELF__) && (defined(LINUX) || defined(FREEBSD) \
-                             || defined(NETBSD) || defined(OPENBSD)))
+                             || defined(NACL) || defined(NETBSD) \
+                             || defined(OPENBSD)))
 
 #ifdef USE_PROC_FOR_LIBRARIES
 
index 3422282..2f80b3d 100644 (file)
 /* Determine the machine type: */
 # if defined(__native_client__)
 #    define NACL
-#    define I386
-#    define mach_type_known
+#    if !defined(__portable_native_client__)
+#      define I386
+#      define mach_type_known
+#    else
+       /* Here we will rely upon arch-specific defines. */
+#    endif
 # endif
 # if defined(__aarch64__)
 #    define AARCH64
 #   endif
 # endif
 
+# ifdef NACL
+#   define OS_TYPE "NACL"
+#   if defined(__GLIBC__)
+#     define DYNAMIC_LOADING
+#   endif
+#   define DATASTART ((ptr_t)0x10020000)
+    extern int _end[];
+#   define DATAEND ((ptr_t)_end)
+#   undef STACK_GRAN
+#   define STACK_GRAN 0x10000
+#   define HEURISTIC1
+#   define USE_MMAP
+#   define USE_MUNMAP
+#   define USE_MMAP_ANON
+#   undef USE_MMAP_FIXED
+#   define GETPAGESIZE() 65536
+#   define MAX_NACL_GC_THREADS 1024
+# endif
+
 # ifdef VAX
 #   define MACH_TYPE "VAX"
 #   define ALIGNMENT 4  /* Pointers are longword aligned by 4.2 C compiler */
 /* #define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff)) */
 #      define DATASTART ((ptr_t)0x10000000)
        extern int _end[];
-#      define DATAEND (_end)
+#      define DATAEND ((ptr_t)_end)
 #      undef STACK_GRAN
 #      define STACK_GRAN 0x10000
 #      define HEURISTIC1
diff --git a/misc.c b/misc.c
index cbe77ed..29938c0 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -1596,8 +1596,13 @@ void GC_printf(const char *format, ...)
 
     if (!GC_quiet) {
       GC_PRINTF_FILLBUF(buf, format);
-      if (WRITE(GC_stdout, buf, strlen(buf)) < 0)
-        ABORT("write to stdout failed");
+#     ifdef NACL
+        (void)WRITE(GC_stdout, buf, strlen(buf));
+        /* Ignore errors silently.      */
+#     else
+        if (WRITE(GC_stdout, buf, strlen(buf)) < 0)
+          ABORT("write to stdout failed");
+#     endif
     }
 }
 
@@ -1614,8 +1619,12 @@ void GC_log_printf(const char *format, ...)
     char buf[BUFSZ + 1];
 
     GC_PRINTF_FILLBUF(buf, format);
-    if (WRITE(GC_log, buf, strlen(buf)) < 0)
-      ABORT("write to GC log failed");
+#   ifdef NACL
+      (void)WRITE(GC_log, buf, strlen(buf));
+#   else
+      if (WRITE(GC_log, buf, strlen(buf)) < 0)
+        ABORT("write to GC log failed");
+#   endif
 }
 
 #ifndef GC_ANDROID_LOG
index 0dfd356..c0bc2a5 100644 (file)
@@ -769,16 +769,28 @@ GC_INNER void GC_stop_world(void)
   STATIC GC_bool GC_nacl_thread_parking_inited = FALSE;
   STATIC pthread_mutex_t GC_nacl_thread_alloc_lock = PTHREAD_MUTEX_INITIALIZER;
 
-  extern void nacl_register_gc_hooks(void (*pre)(void), void (*post)(void));
+  struct nacl_irt_blockhook {
+    int (*register_block_hooks)(void (*pre)(void), void (*post)(void));
+  };
+
+  extern size_t nacl_interface_query(const char *interface_ident,
+                                     void *table, size_t tablesize);
 
   GC_INNER void GC_nacl_initialize_gc_thread(void)
   {
     int i;
-    nacl_register_gc_hooks(nacl_pre_syscall_hook, nacl_post_syscall_hook);
+    static struct nacl_irt_blockhook gc_hook;
+
     pthread_mutex_lock(&GC_nacl_thread_alloc_lock);
     if (!EXPECT(GC_nacl_thread_parking_inited, TRUE)) {
       BZERO(GC_nacl_thread_parked, sizeof(GC_nacl_thread_parked));
       BZERO(GC_nacl_thread_used, sizeof(GC_nacl_thread_used));
+      /* TODO: replace with public 'register hook' function when        */
+      /* available from glibc.                                          */
+      nacl_interface_query("nacl-irt-blockhook-0.1",
+                           &gc_hook, sizeof(gc_hook));
+      gc_hook.register_block_hooks(nacl_pre_syscall_hook,
+                                   nacl_post_syscall_hook);
       GC_nacl_thread_parking_inited = TRUE;
     }
     GC_ASSERT(GC_nacl_num_gc_threads <= MAX_NACL_GC_THREADS);
index 558ef9c..214dc2d 100644 (file)
@@ -1542,12 +1542,6 @@ GC_API int WRAP_FUNC(pthread_detach)(pthread_t thread)
     }
     UNLOCK();
 
-#   ifdef NACL
-      /* Native Client doesn't support pthread cleanup functions, */
-      /* so cleanup the thread here.                              */
-      GC_thread_exit_proc(0);
-#   endif
-
     REAL_FUNC(pthread_exit)(retval);
   }
 #endif /* GC_PTHREAD_EXIT_ATTRIBUTE */