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 #include "sandbox/linux/services/android_ucontext.h" |
| 9 #include "sandbox/linux/tests/unit_tests.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 namespace sandbox { |
| 13 int SigHandleRun = 0; |
| 14 const int kExpectedValueParm2 = 0xec; |
| 15 const int kExpectedValueParm3 = 0xed; |
| 16 const int kExpectedValueParm4 = 0xee; |
| 17 const int kExpectedValueParm5 = 0x00; |
| 18 |
| 19 void SigAction(int n, siginfo_t *SigInfo, void* SigContext) { |
| 20 const ucontext_t *Context = static_cast<ucontext_t*>(SigContext); |
| 21 sigset_t set = 0; |
| 22 |
| 23 sigaddset(&set, SIGPIPE); |
| 24 sigaddset(&set, SIGFPE); |
| 25 |
| 26 /* ARM define registers array as unsigned while x86 define it as signed */ |
| 27 SANDBOX_ASSERT(static_cast<int>(SECCOMP_PARM2(Context)) == |
| 28 static_cast<int>(kExpectedValueParm2)); |
| 29 SANDBOX_ASSERT(static_cast<int>(SECCOMP_PARM3(Context)) == |
| 30 static_cast<int>(kExpectedValueParm3)); |
| 31 SANDBOX_ASSERT(static_cast<int>(SECCOMP_PARM4(Context)) == |
| 32 static_cast<int>(kExpectedValueParm4)); |
| 33 SANDBOX_ASSERT(static_cast<int>(SECCOMP_PARM5(Context)) == |
| 34 static_cast<int>(kExpectedValueParm5)); |
| 35 SANDBOX_ASSERT(Context->uc_sigmask == set); |
| 36 SigHandleRun = 1; |
| 37 } |
| 38 |
| 39 SANDBOX_TEST(UcontextTest, TestUcontext) { |
| 40 int junk1, junk2, junk3, junk4; |
| 41 struct sigaction NewAct; |
| 42 struct sigaction OldAct; |
| 43 sigset_t NewSet, OldSet; |
| 44 |
| 45 memset(&NewAct, 0, sizeof(NewAct)); |
| 46 NewAct.sa_sigaction = SigAction; |
| 47 NewAct.sa_flags = SA_SIGINFO; |
| 48 sigemptyset(&NewAct.sa_mask); |
| 49 |
| 50 sigemptyset(&NewSet); |
| 51 sigaddset(&NewSet, SIGPIPE); |
| 52 sigaddset(&NewSet, SIGFPE); |
| 53 |
| 54 sigprocmask(SIG_SETMASK, &NewSet, &OldSet); |
| 55 SANDBOX_ASSERT(sigaction(SIGSEGV, &NewAct, &OldAct) == 0); |
| 56 |
| 57 #if defined(__i386__) |
| 58 asm __volatile__ ( |
| 59 "movl $0x00, (%%edi)\n\t" |
| 60 : "=c" (junk1), "=d" (junk2), "=S" (junk3), "=D" (junk4) |
| 61 : "0" (kExpectedValueParm2), "1" (kExpectedValueParm3), |
| 62 "2" (kExpectedValueParm4), "3" (kExpectedValueParm5) |
| 63 : "memory" |
| 64 ); |
| 65 #elif defined(__arm__) |
| 66 asm __volatile__ ( |
| 67 "str r3, [r4]\n\t" |
| 68 : "=r1" (junk1), "=r2" (junk2), "=r3" (junk3), "=r4" (junk4) |
| 69 : "0" (kExpectedValueParm2), "1" (kExpectedValueParm3), |
| 70 "2" (kExpectedValueParm4), "3" (kExpectedValueParm5) |
| 71 : "memory" |
| 72 ); |
| 73 #endif |
| 74 |
| 75 SANDBOX_ASSERT(SigHandleRun == 1); |
| 76 sigprocmask(SIG_SETMASK, &OldSet, NULL); |
| 77 sigaction(SIGSEGV, &OldAct, NULL); |
| 78 } |
| 79 |
| 80 } // namespace sandbox |
OLD | NEW |