| OLD | NEW |
| 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 #include <stdarg.h> | 7 #include <stdarg.h> |
| 8 #include <signal.h> | 8 #include <signal.h> |
| 9 | 9 |
| 10 #include "native_client/src/shared/gio/gio.h" | |
| 11 #include "native_client/src/shared/platform/nacl_check.h" | 10 #include "native_client/src/shared/platform/nacl_check.h" |
| 12 #include "native_client/src/shared/platform/nacl_exit.h" | 11 #include "native_client/src/shared/platform/nacl_exit.h" |
| 13 #include "native_client/src/shared/platform/nacl_log.h" | 12 #include "native_client/src/shared/platform/nacl_log.h" |
| 14 #include "native_client/src/trusted/service_runtime/include/bits/nacl_syscalls.h
" | 13 #include "native_client/src/trusted/service_runtime/include/bits/nacl_syscalls.h
" |
| 14 #include "native_client/src/trusted/service_runtime/load_file.h" |
| 15 #include "native_client/src/trusted/service_runtime/nacl_all_modules.h" | 15 #include "native_client/src/trusted/service_runtime/nacl_all_modules.h" |
| 16 #include "native_client/src/trusted/service_runtime/nacl_app.h" | 16 #include "native_client/src/trusted/service_runtime/nacl_app.h" |
| 17 #include "native_client/src/trusted/service_runtime/nacl_app_thread.h" | 17 #include "native_client/src/trusted/service_runtime/nacl_app_thread.h" |
| 18 #include "native_client/src/trusted/service_runtime/nacl_copy.h" | 18 #include "native_client/src/trusted/service_runtime/nacl_copy.h" |
| 19 #include "native_client/src/trusted/service_runtime/nacl_signal.h" | 19 #include "native_client/src/trusted/service_runtime/nacl_signal.h" |
| 20 #include "native_client/src/trusted/service_runtime/nacl_syscall_common.h" | 20 #include "native_client/src/trusted/service_runtime/nacl_syscall_common.h" |
| 21 #include "native_client/src/trusted/service_runtime/nacl_syscall_handlers.h" | 21 #include "native_client/src/trusted/service_runtime/nacl_syscall_handlers.h" |
| 22 #include "native_client/src/trusted/service_runtime/nacl_valgrind_hooks.h" | |
| 23 #include "native_client/src/trusted/service_runtime/sel_ldr.h" | 22 #include "native_client/src/trusted/service_runtime/sel_ldr.h" |
| 24 #include "native_client/tests/signal_handler_single_step/step_test_common.h" | 23 #include "native_client/tests/signal_handler_single_step/step_test_common.h" |
| 25 #include "native_client/tests/signal_handler_single_step/step_test_syscalls.h" | 24 #include "native_client/tests/signal_handler_single_step/step_test_syscalls.h" |
| 26 | 25 |
| 27 | 26 |
| 28 /* | 27 /* |
| 29 * This test case checks that NaCl's Linux signal handler can be | 28 * This test case checks that NaCl's Linux signal handler can be |
| 30 * entered at any point during the context switches between trusted | 29 * entered at any point during the context switches between trusted |
| 31 * and untrusted code. | 30 * and untrusted code. |
| 32 * | 31 * |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 } | 148 } |
| 150 | 149 |
| 151 static const struct NaClDebugCallbacks debug_callbacks = { | 150 static const struct NaClDebugCallbacks debug_callbacks = { |
| 152 ThreadCreateHook, | 151 ThreadCreateHook, |
| 153 ThreadExitHook, | 152 ThreadExitHook, |
| 154 ProcessExitHook | 153 ProcessExitHook |
| 155 }; | 154 }; |
| 156 | 155 |
| 157 int main(int argc, char **argv) { | 156 int main(int argc, char **argv) { |
| 158 struct NaClApp app; | 157 struct NaClApp app; |
| 159 struct GioMemoryFileSnapshot gio_file; | |
| 160 struct NaClSyscallTableEntry syscall_table[NACL_MAX_SYSCALLS] = {{0}}; | 158 struct NaClSyscallTableEntry syscall_table[NACL_MAX_SYSCALLS] = {{0}}; |
| 161 int index; | 159 int index; |
| 162 for (index = 0; index < NACL_MAX_SYSCALLS; index++) { | 160 for (index = 0; index < NACL_MAX_SYSCALLS; index++) { |
| 163 syscall_table[index].handler = NaClSysNotImplementedDecoder; | 161 syscall_table[index].handler = NaClSysNotImplementedDecoder; |
| 164 } | 162 } |
| 165 syscall_table[SINGLE_STEP_TEST_SYSCALL].handler = TestSyscall; | 163 syscall_table[SINGLE_STEP_TEST_SYSCALL].handler = TestSyscall; |
| 166 | 164 |
| 167 NaClAllModulesInit(); | 165 NaClAllModulesInit(); |
| 168 | 166 |
| 169 if (argc != 2) { | 167 if (argc != 2) { |
| 170 NaClLog(LOG_FATAL, "Expected 1 argument: executable filename\n"); | 168 NaClLog(LOG_FATAL, "Expected 1 argument: executable filename\n"); |
| 171 } | 169 } |
| 172 | 170 |
| 173 NaClFileNameForValgrind(argv[1]); | |
| 174 CHECK(GioMemoryFileSnapshotCtor(&gio_file, argv[1])); | |
| 175 CHECK(NaClAppWithSyscallTableCtor(&app, syscall_table)); | 171 CHECK(NaClAppWithSyscallTableCtor(&app, syscall_table)); |
| 176 | 172 |
| 177 app.debug_stub_callbacks = &debug_callbacks; | 173 app.debug_stub_callbacks = &debug_callbacks; |
| 178 NaClSignalHandlerInit(); | 174 NaClSignalHandlerInit(); |
| 179 NaClSignalHandlerAdd(TrapSignalHandler); | 175 NaClSignalHandlerAdd(TrapSignalHandler); |
| 180 | 176 |
| 181 CHECK(NaClAppLoadFile((struct Gio *) &gio_file, &app) == LOAD_OK); | 177 CHECK(NaClAppLoadFileFromFilename(&app, argv[1]) == LOAD_OK); |
| 182 CHECK(NaClAppPrepareToLaunch(&app) == LOAD_OK); | 178 CHECK(NaClAppPrepareToLaunch(&app) == LOAD_OK); |
| 183 CHECK(NaClCreateMainThread(&app, 0, NULL, NULL)); | 179 CHECK(NaClCreateMainThread(&app, 0, NULL, NULL)); |
| 184 CHECK(NaClWaitForMainThreadToExit(&app) == 0); | 180 CHECK(NaClWaitForMainThreadToExit(&app) == 0); |
| 185 | 181 |
| 186 CHECK(!g_in_untrusted_code); | 182 CHECK(!g_in_untrusted_code); |
| 187 CHECK(g_context_switch_count == kNumberOfCallsToTest * 2); | 183 CHECK(g_context_switch_count == kNumberOfCallsToTest * 2); |
| 188 | 184 |
| 189 /* | 185 /* |
| 190 * Avoid calling exit() because it runs process-global destructors | 186 * Avoid calling exit() because it runs process-global destructors |
| 191 * which might break code that is running in our unjoined threads. | 187 * which might break code that is running in our unjoined threads. |
| 192 */ | 188 */ |
| 193 NaClExit(0); | 189 NaClExit(0); |
| 194 return 0; | 190 return 0; |
| 195 } | 191 } |
| OLD | NEW |