summaryrefslogtreecommitdiff
path: root/os_dep.c
diff options
context:
space:
mode:
authorivmai <ivmai>2011-02-20 11:54:32 +0100
committerIvan Maidanski <ivmai@mail.ru>2011-07-26 19:06:56 +0200
commitbd86ef8b64d8a1db388ee8963c54af411e8a226d (patch)
tree3a4fc782c645b694033bf6ea8b5e7374d8a8f39f /os_dep.c
parenteb7c49d700ec28f32c8df663907966d10838ce4f (diff)
2011-02-20 Ivan Maidanski <ivmai@mail.ru> (mostly really Elijah Taylor)
* gc_dlopen.c: Empty unit for NaCl. * os_dep.c: Include fcntl.h for NaCl. * os_dep.c (GC_get_main_stack_base): Ignore USE_GET_STACKBASE_FOR_MAIN macro for NaCl. * os_dep.c (GC_get_stack_base): Return GC_UNIMPLEMENTED for NaCl. * os_dep.c (GC_remap): Use mmap (instead of mprotect) for NaCl. * pthread_start.c (GC_inner_start_routine): Don't invoke pthread_cleanup_push/pop for NaCl. * pthread_stop_world.c (GC_nacl_num_gc_threads, GC_nacl_thread_idx, GC_nacl_park_threads_now, GC_nacl_thread_parker, GC_nacl_gc_thread_self, GC_nacl_thread_parked, GC_nacl_thread_used, GC_nacl_thread_parking_inited, GC_nacl_thread_alloc_lock): New variable (fo NaCl only). * pthread_stop_world.c (GC_suspend_handler): Reformat the code. * pthread_stop_world.c (GC_remove_allowed_signals, suspend_handler_mask, GC_stop_count, GC_world_is_stopped, GC_retry_signals, SIG_THR_RESTART, GC_suspend_ack_sem, GC_restart_ack_sem, GC_suspend_handler_inner, GC_suspend_handler, GC_restart_handler): Don't define for NaCl. * pthread_support.c (GC_get_nprocs): Ditto. * include/private/gc_priv.h (SIG_SUSPEND): Ditto. * include/private/gcconfig.h (LINUX): Ditto. * pthread_stop_world.c (GC_push_all_stacks): Push register storage for NaCl. * pthread_stop_world.c (GC_suspend_all, GC_stop_world, GC_start_world): Implement for NaCl. * pthread_stop_world.c (GC_stop_world): Don't define unused "i" local variable for OpenBSD (and NaCl). * pthread_stop_world.c (NACL_STORE_REGS): New macro definition for NaCl. * pthread_stop_world.c (nacl_pre_syscall_hook, __nacl_suspend_thread_if_needed, nacl_post_syscall_hook, GC_nacl_initialize_gc_thread, GC_nacl_shutdown_gc_thread): New function (for NaCl only). * pthread_stop_world.c (GC_stop_init): Empty for NaCl. * pthread_support.c (pthread_cancel, pthread_sigmask): Don't redirect for NaCl. * include/gc_pthread_redirects.h (pthread_cancel, pthread_sigmask): Ditto. * pthread_support.c (GC_nacl_initialize_gc_thread, GC_nacl_shutdown_gc_thread): New internal prototype (NaCl only). * pthread_support.c (GC_new_thread, GC_delete_thread): Initialize and shutdown thread for NaCl. * pthread_support.c (GC_thr_init): Call sysconf for NaCl. * pthread_support.c (GC_pthread_exit): Call GC_thread_exit_proc for NaCl. * include/gc.h: Don't include features.h for NaCl. * include/gc_pthread_redirects.h (GC_PTHREAD_CONST): New macro. * include/gc_pthread_redirects.h (GC_pthread_create): Use GC_PTHREAD_CONST instead of const. * win32_threads.c (GC_pthread_create): Ditto. * pthread_support.c (GC_pthread_create_t, GC_pthread_create, pthread_create): Ditto. * include/private/gcconfig.h (NACL): Recognize NaCl. * include/private/gcconfig.h (GC_LINUX_THREADS): Valid for NaCl. * include/private/pthread_stop_world.h (thread_stop_info): Add reg_storage member; define NACL_GC_REG_STORAGE_SIZE macro (for NaCl only). * include/private/pthread_support.h (GC_nacl_gc_thread_self): Declare internal variable (for NaCl only).
Diffstat (limited to 'os_dep.c')
-rw-r--r--os_dep.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/os_dep.c b/os_dep.c
index e52661f..768ab45 100644
--- a/os_dep.c
+++ b/os_dep.c
@@ -61,7 +61,7 @@
# include <signal.h>
#endif
-#if defined(UNIX_LIKE) || defined(CYGWIN32)
+#if defined(UNIX_LIKE) || defined(CYGWIN32) || defined(NACL)
# include <fcntl.h>
#endif
@@ -1143,7 +1143,7 @@ GC_INNER word GC_page_size = 0;
ptr_t GC_get_main_stack_base(void)
{
ptr_t result; /* also used as "dummy" to get the approx. sp value */
-# if defined(LINUX) && defined(USE_GET_STACKBASE_FOR_MAIN)
+# if defined(LINUX) && defined(USE_GET_STACKBASE_FOR_MAIN) && !defined(NACL)
pthread_attr_t attr;
void *stackaddr;
size_t size;
@@ -1208,7 +1208,8 @@ GC_INNER word GC_page_size = 0;
}
#endif /* !AMIGA, !BEOS, !OPENBSD, !OS2, !Windows */
-#if defined(GC_LINUX_THREADS) && !defined(HAVE_GET_STACK_BASE)
+#if defined(GC_LINUX_THREADS) && !defined(HAVE_GET_STACK_BASE) \
+ && !defined(NACL)
# include <pthread.h>
/* extern int pthread_getattr_np(pthread_t, pthread_attr_t *); */
@@ -2432,10 +2433,24 @@ GC_INNER void GC_remap(ptr_t start, size_t bytes)
# else
/* It was already remapped with PROT_NONE. */
int result;
-
if (0 == start_addr) return;
- result = mprotect(start_addr, len, (PROT_READ | PROT_WRITE)
- | (pages_executable ? PROT_EXEC : 0));
+
+# ifndef NACL
+ result = mprotect(start_addr, len, (PROT_READ | PROT_WRITE)
+ | (pages_executable ? PROT_EXEC : 0));
+# else
+ {
+ /* NaCl does not expose mprotect, but mmap should work fine. */
+ void *mmap_result = mmap(start_addr, len, (PROT_READ | PROT_WRITE)
+ | (pages_executable ? PROT_EXEC : 0),
+ MAP_PRIVATE | MAP_FIXED | OPT_MAP_ANON,
+ zero_fd, 0 /* offset */);
+ if (mmap_result != (void *)start_addr)
+ ABORT("mmap as mprotect failed");
+ /* Fake the return value as if mprotect succeeded. */
+ result = 0;
+ }
+# endif /* NACL */
# undef IGNORE_PAGES_EXECUTABLE
if (result != 0) {