| 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 <assert.h> | 7 #include <assert.h> |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| 11 #include <unistd.h> | 11 #include <unistd.h> |
| 12 | 12 |
| 13 #include "native_client/src/include/nacl/nacl_exception.h" | 13 #include "native_client/src/include/nacl/nacl_exception.h" |
| 14 #include "native_client/src/trusted/service_runtime/include/sys/nacl_test_crash.
h" | 14 #include "native_client/src/trusted/service_runtime/include/sys/nacl_test_crash.
h" |
| 15 #include "native_client/src/untrusted/nacl/syscall_bindings_trampoline.h" | 15 #include "native_client/src/untrusted/nacl/syscall_bindings_trampoline.h" |
| 16 | 16 |
| 17 | 17 |
| 18 typedef void (*handler_func_t)(struct NaClExceptionContext *context); | |
| 19 | |
| 20 char stack_in_rwdata[0x1000]; | 18 char stack_in_rwdata[0x1000]; |
| 21 | 19 |
| 22 /* | 20 /* |
| 23 * Note that we have to provide an initialiser here otherwise gcc | 21 * Note that we have to provide an initialiser here otherwise gcc |
| 24 * defines this using ".comm" and the variable does not get put into a | 22 * defines this using ".comm" and the variable does not get put into a |
| 25 * read-only segment. | 23 * read-only segment. |
| 26 */ | 24 */ |
| 27 const char stack_in_rodata[0x1000] = "blah"; | 25 const char stack_in_rodata[0x1000] = "blah"; |
| 28 | 26 |
| 29 | 27 |
| 30 void test_bad_handler(void) { | 28 void test_bad_handler(void) { |
| 31 /* | 29 /* |
| 32 * Use an address that we know contains no valid code, yet is within | 30 * Use an address that we know contains no valid code, yet is within |
| 33 * the code segment range and is well-aligned. The bottom 64k of | 31 * the code segment range and is well-aligned. The bottom 64k of |
| 34 * address space is never mapped. | 32 * address space is never mapped. |
| 35 */ | 33 */ |
| 36 handler_func_t handler = (handler_func_t) 0x1000; | 34 nacl_exception_handler_t handler = (nacl_exception_handler_t) 0x1000; |
| 37 int rc = NACL_SYSCALL(exception_handler)(handler, NULL); | 35 int rc = NACL_SYSCALL(exception_handler)(handler, NULL); |
| 38 assert(rc == 0); | 36 assert(rc == 0); |
| 39 fprintf(stderr, "** intended_exit_status=untrusted_segfault\n"); | 37 fprintf(stderr, "** intended_exit_status=untrusted_segfault\n"); |
| 40 /* Cause crash. */ | 38 /* Cause crash. */ |
| 41 *(volatile int *) 0 = 0; | 39 *(volatile int *) 0 = 0; |
| 42 } | 40 } |
| 43 | 41 |
| 44 | 42 |
| 45 #if defined(__i386__) || defined(__x86_64__) | 43 #if defined(__i386__) || defined(__x86_64__) |
| 46 | 44 |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 TRY_TEST(test_bad_handler); | 238 TRY_TEST(test_bad_handler); |
| 241 TRY_TEST(test_stack_outside_sandbox); | 239 TRY_TEST(test_stack_outside_sandbox); |
| 242 TRY_TEST(test_stack_in_rwdata); | 240 TRY_TEST(test_stack_in_rwdata); |
| 243 TRY_TEST(test_stack_in_rodata); | 241 TRY_TEST(test_stack_in_rodata); |
| 244 TRY_TEST(test_stack_in_code); | 242 TRY_TEST(test_stack_in_code); |
| 245 TRY_TEST(test_crash_in_syscall); | 243 TRY_TEST(test_crash_in_syscall); |
| 246 | 244 |
| 247 fprintf(stderr, "Error: Unknown test: \"%s\"\n", argv[1]); | 245 fprintf(stderr, "Error: Unknown test: \"%s\"\n", argv[1]); |
| 248 return 1; | 246 return 1; |
| 249 } | 247 } |
| OLD | NEW |