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

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

Issue 10392005: Thread suspension: Implement for Linux (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Comment about docs Created 8 years, 7 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 #ifndef NATIVE_CLIENT_SERVICE_RUNTIME_NACL_APP_THREAD_H__ 11 #ifndef NATIVE_CLIENT_SERVICE_RUNTIME_NACL_APP_THREAD_H__
12 #define NATIVE_CLIENT_SERVICE_RUNTIME_NACL_APP_THREAD_H__ 1 12 #define NATIVE_CLIENT_SERVICE_RUNTIME_NACL_APP_THREAD_H__ 1
13 13
14 #include "native_client/src/include/atomic_ops.h"
14 #include "native_client/src/shared/platform/nacl_sync.h" 15 #include "native_client/src/shared/platform/nacl_sync.h"
15 #include "native_client/src/shared/platform/nacl_threads.h" 16 #include "native_client/src/shared/platform/nacl_threads.h"
16 #include "native_client/src/trusted/service_runtime/nacl_signal.h" 17 #include "native_client/src/trusted/service_runtime/nacl_signal.h"
17 #include "native_client/src/trusted/service_runtime/sel_rt.h" 18 #include "native_client/src/trusted/service_runtime/sel_rt.h"
18 19
19 20
20 EXTERN_C_BEGIN 21 EXTERN_C_BEGIN
21 22
22 struct NaClApp; 23 struct NaClApp;
23 24
24 /* 25 /*
25 * The thread hosting the NaClAppThread may change suspend_state 26 * The thread hosting the NaClAppThread may change suspend_state
26 * between NACL_APP_THREAD_TRUSTED and NACL_APP_THREAD_UNTRUSTED using 27 * between NACL_APP_THREAD_TRUSTED and NACL_APP_THREAD_UNTRUSTED using
27 * NaClAppThreadSetSuspendState(). 28 * NaClAppThreadSetSuspendState().
28 * 29 *
29 * Another thread may change this from: 30 * A controlling thread may change this from:
30 * NACL_APP_THREAD_UNTRUSTED 31 * NACL_APP_THREAD_UNTRUSTED
31 * -> NACL_APP_THREAD_UNTRUSTED | NACL_APP_THREAD_SUSPENDING 32 * -> NACL_APP_THREAD_UNTRUSTED | NACL_APP_THREAD_SUSPENDING
32 * or 33 * or
33 * NACL_APP_THREAD_TRUSTED 34 * NACL_APP_THREAD_TRUSTED
34 * -> NACL_APP_THREAD_TRUSTED | NACL_APP_THREAD_SUSPENDING 35 * -> NACL_APP_THREAD_TRUSTED | NACL_APP_THREAD_SUSPENDING
35 * and back again. 36 * and back again.
37 *
38 * Additionally, on Linux, the signal handler in the thread being
39 * suspended will change suspend_state from:
40 * NACL_APP_THREAD_UNTRUSTED | NACL_APP_THREAD_SUSPENDING
41 * -> (NACL_APP_THREAD_UNTRUSTED | NACL_APP_THREAD_SUSPENDING
42 * | NACL_APP_THREAD_SUSPENDED)
43 * The controlling thread will later change suspend_thread back to:
44 * NACL_APP_THREAD_UNTRUSTED
45 * This tells the signal handler to resume execution.
36 */ 46 */
37 enum NaClSuspendState { 47 enum NaClSuspendState {
38 NACL_APP_THREAD_UNTRUSTED = 1, 48 NACL_APP_THREAD_UNTRUSTED = 1,
39 NACL_APP_THREAD_TRUSTED = 2, 49 NACL_APP_THREAD_TRUSTED = 2,
40 NACL_APP_THREAD_SUSPENDING = 4 50 NACL_APP_THREAD_SUSPENDING = 4
51 #if NACL_LINUX
52 , NACL_APP_THREAD_SUSPENDED = 8
53 #endif
41 }; 54 };
42 55
43 /* 56 /*
44 * Generally, only the thread itself will need to manipulate this 57 * Generally, only the thread itself will need to manipulate this
45 * structure, but occasionally we may need to blow away a thread for 58 * structure, but occasionally we may need to blow away a thread for
46 * some reason, and look inside. While a thread is in the NaCl 59 * some reason, and look inside. While a thread is in the NaCl
47 * application running untrusted code, the lock must *not* be held. 60 * application running untrusted code, the lock must *not* be held.
48 */ 61 */
49 struct NaClAppThread { 62 struct NaClAppThread {
50 struct NaClMutex mu; 63 struct NaClMutex mu;
(...skipping 14 matching lines...) Expand all
65 * accessed via the %gs segment register on x86-32 so must point 78 * accessed via the %gs segment register on x86-32 so must point
66 * into untrusted address space; we store it as a system pointer. 79 * into untrusted address space; we store it as a system pointer.
67 * The second TLS may be an arbitrary value. 80 * The second TLS may be an arbitrary value.
68 */ 81 */
69 uintptr_t sys_tls; /* first saved TLS ptr */ 82 uintptr_t sys_tls; /* first saved TLS ptr */
70 uint32_t *usr_tlsp; 83 uint32_t *usr_tlsp;
71 uint32_t tls2; /* second saved TLS value */ 84 uint32_t tls2; /* second saved TLS value */
72 85
73 struct NaClThread thread; /* low level thread representation */ 86 struct NaClThread thread; /* low level thread representation */
74 87
75 /* 88 Atomic32 suspend_state; /* enum NaClSuspendState */
76 * Thread suspension is currently only needed and implemented for
77 * Windows, for preventing race conditions when opening up holes in
78 * untrusted address space during mmap/munmap.
79 */
80 #if NACL_WINDOWS
81 enum NaClSuspendState suspend_state;
82 #endif
83 89
84 struct NaClThreadContext user; 90 struct NaClThreadContext user;
85 struct NaClThreadContext sys; 91 struct NaClThreadContext sys;
86 /* 92 /*
87 * NaClThread abstraction allows us to specify the stack size 93 * NaClThread abstraction allows us to specify the stack size
88 * (NACL_KERN_STACK_SIZE), but not its location. The underlying 94 * (NACL_KERN_STACK_SIZE), but not its location. The underlying
89 * implementation takes care of finding memory for the thread stack, 95 * implementation takes care of finding memory for the thread stack,
90 * and when the thread exits (they're not joinable), the stack 96 * and when the thread exits (they're not joinable), the stack
91 * should be automatically released. 97 * should be automatically released.
92 */ 98 */
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 * NaClAppThread. It can be used to switch between the states 151 * NaClAppThread. It can be used to switch between the states
146 * NACL_APP_THREAD_TRUSTED and NACL_APP_THREAD_UNTRUSTED. 152 * NACL_APP_THREAD_TRUSTED and NACL_APP_THREAD_UNTRUSTED.
147 */ 153 */
148 void NaClAppThreadSetSuspendState(struct NaClAppThread *natp, 154 void NaClAppThreadSetSuspendState(struct NaClAppThread *natp,
149 enum NaClSuspendState old_state, 155 enum NaClSuspendState old_state,
150 enum NaClSuspendState new_state); 156 enum NaClSuspendState new_state);
151 157
152 EXTERN_C_END 158 EXTERN_C_END
153 159
154 #endif /* NATIVE_CLIENT_SERVICE_RUNTIME_NACL_APP_THREAD_H__ */ 160 #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