Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / native_client / src / untrusted / pthread / nc_thread.c
index 63e09c9..b177054 100644 (file)
 # include "native_client/src/untrusted/irt/irt_private.h"
 #endif
 
-#define FUN_TO_VOID_PTR(a) ((void *) (uintptr_t) (a))
-
 /*
- * ABI tables for underyling NaCl thread interfaces.
+ * ABI tables for underyling NaCl thread interfaces. This is declared to be
+ * global so that a user will be able to override it using the irt_ext API.
  */
-static struct nacl_irt_thread irt_thread;
+struct nacl_irt_thread __libnacl_irt_thread;
 
 /*
  * These days, the thread_create() syscall/IRT call will align the
@@ -95,10 +94,6 @@ int __nc_memory_block_counter[2];
 
 /* Internal functions */
 
-static inline void nc_abort(void) {
-  while (1) *(volatile int *) 0 = 0;  /* Crash.  */
-}
-
 static inline nc_thread_descriptor_t *nc_get_tdb(void) {
   /*
    * Fetch the thread-specific data pointer.  This is usually just
@@ -258,7 +253,7 @@ static void nc_tdb_init(nc_thread_descriptor_t *tdb,
   basic_data->retval = NULL;
   basic_data->status = THREAD_RUNNING;
   if (pthread_cond_init(&basic_data->join_condvar, NULL) != 0)
-    nc_abort();
+    __builtin_trap();
   basic_data->tdb = tdb;
 }
 
@@ -267,10 +262,10 @@ void __nc_initialize_globals(void) {
   /*
    * Fetch the ABI tables from the IRT.  If we don't have these, all is lost.
    */
-  __nc_initialize_interfaces(&irt_thread);
+  __nc_initialize_interfaces();
 
   if (pthread_mutex_init(&__nc_thread_management_lock, NULL) != 0)
-    nc_abort();
+    __builtin_trap();
 
   /*
    * Tell ThreadSanitizer to not generate happens-before arcs between uses of
@@ -281,7 +276,7 @@ void __nc_initialize_globals(void) {
   ANNOTATE_NOT_HAPPENS_BEFORE_MUTEX(&__nc_thread_management_lock);
 
   if (pthread_cond_init(&__nc_last_thread_cond, NULL) != 0)
-    nc_abort();
+    __builtin_trap();
   STAILQ_INIT(&__nc_thread_memory_blocks[0]);
   STAILQ_INIT(&__nc_thread_memory_blocks[1]);
 
@@ -431,8 +426,7 @@ int pthread_create(pthread_t *thread_id,
   memset(esp, 0, kStackPadBelowAlign);
 
   /* Start the thread. */
-  retval = irt_thread.thread_create(
-      FUN_TO_VOID_PTR(nc_thread_starter), esp, new_tp);
+  retval = __libnacl_irt_thread.thread_create(nc_thread_starter, esp, new_tp);
   if (0 != retval) {
     pthread_mutex_lock(&__nc_thread_management_lock);
     /* TODO(gregoryd) : replace with atomic decrement? */
@@ -551,8 +545,8 @@ void pthread_exit(void *retval) {
   }
 
   pthread_mutex_unlock(&__nc_thread_management_lock);
-  irt_thread.thread_exit(is_used);
-  nc_abort();
+  __libnacl_irt_thread.thread_exit(is_used);
+  __builtin_trap();
 }
 
 int pthread_join(pthread_t thread_id, void **thread_return) {
@@ -651,7 +645,7 @@ int pthread_setschedprio(pthread_t thread_id, int prio) {
      */
     return EPERM;
   }
-  return irt_thread.thread_nice(prio);
+  return __libnacl_irt_thread.thread_nice(prio);
 }
 
 int pthread_attr_init(pthread_attr_t *attr) {
@@ -680,7 +674,7 @@ int pthread_attr_setdetachstate(pthread_attr_t *attr,
   return 0;
 }
 
-int pthread_attr_getdetachstate(pthread_attr_t *attr,
+int pthread_attr_getdetachstate(const pthread_attr_t *attr,
                                 int *detachstate) {
   if (NULL == attr) {
     return EINVAL;
@@ -701,7 +695,7 @@ int pthread_attr_setstacksize(pthread_attr_t *attr,
   return 0;
 }
 
-int pthread_attr_getstacksize(pthread_attr_t *attr,
+int pthread_attr_getstacksize(const pthread_attr_t *attr,
                               size_t *stacksize) {
   if (NULL == attr) {
     return EINVAL;
@@ -817,4 +811,5 @@ void __local_lock_release_recursive(_LOCK_T *lock) {
  * on one symbol.  So if these functions are in another file in a library
  * archive, they might not be linked in by static linking.
  */
+/* @IGNORE_LINES_FOR_CODE_HYGIENE[1] */
 #include "native_client/src/untrusted/pthread/nc_tsd.c"