Chromium Code Reviews| Index: sandbox/linux/services/ucontext_unittest.cc |
| diff --git a/sandbox/linux/services/ucontext_unittest.cc b/sandbox/linux/services/ucontext_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..159a0eb739692d493fc492cda9fcceff4bc86925 |
| --- /dev/null |
| +++ b/sandbox/linux/services/ucontext_unittest.cc |
| @@ -0,0 +1,98 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include <setjmp.h> |
| +#include <signal.h> |
| +#include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" |
| + |
| +#if defined(__arm__) |
| +#include "sandbox/linux/services/android_arm_ucontext.h" |
| +#elif defined(__i386__) |
| +#include "sandbox/linux/services/android_x86_ucontext.h" |
| +#else |
|
Markus (顧孟勤)
2013/01/08 22:30:17
This is a useful unittest even if we are building
|
| +#error "Unsupport CPU ABI" |
| +#endif |
| + |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace base { |
|
jln (very slow on Chromium)
2013/01/08 22:26:09
You're in sandbox.
Please look at any other _unit
|
| +namespace android { |
|
Markus (顧孟勤)
2013/01/08 22:30:17
This should not be Android specific code. Just fol
|
| + |
| +typedef testing::Test ucontext_test; |
|
Markus (顧孟勤)
2013/01/08 22:30:17
This sounds wrong, as far as our style guide is co
|
| + |
| +sigjmp_buf mark; |
| + |
| +static int par1_v = 0xeb; |
| +static int par2_v = 0xec; |
| +static int par3_v = 0xed; |
| +static int par4_v = 0xee; |
| +static int par5_v = 0x00; |
|
Markus (顧孟勤)
2013/01/08 22:30:17
Our style guide prefers the use of anonymous names
|
| + |
| +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
|
| +{ |
|
Markus (顧孟勤)
2013/01/08 22:30:17
The brace should probably be at the end of the pre
|
| + 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++. :).
|
| + sigset_t set = 0; |
| + |
| + sigaddset(&set, SIGPIPE); |
| + 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
|
| + |
| + /* ARM define registers array as unsigned while x86 define it as signed */ |
| + EXPECT_EQ((unsigned long int)SECCOMP_PARM1(ctx), (unsigned long int)par1_v); |
| + EXPECT_EQ((unsigned long int)SECCOMP_PARM2(ctx), (unsigned long int)par2_v); |
| + EXPECT_EQ((unsigned long int)SECCOMP_PARM3(ctx), (unsigned long int)par3_v); |
| + EXPECT_EQ((unsigned long int)SECCOMP_PARM4(ctx), (unsigned long int)par4_v); |
| + EXPECT_EQ((unsigned long int)SECCOMP_PARM5(ctx), (unsigned long int)par5_v); |
| + EXPECT_EQ(ctx->uc_sigmask, set); |
|
Markus (顧孟勤)
2013/01/08 22:30:17
Use the comparison macros that we wrote for the sa
|
| + siglongjmp(mark, -1); |
| +} |
| + |
| +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
|
| + int ret; |
| + struct sigaction act; |
|
Markus (顧孟勤)
2013/01/08 22:30:17
If you write "struct sigaction act = { }", you don
|
| + struct sigaction oact; |
| + |
| + sigset_t new_set, old_set; |
| + |
| + memset(&act, 0, sizeof(act)); |
| + act.sa_sigaction = sig_action; |
| + 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
|
| + sigemptyset(&act.sa_mask); |
| + |
| + sigemptyset(&new_set); |
| + sigaddset(&new_set, SIGPIPE); |
| + sigaddset(&new_set, SIGFPE); |
| + |
| + sigprocmask(SIG_SETMASK, &new_set, &old_set); |
| + |
| + if (sigsetjmp(mark, 1) != -1) { |
| + ret = sigaction(SIGSEGV, &act, &oact); |
| + EXPECT_EQ(ret, 0); |
| + |
| +#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.
|
| + asm __volatile__ ( |
| + "movl $0xeb, %ebx\n\t" |
| + "movl $0xec, %ecx\n\t" |
| + "movl $0xed, %edx\n\t" |
| + "movl $0xee, %esi\n\t" |
| + "movl $0x00, %edi\n\t" |
| + "movl $0x00, (%edi)\n\t" |
| + ); |
| +#elif defined(__arm__) |
| + asm __volatile__ ( |
| + "mov r0, #0xeb\n\t" |
| + "mov r1, #0xec\n\t" |
| + "mov r2, #0xed\n\t" |
| + "mov r3, #0xee\n\t" |
| + "mov r4, #0x00\n\t" |
| + "str r3, [r4]\n\t" |
| + ); |
| +#endif |
| + } |
|
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,
|
| + |
| + sigprocmask(SIG_SETMASK, &old_set, NULL); |
| + sigaction(SIGSEGV, &oact, NULL); |
| +} |
| + |
| +} // namespace android |
| +} // namespace base |