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

Unified Diff: src/trusted/service_runtime/osx/thread_suspension.c

Issue 11543028: Allow creating a NaClAppThread without creating a new host OS thread (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Review: Add NACL_WUR Created 8 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/trusted/service_runtime/nacl_app_thread.c ('k') | src/trusted/service_runtime/sel_ldr.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « src/trusted/service_runtime/nacl_app_thread.c ('k') | src/trusted/service_runtime/sel_ldr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698