| 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..f054fa4511394cf2c2057a24a3fa6b34916e6920
|
| --- /dev/null
|
| +++ b/sandbox/linux/services/ucontext_unittest.cc
|
| @@ -0,0 +1,80 @@
|
| +// 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"
|
| +#include "sandbox/linux/services/android_ucontext.h"
|
| +#include "sandbox/linux/tests/unit_tests.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace sandbox {
|
| +int SigHandleRun = 0;
|
| +const int kExpectedValueParm2 = 0xec;
|
| +const int kExpectedValueParm3 = 0xed;
|
| +const int kExpectedValueParm4 = 0xee;
|
| +const int kExpectedValueParm5 = 0x00;
|
| +
|
| +void SigAction(int n, siginfo_t *SigInfo, void* SigContext) {
|
| + const ucontext_t *Context = static_cast<ucontext_t*>(SigContext);
|
| + sigset_t set = 0;
|
| +
|
| + sigaddset(&set, SIGPIPE);
|
| + sigaddset(&set, SIGFPE);
|
| +
|
| + /* ARM define registers array as unsigned while x86 define it as signed */
|
| + SANDBOX_ASSERT(static_cast<int>(SECCOMP_PARM2(Context)) ==
|
| + static_cast<int>(kExpectedValueParm2));
|
| + SANDBOX_ASSERT(static_cast<int>(SECCOMP_PARM3(Context)) ==
|
| + static_cast<int>(kExpectedValueParm3));
|
| + SANDBOX_ASSERT(static_cast<int>(SECCOMP_PARM4(Context)) ==
|
| + static_cast<int>(kExpectedValueParm4));
|
| + SANDBOX_ASSERT(static_cast<int>(SECCOMP_PARM5(Context)) ==
|
| + static_cast<int>(kExpectedValueParm5));
|
| + SANDBOX_ASSERT(Context->uc_sigmask == set);
|
| + SigHandleRun = 1;
|
| +}
|
| +
|
| +SANDBOX_TEST(UcontextTest, TestUcontext) {
|
| + int junk1, junk2, junk3, junk4;
|
| + struct sigaction NewAct;
|
| + struct sigaction OldAct;
|
| + sigset_t NewSet, OldSet;
|
| +
|
| + memset(&NewAct, 0, sizeof(NewAct));
|
| + NewAct.sa_sigaction = SigAction;
|
| + NewAct.sa_flags = SA_SIGINFO;
|
| + sigemptyset(&NewAct.sa_mask);
|
| +
|
| + sigemptyset(&NewSet);
|
| + sigaddset(&NewSet, SIGPIPE);
|
| + sigaddset(&NewSet, SIGFPE);
|
| +
|
| + sigprocmask(SIG_SETMASK, &NewSet, &OldSet);
|
| + SANDBOX_ASSERT(sigaction(SIGSEGV, &NewAct, &OldAct) == 0);
|
| +
|
| +#if defined(__i386__)
|
| + asm __volatile__ (
|
| + "movl $0x00, (%%edi)\n\t"
|
| + : "=c" (junk1), "=d" (junk2), "=S" (junk3), "=D" (junk4)
|
| + : "0" (kExpectedValueParm2), "1" (kExpectedValueParm3),
|
| + "2" (kExpectedValueParm4), "3" (kExpectedValueParm5)
|
| + : "memory"
|
| + );
|
| +#elif defined(__arm__)
|
| + asm __volatile__ (
|
| + "str r3, [r4]\n\t"
|
| + : "=r1" (junk1), "=r2" (junk2), "=r3" (junk3), "=r4" (junk4)
|
| + : "0" (kExpectedValueParm2), "1" (kExpectedValueParm3),
|
| + "2" (kExpectedValueParm4), "3" (kExpectedValueParm5)
|
| + : "memory"
|
| + );
|
| +#endif
|
| +
|
| + SANDBOX_ASSERT(SigHandleRun == 1);
|
| + sigprocmask(SIG_SETMASK, &OldSet, NULL);
|
| + sigaction(SIGSEGV, &OldAct, NULL);
|
| +}
|
| +
|
| +} // namespace sandbox
|
|
|