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

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

Issue 616813002: Non-SFI Mode: Enable compiling exception_test for x86-32. (Closed) Base URL: https://chromium.googlesource.com/native_client/src/native_client.git@master
Patch Set: workaround part 2 Created 6 years, 2 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
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>
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 stack_top = g_registered_stack + g_registered_stack_size; 175 stack_top = g_registered_stack + g_registered_stack_size;
176 assert(g_registered_stack <= &local_var); 176 assert(g_registered_stack <= &local_var);
177 assert(&local_var < stack_top); 177 assert(&local_var < stack_top);
178 } 178 }
179 179
180 /* Check the exception handler's initial stack pointer more exactly. */ 180 /* Check the exception handler's initial stack pointer more exactly. */
181 uintptr_t frame_base = entry_regs->stack_ptr + kReturnAddrSize; 181 uintptr_t frame_base = entry_regs->stack_ptr + kReturnAddrSize;
182 assert(frame_base % STACK_ALIGNMENT == 0); 182 assert(frame_base % STACK_ALIGNMENT == 0);
183 char *frame_top = (char *) (frame_base + kArgSizeOnStack + 183 char *frame_top = (char *) (frame_base + kArgSizeOnStack +
184 sizeof(struct CombinedContext)); 184 sizeof(struct CombinedContext));
185 /* Check that no more than the stack alignment size is wasted. */ 185 if (NONSFI_MODE) {
Mark Seaborn 2014/09/30 20:32:29 As with the previous change, can you only do chang
Junichi Uekawa 2014/10/01 04:17:13 Done.
186 assert(stack_top - STACK_ALIGNMENT < frame_top); 186 /*
187 * Non-SFI mode exception stack will have ucontext_t and
188 * siginfo_t, which would be anywhere from 400 bytes to 1.5k
189 */
190 assert(stack_top - 1500 < frame_top);
191 } else {
192 /* Check that no more than the stack alignment size is wasted. */
193 assert(stack_top - STACK_ALIGNMENT < frame_top);
194 }
187 assert(frame_top <= stack_top); 195 assert(frame_top <= stack_top);
188 196
189 #if defined(__x86_64__) 197 #if defined(__x86_64__)
190 /* Check that %rsp and %rbp have safe, %r15-extended values. */ 198 /* Check that %rsp and %rbp have safe, %r15-extended values. */
191 assert(entry_regs->stack_ptr >> 32 == entry_regs->r15 >> 32); 199 assert(entry_regs->stack_ptr >> 32 == entry_regs->r15 >> 32);
192 assert(entry_regs->rbp >> 32 == entry_regs->r15 >> 32); 200 assert(entry_regs->rbp >> 32 == entry_regs->r15 >> 32);
193 #endif 201 #endif
194 202
195 return_from_exception_handler(); 203 return_from_exception_handler();
196 } 204 }
197 205
198 void test_exception_stack_with_size(char *stack, size_t stack_size) { 206 void test_exception_stack_with_size(char *stack, size_t stack_size) {
199 if (0 != nacl_exception_set_handler(exception_handler)) { 207 if (0 != nacl_exception_set_handler(exception_handler)) {
200 printf("failed to set exception handler\n"); 208 printf("failed to set exception handler\n");
201 exit(4); 209 exit(4);
202 } 210 }
211 #if !NONSFI_MODE
212 /* TODO(uekawa): Implement set_stack for Non-SFI mode. */
203 if (0 != nacl_exception_set_stack(stack, stack_size)) { 213 if (0 != nacl_exception_set_stack(stack, stack_size)) {
204 printf("failed to set alt stack\n"); 214 printf("failed to set alt stack\n");
205 exit(5); 215 exit(5);
206 } 216 }
207 g_registered_stack = stack; 217 g_registered_stack = stack;
208 g_registered_stack_size = stack_size; 218 g_registered_stack_size = stack_size;
219 #endif
209 220
210 char crash_stack[0x1000]; 221 char crash_stack[0x1000];
211 RegsFillTestValues(&g_regs_at_crash, /* seed= */ 0); 222 RegsFillTestValues(&g_regs_at_crash, /* seed= */ 0);
212 g_regs_at_crash.stack_ptr = (uintptr_t) crash_stack + sizeof(crash_stack); 223 g_regs_at_crash.stack_ptr = (uintptr_t) crash_stack + sizeof(crash_stack);
213 g_regs_at_crash.prog_ctr = (uintptr_t) prog_ctr_at_crash; 224 g_regs_at_crash.prog_ctr = (uintptr_t) prog_ctr_at_crash;
214 RegsApplySandboxConstraints(&g_regs_at_crash); 225 RegsApplySandboxConstraints(&g_regs_at_crash);
215 #if defined(__arm__) 226 #if defined(__arm__)
216 /* crash_at_known_address clobbers r0. */ 227 /* crash_at_known_address clobbers r0. */
217 g_regs_at_crash.r0 = 0; 228 g_regs_at_crash.r0 = 0;
218 #endif 229 #endif
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 400
390 void run_test(const char *test_name, void (*test_func)(void)) { 401 void run_test(const char *test_name, void (*test_func)(void)) {
391 printf("Running %s...\n", test_name); 402 printf("Running %s...\n", test_name);
392 test_func(); 403 test_func();
393 } 404 }
394 405
395 #define RUN_TEST(test_func) (run_test(#test_func, test_func)) 406 #define RUN_TEST(test_func) (run_test(#test_func, test_func))
396 407
397 int TestMain(void) { 408 int TestMain(void) {
398 RUN_TEST(test_exceptions_minimally); 409 RUN_TEST(test_exceptions_minimally);
399 RUN_TEST(test_exception_stack_alignments); 410 if (!NONSFI_MODE) {
400 RUN_TEST(test_getting_previous_handler); 411 /* TODO(uekawa): Implement set_stack for Non-SFI mode. */
401 RUN_TEST(test_invalid_handlers); 412 RUN_TEST(test_exception_stack_alignments);
413 /* NACL_SYSCALL not supported on nonsfi mode */
414 RUN_TEST(test_getting_previous_handler);
415 /* Those handlers are not invalid in NonSFI NaCl. */
416 RUN_TEST(test_invalid_handlers);
417 }
402 /* pthread_join() is broken under qemu-arm. */ 418 /* pthread_join() is broken under qemu-arm. */
403 if (getenv("UNDER_QEMU_ARM") == NULL) 419 if (getenv("UNDER_QEMU_ARM") == NULL)
404 RUN_TEST(test_exceptions_on_non_main_thread); 420 RUN_TEST(test_exceptions_on_non_main_thread);
405 RUN_TEST(test_catching_various_exception_types); 421 RUN_TEST(test_catching_various_exception_types);
406 422
407 #if defined(__i386__) || defined(__x86_64__) 423 #if defined(__i386__) || defined(__x86_64__)
408 RUN_TEST(test_get_x86_direction_flag); 424 RUN_TEST(test_get_x86_direction_flag);
409 RUN_TEST(test_unsetting_x86_direction_flag); 425 RUN_TEST(test_unsetting_x86_direction_flag);
410 #endif 426 #endif
411 427
412 fprintf(stderr, "** intended_exit_status=0\n"); 428 fprintf(stderr, "** intended_exit_status=0\n");
413 return 0; 429 return 0;
414 } 430 }
415 431
416 int main(void) { 432 int main(void) {
417 return RunTests(TestMain); 433 return RunTests(TestMain);
418 } 434 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698