Chromium Code Reviews| 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/mips/sel_ldr_mips.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 /* May be NULL if the current thread does not host a NaClAppThread. */ |
| 23 * This holds the index of the current thread. | 23 THREAD struct NaClThreadContext *nacl_current_thread; |
|
bsy
2013/02/19 19:03:08
maybe nacl_current_thread_context?
Mark Seaborn
2013/03/27 00:29:07
I opted to leave this as "nacl_current_thread" bec
| |
| 24 * This is also used directly in nacl_syscall.S (NaClSyscallSeg). | |
| 25 */ | |
| 26 __thread uint32_t gNaClThreadIdx = NACL_TLS_INDEX_INVALID; | |
| 27 | 24 |
| 28 uint32_t NaClTlsGetIdx(void) { | 25 void NaClTlsSetCurrentThread(struct NaClAppThread *natp) { |
| 29 return gNaClThreadIdx; | 26 nacl_current_thread = &natp->user; |
| 30 } | 27 } |
| 31 | 28 |
| 32 void NaClTlsSetIdx(uint32_t tls_idx) { | 29 struct NaClAppThread *NaClTlsGetCurrentThread(void) { |
| 33 gNaClThreadIdx = tls_idx; | 30 return NaClAppThreadFromThreadContext(nacl_current_thread); |
| 34 } | 31 } |
| 35 | 32 |
| 36 uint32_t NaClGetThreadIdx(struct NaClAppThread *natp) { | 33 uint32_t NaClGetThreadIdx(struct NaClAppThread *natp) { |
| 37 return natp->user.tls_idx; | 34 return natp->user.tls_idx; |
| 38 } | 35 } |
| 39 | 36 |
| 40 | 37 |
| 41 int NaClTlsInit(void) { | 38 int NaClTlsInit(void) { |
| 42 size_t i; | 39 size_t i; |
| 43 | 40 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 if (NACL_THREAD_MAX != i) { | 74 if (NACL_THREAD_MAX != 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 -1; | 79 return -1; |
| 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 int idx = NaClThreadIdxAllocate(); | 89 int idx = NaClThreadIdxAllocate(); |
| 92 | 90 |
| 93 UNREFERENCED_PARAMETER(natp); | 91 UNREFERENCED_PARAMETER(natp); |
| 94 | 92 |
| 95 NaClLog(2, "NaClTlsAllocate: idx %d\n", idx); | 93 NaClLog(2, "NaClTlsAllocate: idx %d\n", idx); |
| 96 if (-1 == idx) { | 94 if (-1 == idx) { |
| 97 NaClLog(LOG_FATAL, | 95 NaClLog(LOG_FATAL, |
| 98 "NaClTlsAllocate: thread limit reached\n"); | 96 "NaClTlsAllocate: thread limit reached\n"); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 | 129 |
| 132 | 130 |
| 133 uint32_t NaClTlsGetTlsValue1(struct NaClAppThread *natp) { | 131 uint32_t NaClTlsGetTlsValue1(struct NaClAppThread *natp) { |
| 134 return natp->user.t8; | 132 return natp->user.t8; |
| 135 } | 133 } |
| 136 | 134 |
| 137 | 135 |
| 138 uint32_t NaClTlsGetTlsValue2(struct NaClAppThread *natp) { | 136 uint32_t NaClTlsGetTlsValue2(struct NaClAppThread *natp) { |
| 139 return natp->user.tls_value2; | 137 return natp->user.tls_value2; |
| 140 } | 138 } |
| OLD | NEW |