#include "native_client/src/include/elf_constants.h"
#include "native_client/src/include/nacl/nacl_exception.h"
-#include "native_client/src/trusted/service_runtime/include/sys/nacl_syscalls.h"
-#include "native_client/src/untrusted/nacl/syscall_bindings_trampoline.h"
#include "native_client/tests/common/register_set.h"
#include "native_client/tests/inbrowser_test_runner/test_runner.h"
#if defined(__mips__)
#define STACK_ALIGNMENT 8
+#elif defined(__arm__) && defined(__native_client_nonsfi__)
+/* AAPCS stack alignment, for Non-SFI NaCl. */
+#define STACK_ALIGNMENT 8
#else
+/* NaCl stack alignment. */
#define STACK_ALIGNMENT 16
#endif
".p2align 4\n"
"crash_at_known_address:\n"
"mov r0, #0\n"
- "bic r0, r0, #0xc0000000\n"
+ SFI_OR_NONSFI_CODE("bic r0, r0, #0xc0000000\n", "")
"prog_ctr_at_crash:\n"
"str r0, [r0]\n"
".popsection\n");
#elif defined(__arm__)
assert(portable->frame_ptr == g_regs_at_crash.r11);
assert(context->arch == EM_ARM);
+# if !defined(__native_client_nonsfi__)
+ /* Verify we have scrubbed r9 for NaCl arm. */
assert(context->regs.r9 == -1);
+# endif
#elif defined(__mips__)
assert(portable->frame_ptr == g_regs_at_crash.frame_ptr);
assert(context->arch == EM_MIPS);
assert(frame_base % STACK_ALIGNMENT == 0);
char *frame_top = (char *) (frame_base + kArgSizeOnStack +
sizeof(struct CombinedContext));
+#if defined(__native_client_nonsfi__)
+ /*
+ * Non-SFI mode exception stack will have ucontext_t and
+ * siginfo_t, which would be anywhere from 400 bytes to 1.5k
+ */
+ assert(stack_top - 1500 < frame_top);
+#else
/* Check that no more than the stack alignment size is wasted. */
assert(stack_top - STACK_ALIGNMENT < frame_top);
+#endif
+
assert(frame_top <= stack_top);
#if defined(__x86_64__)
printf("failed to set exception handler\n");
exit(4);
}
+#if !defined(__native_client_nonsfi__)
+ /* TODO(uekawa): Implement set_stack for Non-SFI mode. */
if (0 != nacl_exception_set_stack(stack, stack_size)) {
printf("failed to set alt stack\n");
exit(5);
}
g_registered_stack = stack;
g_registered_stack_size = stack_size;
+#endif
char crash_stack[0x1000];
RegsFillTestValues(&g_regs_at_crash, /* seed= */ 0);
}
void test_getting_previous_handler(void) {
- /*
- * The direct IRT call and NaCl syscall exposes old handler as API
- * whereas nacl_exception_set_handler() does not. This test
- * exercises that path.
- */
int rc;
nacl_exception_handler_t prev_handler;
- rc = NACL_SYSCALL(exception_handler)(exception_handler, NULL);
+ rc = nacl_exception_get_and_set_handler(exception_handler, NULL);
assert(rc == 0);
- rc = NACL_SYSCALL(exception_handler)(NULL, &prev_handler);
+ rc = nacl_exception_get_and_set_handler(NULL, &prev_handler);
assert(rc == 0);
assert(prev_handler == exception_handler);
- rc = NACL_SYSCALL(exception_handler)(NULL, &prev_handler);
+ rc = nacl_exception_get_and_set_handler(NULL, &prev_handler);
assert(rc == 0);
assert(prev_handler == NULL);
}
int TestMain(void) {
RUN_TEST(test_exceptions_minimally);
- RUN_TEST(test_exception_stack_alignments);
RUN_TEST(test_getting_previous_handler);
+#if !defined(__native_client_nonsfi__)
+ /* TODO(uekawa): Implement set_stack for Non-SFI mode. */
+ RUN_TEST(test_exception_stack_alignments);
+ /* Those handlers are not invalid in NonSFI NaCl. */
RUN_TEST(test_invalid_handlers);
+#endif
/* pthread_join() is broken under qemu-arm. */
if (getenv("UNDER_QEMU_ARM") == NULL)
RUN_TEST(test_exceptions_on_non_main_thread);