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

Unified Diff: src/trusted/service_runtime/osx/crash_filter.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 side-by-side diff with in-line comments
Download patch
Index: src/trusted/service_runtime/osx/crash_filter.c
===================================================================
--- src/trusted/service_runtime/osx/crash_filter.c (revision 10840)
+++ src/trusted/service_runtime/osx/crash_filter.c (working copy)
@@ -6,34 +6,62 @@
#include "native_client/src/trusted/service_runtime/osx/crash_filter.h"
-#include <mach/mach.h>
-#include <mach/task.h>
+#include <inttypes.h>
+#include "native_client/src/include/nacl_compiler_annotations.h"
#include "native_client/src/include/nacl_macros.h"
+#include "native_client/src/shared/platform/nacl_check.h"
#include "native_client/src/shared/platform/nacl_log.h"
+#include "native_client/src/trusted/service_runtime/nacl_app_thread.h"
+#include "native_client/src/trusted/service_runtime/nacl_globals.h"
+#include "native_client/src/trusted/service_runtime/nacl_tls.h"
+#include "native_client/src/trusted/service_runtime/osx/mach_thread_map.h"
+#include "native_client/src/trusted/service_runtime/sel_ldr.h"
#include "native_client/src/trusted/service_runtime/sel_rt.h"
-/*
- * We could provide a version for x86-64, but it would not get tested
- * because we run only minimal tests for x86-64 Mac. This function is
- * currently only used in Chromium which only uses x86-32 NaCl on Mac.
- */
-#if NACL_ARCH(NACL_BUILD_ARCH) == NACL_x86 && NACL_BUILD_SUBARCH == 32
+#if NACL_ARCH(NACL_BUILD_ARCH) == NACL_x86
int NaClMachThreadIsInUntrusted(mach_port_t thread_port) {
- natural_t regs_array[i386_THREAD_STATE_COUNT];
- mach_msg_type_number_t size = NACL_ARRAY_SIZE(regs_array);
- i386_thread_state_t *regs = (i386_thread_state_t *) regs_array;
- kern_return_t rc;
- uint16_t global_cs = NaClGetGlobalCs();
+ x86_thread_state_t state;
+ thread_state_t statep = (thread_state_t) &state;
+ mach_msg_type_number_t size = x86_THREAD_STATE_COUNT;
+ kern_return_t kr;
+ uint32_t nacl_thread_index;
- rc = thread_get_state(thread_port, i386_THREAD_STATE, regs_array, &size);
- if (rc != 0) {
- NaClLog(LOG_FATAL, "NaClMachThreadIsInUntrusted: "
- "thread_get_state() failed with error %i\n", (int) rc);
+ kr = thread_get_state(thread_port, x86_THREAD_STATE, statep, &size);
+ CHECK(kr == KERN_SUCCESS);
Mark Seaborn 2013/02/20 18:33:17 Nit: The NaClLog() call you're replacing here had
Mark Mentovai 2013/02/20 20:15:48 Mark Seaborn wrote:
+
+#if NACL_BUILD_SUBARCH == 32
+ CHECK(state.tsh.flavor == x86_THREAD_STATE32);
+ nacl_thread_index = state.uts.ts32.__gs >> 3;
Mark Seaborn 2013/02/20 18:33:17 As an aside, it's kind of weird that this value do
Mark Mentovai 2013/02/20 20:15:48 Mark Seaborn wrote:
+#elif NACL_BUILD_SUBARCH == 64
+ nacl_thread_index = NaClGetThreadIndexForMachThread(thread_port);
+#endif
+
+ /*
+ * If the thread isn't known to Native Client, it's not untrusted (at least
+ * not by Native Client.)
+ */
+ if (nacl_thread_index == NACL_TLS_INDEX_INVALID) {
Mark Seaborn 2013/02/20 18:33:17 See other comment -- for consistency with mach_exc
+ return 0;
}
+ return NaClMachThreadStateIsInUntrusted(&state, nacl_thread_index);
+}
+
+int NaClMachThreadStateIsInUntrusted(x86_thread_state_t *state,
+ size_t nacl_thread_index) {
+#if NACL_BUILD_SUBARCH == 32
+
+ uint16_t global_cs;
+
+ UNREFERENCED_PARAMETER(nacl_thread_index);
+
+ CHECK(state->tsh.flavor == x86_THREAD_STATE32);
+
+ global_cs = NaClGetGlobalCs();
+
/*
* If global_cs is 0 (which is not a usable segment selector), the
* sandbox has not been initialised yet, so there can be no untrusted
@@ -43,7 +71,18 @@
return 0;
}
- return regs->__cs != global_cs;
+ return state->uts.ts32.__cs != global_cs;
+
+#elif NACL_BUILD_SUBARCH == 64
+
+ struct NaClAppThread *natp;
+
+ CHECK(state->tsh.flavor == x86_THREAD_STATE64);
+
+ natp = NaClAppThreadGetFromIndex(nacl_thread_index);
+ return NaClIsUserAddr(natp->nap, state->uts.ts64.__rip);
+
+#endif /* NACL_BUILD_SUBARCH */
}
-#endif
+#endif /* NACL_ARCH(NACL_BUILD_ARCH) */

Powered by Google App Engine
This is Rietveld 408576698