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

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

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 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
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 struct NaClMutex mu; 64 struct NaClMutex mu;
65 65
66 /* 66 /*
67 * The NaCl app that contains this thread. The app must exist as 67 * The NaCl app that contains this thread. The app must exist as
68 * long as a thread is still alive. 68 * long as a thread is still alive.
69 */ 69 */
70 struct NaClApp *nap; 70 struct NaClApp *nap;
71 71
72 int thread_num; /* index into nap->threads */ 72 int thread_num; /* index into nap->threads */
73 73
74 struct NaClThread thread; /* low level thread representation */ 74 /*
75 * If host_thread_is_defined is true, host_thread is initialized and
76 * owned by the NaClAppThread such that it will be freed by
77 * NaClAppThreadDelete().
78 *
79 * host_thread_is_defined may be false when running untrusted code
80 * on a borrowed host thread that was not created by
81 * NaClAppThreadSpawn().
82 */
83 int host_thread_is_defined;
84 struct NaClThread host_thread; /* low level thread representation */
75 85
76 struct NaClMutex suspend_mu; 86 struct NaClMutex suspend_mu;
77 Atomic32 suspend_state; /* enum NaClSuspendState */ 87 Atomic32 suspend_state; /* enum NaClSuspendState */
78 /* 88 /*
79 * suspended_registers contains the register state of the thread if 89 * suspended_registers contains the register state of the thread if
80 * it has been suspended with save_registers=1 and if suspend_state 90 * it has been suspended with save_registers=1 and if suspend_state
81 * contains NACL_APP_THREAD_UNTRUSTED. This is for use by the debug 91 * contains NACL_APP_THREAD_UNTRUSTED. This is for use by the debug
82 * stub. 92 * stub.
83 * 93 *
84 * To save space, suspended_registers is allocated on demand. It 94 * To save space, suspended_registers is allocated on demand. It
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 */ 144 */
135 uint32_t exception_flag; 145 uint32_t exception_flag;
136 146
137 /* 147 /*
138 * The last generation this thread reported into the service runtime 148 * The last generation this thread reported into the service runtime
139 * Protected by mu 149 * Protected by mu
140 */ 150 */
141 int dynamic_delete_generation; 151 int dynamic_delete_generation;
142 }; 152 };
143 153
154 void WINAPI NaClAppThreadLauncher(void *state);
155
144 void NaClAppThreadTeardown(struct NaClAppThread *natp); 156 void NaClAppThreadTeardown(struct NaClAppThread *natp);
145 157
146 /* 158 /*
147 * Low level initialization of thread, with validated values. The 159 * NaClAppThreadMake() creates a NaClAppThread object without invoking
148 * usr_entry and usr_stack_ptr values are directly used to initialize the 160 * untrusted code or creating a host thread.
149 * user register values; the sys_tls_base is the system address for 161 *
150 * allocating a %gs thread descriptor block base. The caller is 162 * The usr_entry and usr_stack_ptr values are directly used to
151 * responsible for error checking: usr_entry is a valid entry point (0 163 * initialize the user register values. The caller is responsible for
152 * mod N) and sys_tls_base is in the NaClApp's address space. 164 * error checking: usr_entry must be a valid entry point (0 mod N).
153 */ 165 */
154 struct NaClAppThread *NaClAppThreadMake(struct NaClApp *nap, 166 struct NaClAppThread *NaClAppThreadMake(struct NaClApp *nap,
155 uintptr_t usr_entry, 167 uintptr_t usr_entry,
156 uintptr_t usr_stack_ptr, 168 uintptr_t usr_stack_ptr,
157 uint32_t user_tls1, 169 uint32_t user_tls1,
158 uint32_t user_tls2) NACL_WUR; 170 uint32_t user_tls2) NACL_WUR;
159 171
172 /*
173 * NaClAppThreadSpawn() creates a NaClAppThread and launches a host
174 * thread that invokes the given entry point in untrusted code. This
175 * returns true on success, false on failure.
176 */
177 int NaClAppThreadSpawn(struct NaClApp *nap,
178 uintptr_t usr_entry,
179 uintptr_t usr_stack_ptr,
180 uint32_t user_tls1,
181 uint32_t user_tls2) NACL_WUR;
182
160 void NaClAppThreadDelete(struct NaClAppThread *natp); 183 void NaClAppThreadDelete(struct NaClAppThread *natp);
161 184
162 /* 185 /*
163 * This function can be called from the thread hosting the 186 * This function can be called from the thread hosting the
164 * NaClAppThread. It can be used to switch between the states 187 * NaClAppThread. It can be used to switch between the states
165 * NACL_APP_THREAD_TRUSTED and NACL_APP_THREAD_UNTRUSTED. 188 * NACL_APP_THREAD_TRUSTED and NACL_APP_THREAD_UNTRUSTED.
166 */ 189 */
167 void NaClAppThreadSetSuspendState(struct NaClAppThread *natp, 190 void NaClAppThreadSetSuspendState(struct NaClAppThread *natp,
168 enum NaClSuspendState old_state, 191 enum NaClSuspendState old_state,
169 enum NaClSuspendState new_state); 192 enum NaClSuspendState new_state);
170 193
171 EXTERN_C_END 194 EXTERN_C_END
172 195
173 #endif /* NATIVE_CLIENT_SERVICE_RUNTIME_NACL_APP_THREAD_H__ */ 196 #endif /* NATIVE_CLIENT_SERVICE_RUNTIME_NACL_APP_THREAD_H__ */
OLDNEW
« no previous file with comments | « src/trusted/service_runtime/linux/thread_suspension.c ('k') | src/trusted/service_runtime/nacl_app_thread.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698