#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>
#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. */
#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
/* 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
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
}
}
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
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);
}
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 */