| 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/arm/sel_ldr_arm.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 static size_t const kNumThreads = NACL_ARRAY_SIZE_UNSAFE(gNaClThreadIdxInUse); | 21 static size_t const kNumThreads = NACL_ARRAY_SIZE_UNSAFE(gNaClThreadIdxInUse); |
| 22 | 22 |
| 23 /* | 23 /* May be NULL if the current thread does not host a NaClAppThread. */ |
| 24 * This holds the index of the current thread. | 24 static THREAD struct NaClThreadContext *nacl_current_thread; |
| 25 * This is also used directly in nacl_syscall.S (NaClSyscallSeg). | |
| 26 */ | |
| 27 __thread uint32_t gNaClThreadIdx = NACL_TLS_INDEX_INVALID; | |
| 28 | 25 |
| 29 uint32_t NaClTlsGetIdx(void) { | 26 void NaClTlsSetCurrentThread(struct NaClAppThread *natp) { |
| 30 return gNaClThreadIdx; | 27 nacl_current_thread = &natp->user; |
| 31 } | 28 } |
| 32 | 29 |
| 33 void NaClTlsSetIdx(uint32_t tls_idx) { | 30 struct NaClAppThread *NaClTlsGetCurrentThread(void) { |
| 34 gNaClThreadIdx = tls_idx; | 31 return NaClAppThreadFromThreadContext(nacl_current_thread); |
| 35 } | 32 } |
| 36 | 33 |
| 37 uint32_t NaClGetThreadIdx(struct NaClAppThread *natp) { | 34 uint32_t NaClGetThreadIdx(struct NaClAppThread *natp) { |
| 38 return natp->user.tls_idx; | 35 return natp->user.tls_idx; |
| 39 } | 36 } |
| 40 | 37 |
| 41 | 38 |
| 42 int NaClTlsInit(void) { | 39 int NaClTlsInit(void) { |
| 43 size_t i; | 40 size_t i; |
| 44 | 41 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 if (kNumThreads != i) { | 74 if (kNumThreads != i) { |
| 78 return i; | 75 return i; |
| 79 } | 76 } |
| 80 | 77 |
| 81 NaClLog(LOG_ERROR, "NaClThreadIdxAllocate: no more slots for a thread\n"); | 78 NaClLog(LOG_ERROR, "NaClThreadIdxAllocate: no more slots for a thread\n"); |
| 82 return NACL_TLS_INDEX_INVALID; | 79 return NACL_TLS_INDEX_INVALID; |
| 83 } | 80 } |
| 84 | 81 |
| 85 | 82 |
| 86 /* | 83 /* |
| 87 * Allocation does not mean we can set gNaClThreadIdx, since we are not | 84 * Allocation does not mean we can set nacl_current_thread, since we |
| 88 * that thread. Setting it must wait until the thread actually launches. | 85 * are not that thread. Setting it must wait until the thread |
| 86 * actually launches. |
| 89 */ | 87 */ |
| 90 uint32_t NaClTlsAllocate(struct NaClAppThread *natp) { | 88 uint32_t NaClTlsAllocate(struct NaClAppThread *natp) { |
| 91 UNREFERENCED_PARAMETER(natp); | 89 UNREFERENCED_PARAMETER(natp); |
| 92 | 90 |
| 93 return NaClThreadIdxAllocate(); | 91 return NaClThreadIdxAllocate(); |
| 94 } | 92 } |
| 95 | 93 |
| 96 | 94 |
| 97 void NaClTlsFree(struct NaClAppThread *natp) { | 95 void NaClTlsFree(struct NaClAppThread *natp) { |
| 98 uint32_t idx = NaClGetThreadIdx(natp); | 96 uint32_t idx = NaClGetThreadIdx(natp); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 118 | 116 |
| 119 | 117 |
| 120 uint32_t NaClTlsGetTlsValue1(struct NaClAppThread *natp) { | 118 uint32_t NaClTlsGetTlsValue1(struct NaClAppThread *natp) { |
| 121 return natp->user.tls_value1; | 119 return natp->user.tls_value1; |
| 122 } | 120 } |
| 123 | 121 |
| 124 | 122 |
| 125 uint32_t NaClTlsGetTlsValue2(struct NaClAppThread *natp) { | 123 uint32_t NaClTlsGetTlsValue2(struct NaClAppThread *natp) { |
| 126 return natp->user.tls_value2; | 124 return natp->user.tls_value2; |
| 127 } | 125 } |
| OLD | NEW |