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

Side by Side Diff: tests/exception_test/exception_test.c

Issue 14876015: Add wrapper library for the nacl_irt_exception_handling IRT interface (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Cleanup + remove minidump_generator.gyp for now because of pthread.h problem in Gyp build Created 7 years, 7 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
« no previous file with comments | « tests/exception_test/exception_crash_test.c ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <errno.h> 8 #include <errno.h>
9 #include <pthread.h> 9 #include <pthread.h>
10 #include <setjmp.h> 10 #include <setjmp.h>
11 #include <stdint.h> 11 #include <stdint.h>
12 #include <stdio.h> 12 #include <stdio.h>
13 #include <stdlib.h> 13 #include <stdlib.h>
14 #include <string.h> 14 #include <string.h>
15 15
16 #include "native_client/src/include/elf_constants.h" 16 #include "native_client/src/include/elf_constants.h"
17 #include "native_client/src/include/nacl/nacl_exception.h" 17 #include "native_client/src/include/nacl/nacl_exception.h"
18 #include "native_client/src/trusted/service_runtime/include/sys/nacl_syscalls.h" 18 #include "native_client/src/trusted/service_runtime/include/sys/nacl_syscalls.h"
19 #include "native_client/src/untrusted/nacl/syscall_bindings_trampoline.h" 19 #include "native_client/src/untrusted/nacl/syscall_bindings_trampoline.h"
20 #include "native_client/tests/common/register_set.h" 20 #include "native_client/tests/common/register_set.h"
21 #include "native_client/tests/inbrowser_test_runner/test_runner.h" 21 #include "native_client/tests/inbrowser_test_runner/test_runner.h"
22 22
23 23
24 typedef void (*handler_func_t)(struct NaClExceptionContext *context);
25
26 /* 24 /*
27 * This is used for calculating the size of the exception stack frame 25 * This is used for calculating the size of the exception stack frame
28 * when alignment is taken into account. 26 * when alignment is taken into account.
29 */ 27 */
30 struct CombinedContext { 28 struct CombinedContext {
31 struct NaClExceptionContext c1; 29 struct NaClExceptionContext c1;
32 struct NaClExceptionPortableContext c2; 30 struct NaClExceptionPortableContext c2;
33 }; 31 };
34 32
35 char stack[0x10000]; 33 char stack[0x10000];
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 * different addresses modulo the stack alignment size. 231 * different addresses modulo the stack alignment size.
234 */ 232 */
235 int diff; 233 int diff;
236 for (diff = 0; diff <= STACK_ALIGNMENT * 2; diff++) { 234 for (diff = 0; diff <= STACK_ALIGNMENT * 2; diff++) {
237 test_exception_stack_with_size(stack, sizeof(stack) - diff); 235 test_exception_stack_with_size(stack, sizeof(stack) - diff);
238 } 236 }
239 } 237 }
240 238
241 void test_getting_previous_handler(void) { 239 void test_getting_previous_handler(void) {
242 int rc; 240 int rc;
243 handler_func_t prev_handler; 241 nacl_exception_handler_t prev_handler;
244 242
245 rc = NACL_SYSCALL(exception_handler)(exception_handler, NULL); 243 rc = NACL_SYSCALL(exception_handler)(exception_handler, NULL);
246 assert(rc == 0); 244 assert(rc == 0);
247 245
248 rc = NACL_SYSCALL(exception_handler)(NULL, &prev_handler); 246 rc = NACL_SYSCALL(exception_handler)(NULL, &prev_handler);
249 assert(rc == 0); 247 assert(rc == 0);
250 assert(prev_handler == exception_handler); 248 assert(prev_handler == exception_handler);
251 249
252 rc = NACL_SYSCALL(exception_handler)(NULL, &prev_handler); 250 rc = NACL_SYSCALL(exception_handler)(NULL, &prev_handler);
253 assert(rc == 0); 251 assert(rc == 0);
254 assert(prev_handler == NULL); 252 assert(prev_handler == NULL);
255 } 253 }
256 254
257 void test_invalid_handlers(void) { 255 void test_invalid_handlers(void) {
258 int rc; 256 int rc;
259 handler_func_t unaligned_func_ptr = 257 nacl_exception_handler_t unaligned_func_ptr =
260 (handler_func_t) ((uintptr_t) exception_handler + 1); 258 (nacl_exception_handler_t) ((uintptr_t) exception_handler + 1);
261 const char *ptr_in_rodata_segment = ""; 259 const char *ptr_in_rodata_segment = "";
262 260
263 /* An alignment check is required for safety in all NaCl sandboxes. */ 261 /* An alignment check is required for safety in all NaCl sandboxes. */
264 rc = NACL_SYSCALL(exception_handler)(unaligned_func_ptr, NULL); 262 rc = NACL_SYSCALL(exception_handler)(unaligned_func_ptr, NULL);
265 assert(rc == -EFAULT); 263 assert(rc == -EFAULT);
266 264
267 /* A range check is required for safety in the NaCl ARM sandbox. */ 265 /* A range check is required for safety in the NaCl ARM sandbox. */
268 rc = NACL_SYSCALL(exception_handler)( 266 rc = NACL_SYSCALL(exception_handler)(
269 (handler_func_t) (uintptr_t) ptr_in_rodata_segment, NULL); 267 (nacl_exception_handler_t) (uintptr_t) ptr_in_rodata_segment, NULL);
270 assert(rc == -EFAULT); 268 assert(rc == -EFAULT);
271 } 269 }
272 270
273 271
274 void *thread_func(void *unused_arg) { 272 void *thread_func(void *unused_arg) {
275 /* 273 /*
276 * This tests that the exception handler gets the correct 274 * This tests that the exception handler gets the correct
277 * NaClAppThread for this thread. If it gets the wrong thread, the 275 * NaClAppThread for this thread. If it gets the wrong thread, the
278 * handler will detect that the stack it is running on does not 276 * handler will detect that the stack it is running on does not
279 * match the stack that was registered. 277 * match the stack that was registered.
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 RUN_TEST(test_unsetting_x86_direction_flag); 366 RUN_TEST(test_unsetting_x86_direction_flag);
369 #endif 367 #endif
370 368
371 fprintf(stderr, "** intended_exit_status=0\n"); 369 fprintf(stderr, "** intended_exit_status=0\n");
372 return 0; 370 return 0;
373 } 371 }
374 372
375 int main(void) { 373 int main(void) {
376 return RunTests(TestMain); 374 return RunTests(TestMain);
377 } 375 }
OLDNEW
« no previous file with comments | « tests/exception_test/exception_crash_test.c ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698