Index: src/trusted/service_runtime/osx/thread_suspension.c |
diff --git a/src/trusted/service_runtime/osx/thread_suspension.c b/src/trusted/service_runtime/osx/thread_suspension.c |
index c5114407468c05fba77d4d49af982d125905b124..56db973f84e07816887f8fce25531eb2d060073a 100644 |
--- a/src/trusted/service_runtime/osx/thread_suspension.c |
+++ b/src/trusted/service_runtime/osx/thread_suspension.c |
@@ -26,6 +26,11 @@ struct NaClAppThreadSuspendedRegisters { |
#endif |
}; |
+static mach_port_t GetHostThreadPort(struct NaClAppThread *natp) { |
+ CHECK(natp->host_thread_is_defined); |
+ return pthread_mach_thread_np(natp->host_thread.tid); |
+} |
+ |
void NaClAppThreadSetSuspendState(struct NaClAppThread *natp, |
enum NaClSuspendState old_state, |
enum NaClSuspendState new_state) { |
@@ -54,7 +59,7 @@ void NaClUntrustedThreadSuspend(struct NaClAppThread *natp, |
if (natp->suspend_state == NACL_APP_THREAD_UNTRUSTED) { |
kern_return_t result; |
mach_msg_type_number_t size; |
- mach_port_t thread_port = pthread_mach_thread_np(natp->thread.tid); |
+ mach_port_t thread_port = GetHostThreadPort(natp); |
result = thread_suspend(thread_port); |
if (result != KERN_SUCCESS) { |
@@ -88,8 +93,7 @@ void NaClUntrustedThreadSuspend(struct NaClAppThread *natp, |
void NaClUntrustedThreadResume(struct NaClAppThread *natp) { |
if (natp->suspend_state == NACL_APP_THREAD_UNTRUSTED) { |
- mach_port_t thread_port = pthread_mach_thread_np(natp->thread.tid); |
- kern_return_t result = thread_resume(thread_port); |
+ kern_return_t result = thread_resume(GetHostThreadPort(natp)); |
if (result != KERN_SUCCESS) { |
NaClLog(LOG_FATAL, "NaClUntrustedThreadResume: " |
"thread_resume() call failed: error %d\n", (int) result); |
@@ -138,7 +142,6 @@ void NaClAppThreadGetSuspendedRegistersInternal( |
void NaClAppThreadSetSuspendedRegistersInternal( |
struct NaClAppThread *natp, const struct NaClSignalContext *regs) { |
- mach_port_t thread_port = pthread_mach_thread_np(natp->thread.tid); |
kern_return_t result; |
mach_msg_type_number_t size; |
struct NaClAppThreadSuspendedRegisters *state = natp->suspended_registers; |
@@ -168,7 +171,7 @@ void NaClAppThreadSetSuspendedRegistersInternal( |
#endif |
size = sizeof(context_copy) / sizeof(natural_t); |
- result = thread_set_state(thread_port, x86_THREAD_STATE, |
+ result = thread_set_state(GetHostThreadPort(natp), x86_THREAD_STATE, |
(void *) &context_copy, size); |
if (result != KERN_SUCCESS) { |
NaClLog(LOG_FATAL, "NaClAppThreadSetSuspendedRegistersInternal: " |
@@ -177,7 +180,6 @@ void NaClAppThreadSetSuspendedRegistersInternal( |
} |
int NaClAppThreadUnblockIfFaulted(struct NaClAppThread *natp, int *signal) { |
- mach_port_t thread_port; |
kern_return_t result; |
if (natp->fault_signal == 0) { |
return 0; |
@@ -190,8 +192,7 @@ int NaClAppThreadUnblockIfFaulted(struct NaClAppThread *natp, int *signal) { |
* undoes the effect of mach_exception_handler.c's thread_suspend() |
* call. |
*/ |
- thread_port = pthread_mach_thread_np(natp->thread.tid); |
- result = thread_resume(thread_port); |
+ result = thread_resume(GetHostThreadPort(natp)); |
if (result != KERN_SUCCESS) { |
NaClLog(LOG_FATAL, "NaClAppThreadUnblockIfFaulted: " |
"thread_resume() call failed: error %d\n", (int) result); |