Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Unified Diff: sandbox/linux/services/ucontext_unittest.cc

Issue 11828016: ucontext_t support for Android x86. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sandbox/linux/services/android_x86_ucontext.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « sandbox/linux/services/android_x86_ucontext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698