Chromium Code Reviews| Index: src/trusted/service_runtime/osx/crash_filter.c |
| =================================================================== |
| --- src/trusted/service_runtime/osx/crash_filter.c (revision 10790) |
| +++ src/trusted/service_runtime/osx/crash_filter.c (working copy) |
| @@ -6,34 +6,57 @@ |
| #include "native_client/src/trusted/service_runtime/osx/crash_filter.h" |
| -#include <mach/mach.h> |
| -#include <mach/task.h> |
| - |
| #include "native_client/src/include/nacl_macros.h" |
| #include "native_client/src/shared/platform/nacl_log.h" |
| +#include "native_client/src/trusted/service_runtime/nacl_globals.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; |
| +#if NACL_BUILD_SUBARCH == 64 |
| + size_t nacl_thread_index; |
| + struct NaClAppThread* natp; |
| +#endif |
| - 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); |
| + |
| +#if NACL_BUILD_SUBARCH == 32 |
| + return NaClMachThreadStateIsInUntrusted(&state); |
| +#elif NACL_BUILD_SUBARCH == 64 |
| + nacl_thread_index = GetNaClThreadIndexForMachThread(thread_port); |
| + |
| + /* |
| + * If the thread isn't known to Native Client, it's not untrusted (at least |
| + * not by Native Client.) |
| + */ |
| + if (!nacl_thread_index) { |
|
Mark Seaborn
2013/02/14 00:37:54
Make this "if (nacl_thread_index == NACL_TLS_INDEX
|
| + return 0; |
| } |
| + natp = NaClAppThreadGetFromIndex(nacl_thread_index); |
| + |
| + return NaClMachThreadStateIsInUntrusted(natp, &state); |
| +#endif /* NACL_BUILD_SUBARCH */ |
| +} |
| + |
| +#if NACL_BUILD_SUBARCH == 32 |
| + |
| +int NaClMachThreadStateIsInUntrusted(x86_thread_state_t *state) { |
| + uint16_t global_cs; |
| + |
| + 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 +66,18 @@ |
| return 0; |
| } |
| - return regs->__cs != global_cs; |
| + return state->uts.ts32.__cs != global_cs; |
| } |
| -#endif |
| +#elif NACL_BUILD_SUBARCH == 64 |
| + |
| +int NaClMachThreadStateIsInUntrusted(struct NaClAppThread *natp, |
| + x86_thread_state_t *state) { |
| + CHECK(state->tsh.flavor == x86_THREAD_STATE64); |
| + |
| + return NaClIsUserAddr(natp->nap, state->uts.ts64.__rip); |
| +} |
| + |
| +#endif /* NACL_BUILD_SUBARCH */ |
| + |
| +#endif /* NACL_ARCH(NACL_BUILD_ARCH) */ |