OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 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 | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #include "native_client/src/include/nacl_platform.h" | 7 #include "native_client/src/include/nacl_platform.h" |
8 #include "native_client/src/include/nacl_macros.h" | 8 #include "native_client/src/include/nacl_macros.h" |
9 #include "native_client/src/include/portability.h" | 9 #include "native_client/src/include/portability.h" |
10 #include "native_client/src/shared/platform/nacl_check.h" | 10 #include "native_client/src/shared/platform/nacl_check.h" |
11 #include "native_client/src/shared/platform/nacl_sync_checked.h" | 11 #include "native_client/src/shared/platform/nacl_sync_checked.h" |
12 #include "native_client/src/trusted/service_runtime/arch/arm/sel_ldr_arm.h" | 12 #include "native_client/src/trusted/service_runtime/arch/mips/sel_ldr_mips.h" |
13 #include "native_client/src/trusted/service_runtime/nacl_app_thread.h" | 13 #include "native_client/src/trusted/service_runtime/nacl_app_thread.h" |
14 #include "native_client/src/trusted/service_runtime/nacl_globals.h" | 14 #include "native_client/src/trusted/service_runtime/nacl_globals.h" |
15 #include "native_client/src/trusted/service_runtime/nacl_tls.h" | 15 #include "native_client/src/trusted/service_runtime/nacl_tls.h" |
16 #include "native_client/src/trusted/service_runtime/sel_ldr.h" | 16 #include "native_client/src/trusted/service_runtime/sel_ldr.h" |
17 #include "native_client/src/trusted/service_runtime/sel_memory.h" | 17 #include "native_client/src/trusted/service_runtime/sel_memory.h" |
18 | 18 |
19 static struct NaClMutex gNaClTlsMu; | 19 static struct NaClMutex gNaClTlsMu; |
20 static int gNaClThreadIdxInUse[NACL_THREAD_MAX]; /* bool */ | 20 static int gNaClThreadIdxInUse[NACL_THREAD_MAX]; /* bool */ |
21 | 21 |
22 /* | 22 /* |
23 * This holds the index of the current thread. | 23 * This holds the index of the current thread. |
24 * This is also used directly in nacl_syscall.S (NaClSyscallSeg). | 24 * This is also used directly in nacl_syscall.S (NaClSyscallSeg). |
25 */ | 25 */ |
26 __thread uint32_t gNaClThreadIdx = NACL_TLS_INDEX_INVALID; | 26 __thread uint32_t gNaClThreadIdx = NACL_TLS_INDEX_INVALID; |
27 | 27 |
28 uint32_t NaClTlsGetIdx(void) { | 28 uint32_t NaClTlsGetIdx(void) { |
29 return gNaClThreadIdx; | 29 return gNaClThreadIdx; |
30 } | 30 } |
31 | 31 |
32 void NaClTlsSetIdx(uint32_t tls_idx) { | 32 void NaClTlsSetIdx(uint32_t tls_idx) { |
33 gNaClThreadIdx = tls_idx; | 33 gNaClThreadIdx = tls_idx; |
34 } | 34 } |
35 | 35 |
| 36 |
36 uint32_t NaClGetThreadIdx(struct NaClAppThread *natp) { | 37 uint32_t NaClGetThreadIdx(struct NaClAppThread *natp) { |
37 return natp->user.tls_idx; | 38 return natp->user.tls_idx; |
38 } | 39 } |
39 | 40 |
40 | |
41 int NaClTlsInit() { | 41 int NaClTlsInit() { |
42 size_t i; | 42 size_t i; |
43 | 43 |
44 NaClLog(2, "NaClTlsInit\n"); | 44 NaClLog(2, "NaClTlsInit\n"); |
45 | 45 |
46 for (i = 0; i < NACL_ARRAY_SIZE(gNaClThreadIdxInUse); i++) { | 46 for (i = 0; i < NACL_ARRAY_SIZE(gNaClThreadIdxInUse); i++) { |
47 gNaClThreadIdxInUse[i] = 0; | 47 gNaClThreadIdxInUse[i] = 0; |
48 } | 48 } |
49 if (!NaClMutexCtor(&gNaClTlsMu)) { | 49 if (!NaClMutexCtor(&gNaClTlsMu)) { |
50 NaClLog(LOG_WARNING, | 50 NaClLog(LOG_WARNING, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 } | 82 } |
83 | 83 |
84 | 84 |
85 /* | 85 /* |
86 * Allocation does not mean we can set gNaClThreadIdx, since we are not | 86 * Allocation does not mean we can set gNaClThreadIdx, since we are not |
87 * that thread. Setting it must wait until the thread actually launches. | 87 * that thread. Setting it must wait until the thread actually launches. |
88 */ | 88 */ |
89 uint32_t NaClTlsAllocate(struct NaClAppThread *natp) { | 89 uint32_t NaClTlsAllocate(struct NaClAppThread *natp) { |
90 int idx = NaClThreadIdxAllocate(); | 90 int idx = NaClThreadIdxAllocate(); |
91 | 91 |
92 NaClLog(2, "NaClTlsAllocate: $tp %x idx %d\n", natp->tls_values.tls1, idx); | 92 NaClLog(2, "NaClTlsAllocate: $tp %x idx %d\n", natp->tls_values.tls1, idx); |
93 if (-1 == idx) { | 93 if (-1 == idx) { |
94 NaClLog(LOG_FATAL, | 94 NaClLog(LOG_FATAL, |
95 "NaClTlsAllocate: thread limit reached\n"); | 95 "NaClTlsAllocate: thread limit reached\n"); |
96 return NACL_TLS_INDEX_INVALID; | 96 return NACL_TLS_INDEX_INVALID; |
97 } | 97 } |
98 | 98 |
99 natp->user.r9 = natp->tls_values.tls1; | 99 natp->user.t8 = natp->tls_values.tls1; |
100 | 100 |
101 /* | 101 /* |
102 * Bias by 1: successful return value is never 0. | 102 * Bias by 1: successful return value is never 0. |
103 */ | 103 */ |
104 return idx + 1; | 104 return idx + 1; |
105 } | 105 } |
106 | 106 |
107 | 107 |
108 void NaClTlsFree(struct NaClAppThread *natp) { | 108 void NaClTlsFree(struct NaClAppThread *natp) { |
109 uint32_t idx = NaClGetThreadIdx(natp); | 109 uint32_t idx = NaClGetThreadIdx(natp); |
110 NaClLog(2, | 110 NaClLog(2, |
111 "NaClTlsFree: old idx %d $tp %x\n", | 111 "NaClTlsFree: old idx %d $tp %x\n", |
112 idx, natp->user.r9); | 112 idx, natp->user.t8); |
113 | 113 |
114 NaClXMutexLock(&gNaClTlsMu); | 114 NaClXMutexLock(&gNaClTlsMu); |
115 gNaClThreadIdxInUse[idx - 1] = 0; | 115 gNaClThreadIdxInUse[idx - 1] = 0; |
116 NaClXMutexUnlock(&gNaClTlsMu); | 116 NaClXMutexUnlock(&gNaClTlsMu); |
117 | 117 |
118 natp->user.r9 = 0; | 118 natp->user.t8 = 0; |
119 } | 119 } |
120 | 120 |
121 | 121 |
122 void NaClTlsChange(struct NaClAppThread *natp) { | 122 void NaClTlsChange(struct NaClAppThread *natp) { |
123 NaClLog(2, "NaClTlsChange: $tp %x\n", natp->tls_values.tls1); | 123 NaClLog(2, "NaClTlsChange: $tp %x\n", natp->tls_values.tls1); |
124 | 124 |
125 natp->user.r9 = natp->tls_values.tls1; | 125 natp->user.t8 = natp->tls_values.tls1; |
126 } | 126 } |
OLD | NEW |