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

Side by Side Diff: src/trusted/service_runtime/osx/mach_thread_trusted_state.c

Issue 12207165: Mac x86_64: Mach exception support (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: Created 7 years, 10 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) 2011 The Native Client Authors. All rights reserved. 2 * Copyright (c) 2011 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 #include "native_client/src/trusted/service_runtime/osx/crash_filter.h" 7 #include "native_client/src/trusted/service_runtime/osx/mach_thread_trusted_stat e.h"
8 8
9 #include <mach/mach.h> 9 #include "native_client/src/include/nacl_compiler_annotations.h"
10 #include <mach/task.h>
11
12 #include "native_client/src/include/nacl_macros.h" 10 #include "native_client/src/include/nacl_macros.h"
13 #include "native_client/src/shared/platform/nacl_log.h" 11 #include "native_client/src/shared/platform/nacl_log.h"
12 #include "native_client/src/trusted/service_runtime/nacl_app_thread.h"
13 #include "native_client/src/trusted/service_runtime/nacl_globals.h"
14 #include "native_client/src/trusted/service_runtime/nacl_tls.h"
15 #include "native_client/src/trusted/service_runtime/osx/mach_thread_map.h"
16 #include "native_client/src/trusted/service_runtime/sel_ldr.h"
14 #include "native_client/src/trusted/service_runtime/sel_rt.h" 17 #include "native_client/src/trusted/service_runtime/sel_rt.h"
15 18
16 19
17 /* 20 #if NACL_ARCH(NACL_BUILD_ARCH) == NACL_x86
18 * We could provide a version for x86-64, but it would not get tested
19 * because we run only minimal tests for x86-64 Mac. This function is
20 * currently only used in Chromium which only uses x86-32 NaCl on Mac.
21 */
22 #if NACL_ARCH(NACL_BUILD_ARCH) == NACL_x86 && NACL_BUILD_SUBARCH == 32
23 21
24 int NaClMachThreadIsInUntrusted(mach_port_t thread_port) { 22 int NaClMachThreadIsInUntrusted(mach_port_t thread_port) {
25 natural_t regs_array[i386_THREAD_STATE_COUNT]; 23 x86_thread_state_t state;
26 mach_msg_type_number_t size = NACL_ARRAY_SIZE(regs_array); 24 thread_state_t statep = (thread_state_t) &state;
27 i386_thread_state_t *regs = (i386_thread_state_t *) regs_array; 25 mach_msg_type_number_t size = x86_THREAD_STATE_COUNT;
28 kern_return_t rc; 26 kern_return_t kr;
29 uint16_t global_cs = NaClGetGlobalCs(); 27 size_t nacl_thread_index;
30 28
31 rc = thread_get_state(thread_port, i386_THREAD_STATE, regs_array, &size); 29 kr = thread_get_state(thread_port, x86_THREAD_STATE, statep, &size);
32 if (rc != 0) { 30 CHECK(kr == KERN_SUCCESS);
33 NaClLog(LOG_FATAL, "NaClMachThreadIsInUntrusted: " 31
34 "thread_get_state() failed with error %i\n", (int) rc); 32 #if NACL_BUILD_SUBARCH == 32
33 CHECK(state.tsh.flavor == x86_THREAD_STATE32);
34 nacl_thread_index = state.uts.ts32.__gs >> 3;
35 #elif NACL_BUILD_SUBARCH == 64
36 nacl_thread_index = NaClGetThreadIndexForMachThread(thread_port);
37 #endif
38
39 /*
40 * If the thread isn't known to Native Client, it's not untrusted (at least
41 * not by Native Client.)
42 */
43 if (nacl_thread_index == NACL_TLS_INDEX_INVALID) {
44 return 0;
35 } 45 }
36 46
47 return NaClMachThreadStateIsInUntrusted(&state, nacl_thread_index);
48 }
49
50 int NaClMachThreadStateIsInUntrusted(x86_thread_state_t *state,
51 size_t nacl_thread_index) {
52 #if NACL_BUILD_SUBARCH == 32
53
54 uint16_t global_cs;
55
56 UNREFERENCED_PARAMETER(nacl_thread_index);
57
58 CHECK(state->tsh.flavor == x86_THREAD_STATE32);
59
60 global_cs = NaClGetGlobalCs();
61
37 /* 62 /*
38 * If global_cs is 0 (which is not a usable segment selector), the 63 * If global_cs is 0 (which is not a usable segment selector), the
39 * sandbox has not been initialised yet, so there can be no untrusted 64 * sandbox has not been initialised yet, so there can be no untrusted
40 * code running. 65 * code running.
41 */ 66 */
42 if (global_cs == 0) { 67 if (global_cs == 0) {
43 return 0; 68 return 0;
44 } 69 }
45 70
46 return regs->__cs != global_cs; 71 return state->uts.ts32.__cs != global_cs;
72
73 #elif NACL_BUILD_SUBARCH == 64
74
75 struct NaClAppThread *natp;
76
77 CHECK(state->tsh.flavor == x86_THREAD_STATE64);
78
79 natp = NaClAppThreadGetFromIndex(nacl_thread_index);
80 return NaClIsUserAddr(natp->nap, state->uts.ts64.__rip);
81
82 #endif /* NACL_BUILD_SUBARCH */
47 } 83 }
48 84
49 #endif 85 #endif /* NACL_ARCH(NACL_BUILD_ARCH) */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698