From: Elijah Taylor Date: Thu, 31 Jan 2013 20:04:20 +0000 (-0800) Subject: NaCl runtime fixes X-Git-Tag: gc7_6_0~126 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9738a14;p=gc NaCl runtime fixes (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 --- diff --git a/dyn_load.c b/dyn_load.c index 326bd2de..381e945a 100644 --- a/dyn_load.c +++ b/dyn_load.c @@ -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 @@ -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 # 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 diff --git a/include/private/gcconfig.h b/include/private/gcconfig.h index 34222820..2f80b3d0 100644 --- a/include/private/gcconfig.h +++ b/include/private/gcconfig.h @@ -93,8 +93,12 @@ /* 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 @@ -1046,6 +1050,25 @@ # 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 */ @@ -1294,7 +1317,7 @@ /* #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 cbe77edb..29938c0c 100644 --- 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 diff --git a/pthread_stop_world.c b/pthread_stop_world.c index 0dfd3563..c0bc2a5e 100644 --- a/pthread_stop_world.c +++ b/pthread_stop_world.c @@ -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); diff --git a/pthread_support.c b/pthread_support.c index 558ef9ca..214dc2da 100644 --- a/pthread_support.c +++ b/pthread_support.c @@ -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 */