Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / native_client / tests / nonsfi / sigaction_test.cc
1 /*
2  * Copyright 2014 The Native Client Authors. All rights reserved.
3  * Use of this source code is governed by a BSD-style license that can be
4  * found in the LICENSE file.
5  */
6
7 #include <setjmp.h>
8 #include <signal.h>
9 #include <string.h>
10 #include <unistd.h>
11
12 #include "native_client/src/include/nacl_assert.h"
13 #include "native_client/src/nonsfi/linux/linux_sys_private.h"
14 #include "native_client/src/nonsfi/linux/linux_syscall_defines.h"
15 #include "native_client/src/nonsfi/linux/linux_syscall_structs.h"
16
17 static jmp_buf g_jmp_buf;
18
19 static void return_from_signal_handler(int signo, linux_siginfo_t *info,
20                                        void *data) {
21   ASSERT_EQ(signo, SIGSEGV);
22   ASSERT_NE(info, NULL);
23   ASSERT_EQ(info->si_signo, SIGSEGV);
24   ASSERT_NE(data, NULL);
25   longjmp(g_jmp_buf, 42);
26 }
27
28 int main(int argc, char *argv[]) {
29   struct linux_sigaction sa;
30   memset(&sa, 0, sizeof(sa));
31   sa.sa_sigaction = return_from_signal_handler;
32   sa.sa_flags = LINUX_SA_SIGINFO;
33   sigset_t *mask = (sigset_t *)&sa.sa_mask;
34   sigemptyset(mask);
35   sigaddset(mask, LINUX_SIGSEGV);
36
37   int rc = linux_sigaction(LINUX_SIGSEGV, &sa, NULL);
38   ASSERT_EQ(rc, 0);
39
40   rc = setjmp(g_jmp_buf);
41   if (rc == 0) {
42     /* Crash. */
43     *(volatile int *) 0 = 0;
44     _exit(1); /* Shouldn't reach here. */
45   }
46
47   ASSERT_EQ(rc, 42);
48
49   /*
50    * We do not test oldact (the third argument of sigaction) as user
51    * mode qemu seems not to support it and crash with it.
52    */
53
54   puts("PASSED");
55   return 0;
56 }