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

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 <inttypes.h>
10 #include <mach/task.h>
11 10
11 #include "native_client/src/include/nacl_compiler_annotations.h"
12 #include "native_client/src/include/nacl_macros.h" 12 #include "native_client/src/include/nacl_macros.h"
13 #include "native_client/src/shared/platform/nacl_check.h"
13 #include "native_client/src/shared/platform/nacl_log.h" 14 #include "native_client/src/shared/platform/nacl_log.h"
15 #include "native_client/src/trusted/service_runtime/nacl_app_thread.h"
16 #include "native_client/src/trusted/service_runtime/nacl_globals.h"
17 #include "native_client/src/trusted/service_runtime/nacl_tls.h"
18 #include "native_client/src/trusted/service_runtime/osx/mach_thread_map.h"
19 #include "native_client/src/trusted/service_runtime/sel_ldr.h"
14 #include "native_client/src/trusted/service_runtime/sel_rt.h" 20 #include "native_client/src/trusted/service_runtime/sel_rt.h"
15 21
16 22
17 /* 23 #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 24
24 int NaClMachThreadIsInUntrusted(mach_port_t thread_port) { 25 int NaClMachThreadIsInUntrusted(mach_port_t thread_port) {
25 natural_t regs_array[i386_THREAD_STATE_COUNT]; 26 x86_thread_state_t state;
26 mach_msg_type_number_t size = NACL_ARRAY_SIZE(regs_array); 27 thread_state_t statep = (thread_state_t) &state;
27 i386_thread_state_t *regs = (i386_thread_state_t *) regs_array; 28 mach_msg_type_number_t size = x86_THREAD_STATE_COUNT;
28 kern_return_t rc; 29 kern_return_t kr;
29 uint16_t global_cs = NaClGetGlobalCs(); 30 uint32_t nacl_thread_index;
30 31
31 rc = thread_get_state(thread_port, i386_THREAD_STATE, regs_array, &size); 32 kr = thread_get_state(thread_port, x86_THREAD_STATE, statep, &size);
32 if (rc != 0) { 33 CHECK(kr == KERN_SUCCESS);
33 NaClLog(LOG_FATAL, "NaClMachThreadIsInUntrusted: " 34
34 "thread_get_state() failed with error %i\n", (int) rc); 35 #if NACL_BUILD_SUBARCH == 32
36 CHECK(state.tsh.flavor == x86_THREAD_STATE32);
37 nacl_thread_index = state.uts.ts32.__gs >> 3;
38 #elif NACL_BUILD_SUBARCH == 64
39 nacl_thread_index = NaClGetThreadIndexForMachThread(thread_port);
40 #endif
41
42 /*
43 * If the thread isn't known to Native Client, it's not untrusted (at least
44 * not by Native Client.)
45 */
46 if (nacl_thread_index == NACL_TLS_INDEX_INVALID) {
47 return 0;
35 } 48 }
36 49
50 return NaClMachThreadStateIsInUntrusted(&state, nacl_thread_index);
51 }
52
53 int NaClMachThreadStateIsInUntrusted(x86_thread_state_t *state,
54 size_t nacl_thread_index) {
55 #if NACL_BUILD_SUBARCH == 32
56
57 uint16_t global_cs;
58
59 UNREFERENCED_PARAMETER(nacl_thread_index);
60
61 CHECK(state->tsh.flavor == x86_THREAD_STATE32);
62
63 global_cs = NaClGetGlobalCs();
64
37 /* 65 /*
38 * If global_cs is 0 (which is not a usable segment selector), the 66 * 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 67 * sandbox has not been initialised yet, so there can be no untrusted
40 * code running. 68 * code running.
41 */ 69 */
42 if (global_cs == 0) { 70 if (global_cs == 0) {
43 return 0; 71 return 0;
44 } 72 }
45 73
46 return regs->__cs != global_cs; 74 return state->uts.ts32.__cs != global_cs;
75
76 #elif NACL_BUILD_SUBARCH == 64
77
78 struct NaClAppThread *natp;
79
80 CHECK(state->tsh.flavor == x86_THREAD_STATE64);
81
82 natp = NaClAppThreadGetFromIndex(nacl_thread_index);
83 return NaClIsUserAddr(natp->nap, state->uts.ts64.__rip);
84
85 #endif /* NACL_BUILD_SUBARCH */
47 } 86 }
48 87
49 #endif 88 #endif /* NACL_ARCH(NACL_BUILD_ARCH) */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698