OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include <setjmp.h> | |
6 #include <signal.h> | |
7 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" | |
8 | |
9 #if defined(__arm__) | |
10 #include "sandbox/linux/services/android_arm_ucontext.h" | |
11 #elif defined(__i386__) | |
12 #include "sandbox/linux/services/android_x86_ucontext.h" | |
13 #else | |
Markus (顧孟勤)
2013/01/08 22:30:17
This is a useful unittest even if we are building
| |
14 #error "Unsupport CPU ABI" | |
15 #endif | |
16 | |
17 #include "testing/gtest/include/gtest/gtest.h" | |
18 | |
19 namespace base { | |
jln (very slow on Chromium)
2013/01/08 22:26:09
You're in sandbox.
Please look at any other _unit
| |
20 namespace android { | |
Markus (顧孟勤)
2013/01/08 22:30:17
This should not be Android specific code. Just fol
| |
21 | |
22 typedef testing::Test ucontext_test; | |
Markus (顧孟勤)
2013/01/08 22:30:17
This sounds wrong, as far as our style guide is co
| |
23 | |
24 sigjmp_buf mark; | |
25 | |
26 static int par1_v = 0xeb; | |
27 static int par2_v = 0xec; | |
28 static int par3_v = 0xed; | |
29 static int par4_v = 0xee; | |
30 static int par5_v = 0x00; | |
Markus (顧孟勤)
2013/01/08 22:30:17
Our style guide prefers the use of anonymous names
| |
31 | |
32 void sig_action(int n, siginfo_t *siginfo, void* context) | |
Markus (顧孟勤)
2013/01/08 22:30:17
While I personally think our style guide is mistak
| |
33 { | |
Markus (顧孟勤)
2013/01/08 22:30:17
The brace should probably be at the end of the pre
| |
34 ucontext_t *ctx = (ucontext_t *)context; | |
Markus (顧孟勤)
2013/01/08 22:30:17
According to our style guide, we should be using C
yfw.chromium
2013/01/09 02:38:14
Yes. several C vs C++. :).
| |
35 sigset_t set = 0; | |
36 | |
37 sigaddset(&set, SIGPIPE); | |
38 sigaddset(&set, SIGFPE); | |
Markus (顧孟勤)
2013/01/08 22:30:17
This is a little fragile. Both glibc and the kerne
yfw.chromium
2013/01/09 02:38:14
No. If kernel changes the signal mask between we s
| |
39 | |
40 /* ARM define registers array as unsigned while x86 define it as signed */ | |
41 EXPECT_EQ((unsigned long int)SECCOMP_PARM1(ctx), (unsigned long int)par1_v); | |
42 EXPECT_EQ((unsigned long int)SECCOMP_PARM2(ctx), (unsigned long int)par2_v); | |
43 EXPECT_EQ((unsigned long int)SECCOMP_PARM3(ctx), (unsigned long int)par3_v); | |
44 EXPECT_EQ((unsigned long int)SECCOMP_PARM4(ctx), (unsigned long int)par4_v); | |
45 EXPECT_EQ((unsigned long int)SECCOMP_PARM5(ctx), (unsigned long int)par5_v); | |
46 EXPECT_EQ(ctx->uc_sigmask, set); | |
Markus (顧孟勤)
2013/01/08 22:30:17
Use the comparison macros that we wrote for the sa
| |
47 siglongjmp(mark, -1); | |
48 } | |
49 | |
50 TEST_F(ucontext_test, TestUcontext) { | |
jln (very slow on Chromium)
2013/01/08 22:26:09
Please use a SANDBOX_TEST so that you get to run i
Markus (顧孟勤)
2013/01/08 22:30:17
Use the test macros that we wrote for the sandbox.
yfw.chromium
2013/01/09 02:38:14
So I suppose that it's ok child process receiving
| |
51 int ret; | |
52 struct sigaction act; | |
Markus (顧孟勤)
2013/01/08 22:30:17
If you write "struct sigaction act = { }", you don
| |
53 struct sigaction oact; | |
54 | |
55 sigset_t new_set, old_set; | |
56 | |
57 memset(&act, 0, sizeof(act)); | |
58 act.sa_sigaction = sig_action; | |
59 act.sa_flags = SA_RESTART | SA_SIGINFO; | |
Markus (顧孟勤)
2013/01/08 22:30:17
Why do you set SA_RESTART? I don't think that even
yfw.chromium
2013/01/09 02:38:14
I tried to minimize the impact of the test (Before
| |
60 sigemptyset(&act.sa_mask); | |
61 | |
62 sigemptyset(&new_set); | |
63 sigaddset(&new_set, SIGPIPE); | |
64 sigaddset(&new_set, SIGFPE); | |
65 | |
66 sigprocmask(SIG_SETMASK, &new_set, &old_set); | |
67 | |
68 if (sigsetjmp(mark, 1) != -1) { | |
69 ret = sigaction(SIGSEGV, &act, &oact); | |
70 EXPECT_EQ(ret, 0); | |
71 | |
72 #if defined(__i386__) | |
Markus (顧孟勤)
2013/01/08 22:30:17
I really would prefer if you tried to avoid using
yfw.chromium
2013/01/09 02:38:14
No. toolchain could use registers for
*(volatile c
yfw.chromium
2013/01/09 02:38:14
Done.
| |
73 asm __volatile__ ( | |
74 "movl $0xeb, %ebx\n\t" | |
75 "movl $0xec, %ecx\n\t" | |
76 "movl $0xed, %edx\n\t" | |
77 "movl $0xee, %esi\n\t" | |
78 "movl $0x00, %edi\n\t" | |
79 "movl $0x00, (%edi)\n\t" | |
80 ); | |
81 #elif defined(__arm__) | |
82 asm __volatile__ ( | |
83 "mov r0, #0xeb\n\t" | |
84 "mov r1, #0xec\n\t" | |
85 "mov r2, #0xed\n\t" | |
86 "mov r3, #0xee\n\t" | |
87 "mov r4, #0x00\n\t" | |
88 "str r3, [r4]\n\t" | |
89 ); | |
90 #endif | |
91 } | |
Markus (顧孟勤)
2013/01/08 22:30:17
How about you change one or more of the CPU regist
yfw.chromium
2013/01/09 02:38:14
If want to make sure the signal handler is called,
| |
92 | |
93 sigprocmask(SIG_SETMASK, &old_set, NULL); | |
94 sigaction(SIGSEGV, &oact, NULL); | |
95 } | |
96 | |
97 } // namespace android | |
98 } // namespace base | |
OLD | NEW |