Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / native_client / src / untrusted / pthread / nc_init_private.c
1 /*
2  * Copyright (c) 2012 The Native Client Authors. All rights reserved.
3  * Use of this source code is governed by a BSD-style license that can be
4  * found in the LICENSE file.
5  */
6
7 #include "native_client/src/untrusted/irt/irt_interfaces.h"
8 #include "native_client/src/untrusted/nacl/nacl_irt.h"
9 #include "native_client/src/untrusted/nacl/syscall_bindings_trampoline.h"
10 #include "native_client/src/untrusted/pthread/pthread_internal.h"
11
12 static int nacl_irt_thread_create(void (*start_func)(void), void *stack,
13                                   void *thread_ptr) {
14 #if defined(NACL_IN_IRT)
15   /*
16    * We want the first TLS to point to an unmapped location.  The
17    * thread_create() syscall rejects a zero argument for the first
18    * TLS, so use a non-zero value in the unmapped first 64k page.
19    */
20   void *user_tls = (void *) 0x1000;
21   return -NACL_SYSCALL(thread_create)((void *) start_func, stack,
22                                       user_tls, thread_ptr);
23 #else
24   return -NACL_SYSCALL(thread_create)((void *) start_func, stack,
25                                       thread_ptr, 0);
26 #endif
27 }
28
29 static void nacl_irt_thread_exit(int32_t *stack_flag) {
30   NACL_SYSCALL(thread_exit)(stack_flag);
31   __builtin_trap();
32 }
33
34 static int nacl_irt_thread_nice(const int nice) {
35   return -NACL_SYSCALL(thread_nice)(nice);
36 }
37
38 void __nc_initialize_interfaces(void) {
39   const struct nacl_irt_thread init = {
40     nacl_irt_thread_create,
41     nacl_irt_thread_exit,
42     nacl_irt_thread_nice,
43   };
44   __libnacl_irt_thread = init;
45 }