| 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 #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_exit.h" | 11 #include "native_client/src/shared/platform/nacl_exit.h" |
| 12 #include "native_client/src/shared/platform/nacl_sync_checked.h" | 12 #include "native_client/src/shared/platform/nacl_sync_checked.h" |
| 13 | 13 |
| 14 #include "native_client/src/trusted/service_runtime/arch/sel_ldr_arch.h" | 14 #include "native_client/src/trusted/service_runtime/arch/sel_ldr_arch.h" |
| 15 #include "native_client/src/trusted/service_runtime/nacl_desc_effector_ldr.h" | 15 #include "native_client/src/trusted/service_runtime/nacl_desc_effector_ldr.h" |
| 16 #include "native_client/src/trusted/service_runtime/nacl_globals.h" | 16 #include "native_client/src/trusted/service_runtime/nacl_globals.h" |
| 17 #include "native_client/src/trusted/service_runtime/nacl_oop_debugger_hooks.h" | 17 #include "native_client/src/trusted/service_runtime/nacl_oop_debugger_hooks.h" |
| 18 #include "native_client/src/trusted/service_runtime/nacl_tls.h" | 18 #include "native_client/src/trusted/service_runtime/nacl_tls.h" |
| 19 #include "native_client/src/trusted/service_runtime/nacl_switch_to_app.h" | 19 #include "native_client/src/trusted/service_runtime/nacl_switch_to_app.h" |
| 20 #include "native_client/src/trusted/service_runtime/nacl_stack_safety.h" | 20 #include "native_client/src/trusted/service_runtime/nacl_stack_safety.h" |
| 21 #include "native_client/src/trusted/service_runtime/nacl_syscall_common.h" | 21 #include "native_client/src/trusted/service_runtime/nacl_syscall_common.h" |
| 22 | 22 |
| 23 | 23 |
| 24 void NaClAppThreadSetSuspendState(struct NaClAppThread *natp, | |
| 25 enum NaClSuspendState old_state, | |
| 26 enum NaClSuspendState new_state) { | |
| 27 #if NACL_WINDOWS | |
| 28 NaClXMutexLock(&natp->mu); | |
| 29 while ((natp->suspend_state & NACL_APP_THREAD_SUSPENDING) != 0) { | |
| 30 /* | |
| 31 * We are being suspended, but SuspendThread() has not taken effect yet. | |
| 32 */ | |
| 33 NaClXCondVarWait(&natp->cv, &natp->mu); | |
| 34 } | |
| 35 DCHECK(natp->suspend_state == old_state); | |
| 36 natp->suspend_state = new_state; | |
| 37 NaClXMutexUnlock(&natp->mu); | |
| 38 #else | |
| 39 UNREFERENCED_PARAMETER(natp); | |
| 40 UNREFERENCED_PARAMETER(old_state); | |
| 41 UNREFERENCED_PARAMETER(new_state); | |
| 42 #endif | |
| 43 } | |
| 44 | |
| 45 | |
| 46 void WINAPI NaClThreadLauncher(void *state) { | 24 void WINAPI NaClThreadLauncher(void *state) { |
| 47 struct NaClAppThread *natp = (struct NaClAppThread *) state; | 25 struct NaClAppThread *natp = (struct NaClAppThread *) state; |
| 48 uint32_t thread_idx; | 26 uint32_t thread_idx; |
| 49 NaClLog(4, "NaClThreadLauncher: entered\n"); | 27 NaClLog(4, "NaClThreadLauncher: entered\n"); |
| 50 | 28 |
| 51 NaClSignalStackRegister(natp->signal_stack); | 29 NaClSignalStackRegister(natp->signal_stack); |
| 52 | 30 |
| 53 NaClLog(4, " natp = 0x%016"NACL_PRIxPTR"\n", (uintptr_t) natp); | 31 NaClLog(4, " natp = 0x%016"NACL_PRIxPTR"\n", (uintptr_t) natp); |
| 54 NaClLog(4, " prog_ctr = 0x%016"NACL_PRIxNACL_REG"\n", natp->user.prog_ctr); | 32 NaClLog(4, " prog_ctr = 0x%016"NACL_PRIxNACL_REG"\n", natp->user.prog_ctr); |
| 55 NaClLog(4, "stack_ptr = 0x%016"NACL_PRIxPTR"\n", | 33 NaClLog(4, "stack_ptr = 0x%016"NACL_PRIxPTR"\n", |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 if (!NaClCondVarCtor(&natp->cv)) { | 193 if (!NaClCondVarCtor(&natp->cv)) { |
| 216 goto cleanup_mutex; | 194 goto cleanup_mutex; |
| 217 } | 195 } |
| 218 | 196 |
| 219 natp->sysret = 0; | 197 natp->sysret = 0; |
| 220 | 198 |
| 221 if (!NaClSignalStackAllocate(&natp->signal_stack)) { | 199 if (!NaClSignalStackAllocate(&natp->signal_stack)) { |
| 222 goto cleanup_cv; | 200 goto cleanup_cv; |
| 223 } | 201 } |
| 224 | 202 |
| 225 #if NACL_WINDOWS | |
| 226 natp->suspend_state = NACL_APP_THREAD_TRUSTED; | 203 natp->suspend_state = NACL_APP_THREAD_TRUSTED; |
| 227 #endif | |
| 228 | 204 |
| 229 natp->thread_num = -1; /* illegal index */ | 205 natp->thread_num = -1; /* illegal index */ |
| 230 natp->sys_tls = sys_tls; | 206 natp->sys_tls = sys_tls; |
| 231 natp->tls2 = user_tls2; | 207 natp->tls2 = user_tls2; |
| 232 natp->usr_tlsp = NULL; | 208 natp->usr_tlsp = NULL; |
| 233 | 209 |
| 234 natp->dynamic_delete_generation = 0; | 210 natp->dynamic_delete_generation = 0; |
| 235 | 211 |
| 236 rv = NaClThreadCtor(&natp->thread, | 212 rv = NaClThreadCtor(&natp->thread, |
| 237 NaClThreadLauncher, | 213 NaClThreadLauncher, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 258 * the thread must not be still running, else this crashes the system | 234 * the thread must not be still running, else this crashes the system |
| 259 */ | 235 */ |
| 260 | 236 |
| 261 NaClThreadDtor(&natp->thread); | 237 NaClThreadDtor(&natp->thread); |
| 262 NaClSignalStackFree(natp->signal_stack); | 238 NaClSignalStackFree(natp->signal_stack); |
| 263 natp->signal_stack = NULL; | 239 natp->signal_stack = NULL; |
| 264 NaClTlsFree(natp); | 240 NaClTlsFree(natp); |
| 265 NaClCondVarDtor(&natp->cv); | 241 NaClCondVarDtor(&natp->cv); |
| 266 NaClMutexDtor(&natp->mu); | 242 NaClMutexDtor(&natp->mu); |
| 267 } | 243 } |
| OLD | NEW |