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 /* | 7 /* |
| 8 * NaCl Server Runtime user thread state. | 8 * NaCl Server Runtime user thread state. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include <string.h> | 11 #include <string.h> |
| 12 | 12 |
| 13 #include "native_client/src/shared/platform/aligned_malloc.h" | 13 #include "native_client/src/shared/platform/aligned_malloc.h" |
| 14 #include "native_client/src/shared/platform/nacl_check.h" | 14 #include "native_client/src/shared/platform/nacl_check.h" |
| 15 #include "native_client/src/shared/platform/nacl_exit.h" | 15 #include "native_client/src/shared/platform/nacl_exit.h" |
| 16 #include "native_client/src/shared/platform/nacl_sync_checked.h" | 16 #include "native_client/src/shared/platform/nacl_sync_checked.h" |
| 17 | 17 |
| 18 #include "native_client/src/trusted/service_runtime/arch/sel_ldr_arch.h" | 18 #include "native_client/src/trusted/service_runtime/arch/sel_ldr_arch.h" |
| 19 #include "native_client/src/trusted/service_runtime/nacl_desc_effector_ldr.h" | 19 #include "native_client/src/trusted/service_runtime/nacl_desc_effector_ldr.h" |
| 20 #include "native_client/src/trusted/service_runtime/nacl_globals.h" | 20 #include "native_client/src/trusted/service_runtime/nacl_globals.h" |
| 21 #include "native_client/src/trusted/service_runtime/nacl_tls.h" | 21 #include "native_client/src/trusted/service_runtime/nacl_tls.h" |
| 22 #include "native_client/src/trusted/service_runtime/nacl_switch_to_app.h" | 22 #include "native_client/src/trusted/service_runtime/nacl_switch_to_app.h" |
| 23 #include "native_client/src/trusted/service_runtime/nacl_stack_safety.h" | 23 #include "native_client/src/trusted/service_runtime/nacl_stack_safety.h" |
| 24 #include "native_client/src/trusted/service_runtime/nacl_syscall_common.h" | 24 #include "native_client/src/trusted/service_runtime/nacl_syscall_common.h" |
| 25 #include "native_client/src/trusted/service_runtime/osx/mach_thread_map.h" | |
| 25 | 26 |
| 26 | 27 |
| 27 void WINAPI NaClAppThreadLauncher(void *state) { | 28 void WINAPI NaClAppThreadLauncher(void *state) { |
| 28 struct NaClAppThread *natp = (struct NaClAppThread *) state; | 29 struct NaClAppThread *natp = (struct NaClAppThread *) state; |
| 29 uint32_t thread_idx; | 30 uint32_t thread_idx; |
| 30 NaClLog(4, "NaClAppThreadLauncher: entered\n"); | 31 NaClLog(4, "NaClAppThreadLauncher: entered\n"); |
| 31 | 32 |
| 32 NaClSignalStackRegister(natp->signal_stack); | 33 NaClSignalStackRegister(natp->signal_stack); |
| 33 | 34 |
| 34 NaClLog(4, " natp = 0x%016"NACL_PRIxPTR"\n", (uintptr_t) natp); | 35 NaClLog(4, " natp = 0x%016"NACL_PRIxPTR"\n", (uintptr_t) natp); |
| 35 NaClLog(4, " prog_ctr = 0x%016"NACL_PRIxNACL_REG"\n", natp->user.prog_ctr); | 36 NaClLog(4, " prog_ctr = 0x%016"NACL_PRIxNACL_REG"\n", natp->user.prog_ctr); |
| 36 NaClLog(4, "stack_ptr = 0x%016"NACL_PRIxPTR"\n", | 37 NaClLog(4, "stack_ptr = 0x%016"NACL_PRIxPTR"\n", |
| 37 NaClGetThreadCtxSp(&natp->user)); | 38 NaClGetThreadCtxSp(&natp->user)); |
| 38 | 39 |
| 39 thread_idx = NaClGetThreadIdx(natp); | 40 thread_idx = NaClGetThreadIdx(natp); |
| 40 CHECK(0 < thread_idx); | 41 CHECK(0 < thread_idx); |
| 41 CHECK(thread_idx < NACL_THREAD_MAX); | 42 CHECK(thread_idx < NACL_THREAD_MAX); |
| 42 NaClTlsSetIdx(thread_idx); | 43 NaClTlsSetIdx(thread_idx); |
| 43 nacl_user[thread_idx] = &natp->user; | 44 nacl_user[thread_idx] = &natp->user; |
| 44 #if NACL_WINDOWS | 45 #if NACL_WINDOWS |
| 45 nacl_thread_ids[thread_idx] = GetCurrentThreadId(); | 46 nacl_thread_ids[thread_idx] = GetCurrentThreadId(); |
| 47 #elif NACL_OSX | |
|
Mark Mentovai
2013/02/15 22:30:30
It occurs to me that I could get rid of the #ifdef
| |
| 48 NaClSetCurrentMachThreadForThreadIndex(thread_idx); | |
| 46 #endif | 49 #endif |
| 47 | 50 |
| 48 /* | 51 /* |
| 49 * We have to hold the threads_mu lock until after thread_num field | 52 * We have to hold the threads_mu lock until after thread_num field |
| 50 * in this thread has been initialized. All other threads can only | 53 * in this thread has been initialized. All other threads can only |
| 51 * find and examine this natp through the threads table, so the fact | 54 * find and examine this natp through the threads table, so the fact |
| 52 * that natp is not consistent (no thread_num) will not be visible. | 55 * that natp is not consistent (no thread_num) will not be visible. |
| 53 */ | 56 */ |
| 54 NaClXMutexLock(&natp->nap->threads_mu); | 57 NaClXMutexLock(&natp->nap->threads_mu); |
| 55 natp->thread_num = NaClAddThreadMu(natp->nap, natp); | 58 natp->thread_num = NaClAddThreadMu(natp->nap, natp); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 */ | 118 */ |
| 116 thread_idx = NaClGetThreadIdx(natp); | 119 thread_idx = NaClGetThreadIdx(natp); |
| 117 /* | 120 /* |
| 118 * On x86-64 and ARM, clearing nacl_user entry ensures that we will | 121 * On x86-64 and ARM, clearing nacl_user entry ensures that we will |
| 119 * fault if another syscall is made with this thread_idx. In | 122 * fault if another syscall is made with this thread_idx. In |
| 120 * particular, thread_idx 0 is never used. | 123 * particular, thread_idx 0 is never used. |
| 121 */ | 124 */ |
| 122 nacl_user[thread_idx] = NULL; | 125 nacl_user[thread_idx] = NULL; |
| 123 #if NACL_WINDOWS | 126 #if NACL_WINDOWS |
| 124 nacl_thread_ids[thread_idx] = 0; | 127 nacl_thread_ids[thread_idx] = 0; |
| 128 #elif NACL_OSX | |
| 129 NaClClearMachThreadForThreadIndex(thread_idx); | |
| 125 #endif | 130 #endif |
| 126 | 131 |
| 127 NaClLog(3, " removing thread from thread table\n"); | 132 NaClLog(3, " removing thread from thread table\n"); |
| 128 /* Deallocate the ID natp->thread_num. */ | 133 /* Deallocate the ID natp->thread_num. */ |
| 129 NaClRemoveThreadMu(nap, natp->thread_num); | 134 NaClRemoveThreadMu(nap, natp->thread_num); |
| 130 NaClLog(3, " unlocking thread\n"); | 135 NaClLog(3, " unlocking thread\n"); |
| 131 NaClXMutexUnlock(&natp->mu); | 136 NaClXMutexUnlock(&natp->mu); |
| 132 NaClLog(3, " unlocking thread table\n"); | 137 NaClLog(3, " unlocking thread table\n"); |
| 133 NaClXMutexUnlock(&nap->threads_mu); | 138 NaClXMutexUnlock(&nap->threads_mu); |
| 134 NaClLog(3, " unregistering signal stack\n"); | 139 NaClLog(3, " unregistering signal stack\n"); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 NaClThreadDtor(&natp->host_thread); | 265 NaClThreadDtor(&natp->host_thread); |
| 261 } | 266 } |
| 262 free(natp->suspended_registers); | 267 free(natp->suspended_registers); |
| 263 NaClMutexDtor(&natp->suspend_mu); | 268 NaClMutexDtor(&natp->suspend_mu); |
| 264 NaClSignalStackFree(natp->signal_stack); | 269 NaClSignalStackFree(natp->signal_stack); |
| 265 natp->signal_stack = NULL; | 270 natp->signal_stack = NULL; |
| 266 NaClTlsFree(natp); | 271 NaClTlsFree(natp); |
| 267 NaClMutexDtor(&natp->mu); | 272 NaClMutexDtor(&natp->mu); |
| 268 NaClAlignedFree(natp); | 273 NaClAlignedFree(natp); |
| 269 } | 274 } |
| OLD | NEW |