Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(239)

Side by Side Diff: src/trusted/service_runtime/nacl_app_thread.c

Issue 12207165: Mac x86_64: Mach exception support (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 25
26 #if NACL_OSX
Mark Seaborn 2013/02/14 00:37:54 I'd be inclined to put this #if into the header so
27 #include "native_client/src/trusted/service_runtime/osx/mach_thread_map.h"
28 #endif
29
26 30
27 void WINAPI NaClAppThreadLauncher(void *state) { 31 void WINAPI NaClAppThreadLauncher(void *state) {
28 struct NaClAppThread *natp = (struct NaClAppThread *) state; 32 struct NaClAppThread *natp = (struct NaClAppThread *) state;
29 uint32_t thread_idx; 33 uint32_t thread_idx;
30 NaClLog(4, "NaClAppThreadLauncher: entered\n"); 34 NaClLog(4, "NaClAppThreadLauncher: entered\n");
31 35
32 NaClSignalStackRegister(natp->signal_stack); 36 NaClSignalStackRegister(natp->signal_stack);
33 37
34 NaClLog(4, " natp = 0x%016"NACL_PRIxPTR"\n", (uintptr_t) natp); 38 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); 39 NaClLog(4, " prog_ctr = 0x%016"NACL_PRIxNACL_REG"\n", natp->user.prog_ctr);
36 NaClLog(4, "stack_ptr = 0x%016"NACL_PRIxPTR"\n", 40 NaClLog(4, "stack_ptr = 0x%016"NACL_PRIxPTR"\n",
37 NaClGetThreadCtxSp(&natp->user)); 41 NaClGetThreadCtxSp(&natp->user));
38 42
39 thread_idx = NaClGetThreadIdx(natp); 43 thread_idx = NaClGetThreadIdx(natp);
40 CHECK(0 < thread_idx); 44 CHECK(0 < thread_idx);
41 CHECK(thread_idx < NACL_THREAD_MAX); 45 CHECK(thread_idx < NACL_THREAD_MAX);
42 NaClTlsSetIdx(thread_idx); 46 NaClTlsSetIdx(thread_idx);
43 nacl_user[thread_idx] = &natp->user; 47 nacl_user[thread_idx] = &natp->user;
44 #if NACL_WINDOWS 48 #if NACL_WINDOWS
45 nacl_thread_ids[thread_idx] = GetCurrentThreadId(); 49 nacl_thread_ids[thread_idx] = GetCurrentThreadId();
50 #elif NACL_OSX
51 SetCurrentMachThreadForNaClThreadIndex(thread_idx);
46 #endif 52 #endif
47 53
48 /* 54 /*
49 * We have to hold the threads_mu lock until after thread_num field 55 * 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 56 * in this thread has been initialized. All other threads can only
51 * find and examine this natp through the threads table, so the fact 57 * 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. 58 * that natp is not consistent (no thread_num) will not be visible.
53 */ 59 */
54 NaClXMutexLock(&natp->nap->threads_mu); 60 NaClXMutexLock(&natp->nap->threads_mu);
55 natp->thread_num = NaClAddThreadMu(natp->nap, natp); 61 natp->thread_num = NaClAddThreadMu(natp->nap, natp);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 */ 121 */
116 thread_idx = NaClGetThreadIdx(natp); 122 thread_idx = NaClGetThreadIdx(natp);
117 /* 123 /*
118 * On x86-64 and ARM, clearing nacl_user entry ensures that we will 124 * 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 125 * fault if another syscall is made with this thread_idx. In
120 * particular, thread_idx 0 is never used. 126 * particular, thread_idx 0 is never used.
121 */ 127 */
122 nacl_user[thread_idx] = NULL; 128 nacl_user[thread_idx] = NULL;
123 #if NACL_WINDOWS 129 #if NACL_WINDOWS
124 nacl_thread_ids[thread_idx] = 0; 130 nacl_thread_ids[thread_idx] = 0;
131 #elif NACL_OSX
132 ClearMachThreadForNaClThreadIndex(thread_idx);
125 #endif 133 #endif
126 134
127 NaClLog(3, " removing thread from thread table\n"); 135 NaClLog(3, " removing thread from thread table\n");
128 /* Deallocate the ID natp->thread_num. */ 136 /* Deallocate the ID natp->thread_num. */
129 NaClRemoveThreadMu(nap, natp->thread_num); 137 NaClRemoveThreadMu(nap, natp->thread_num);
130 NaClLog(3, " unlocking thread\n"); 138 NaClLog(3, " unlocking thread\n");
131 NaClXMutexUnlock(&natp->mu); 139 NaClXMutexUnlock(&natp->mu);
132 NaClLog(3, " unlocking thread table\n"); 140 NaClLog(3, " unlocking thread table\n");
133 NaClXMutexUnlock(&nap->threads_mu); 141 NaClXMutexUnlock(&nap->threads_mu);
134 NaClLog(3, " unregistering signal stack\n"); 142 NaClLog(3, " unregistering signal stack\n");
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 NaClThreadDtor(&natp->host_thread); 268 NaClThreadDtor(&natp->host_thread);
261 } 269 }
262 free(natp->suspended_registers); 270 free(natp->suspended_registers);
263 NaClMutexDtor(&natp->suspend_mu); 271 NaClMutexDtor(&natp->suspend_mu);
264 NaClSignalStackFree(natp->signal_stack); 272 NaClSignalStackFree(natp->signal_stack);
265 natp->signal_stack = NULL; 273 natp->signal_stack = NULL;
266 NaClTlsFree(natp); 274 NaClTlsFree(natp);
267 NaClMutexDtor(&natp->mu); 275 NaClMutexDtor(&natp->mu);
268 NaClAlignedFree(natp); 276 NaClAlignedFree(natp);
269 } 277 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698