Index: sandbox/linux/seccomp-bpf/trap.cc |
diff --git a/sandbox/linux/seccomp-bpf/trap.cc b/sandbox/linux/seccomp-bpf/trap.cc |
index 145e62469cacca37c07aa40916c1d27795082c11..79b756952961b24b54260c09911071bb74a02ddd 100644 |
--- a/sandbox/linux/seccomp-bpf/trap.cc |
+++ b/sandbox/linux/seccomp-bpf/trap.cc |
@@ -17,12 +17,9 @@ |
#include "sandbox/linux/bpf_dsl/seccomp_macros.h" |
#include "sandbox/linux/seccomp-bpf/die.h" |
#include "sandbox/linux/seccomp-bpf/syscall.h" |
+#include "sandbox/linux/services/syscall_wrappers.h" |
#include "sandbox/linux/system_headers/linux_seccomp.h" |
- |
-// Android's signal.h doesn't define ucontext etc. |
-#if defined(OS_ANDROID) |
-#include "sandbox/linux/system_headers/android_ucontext.h" |
-#endif |
+#include "sandbox/linux/system_headers/linux_signal.h" |
namespace { |
@@ -53,13 +50,13 @@ const char kSandboxDebuggingEnv[] = "CHROME_SANDBOX_DEBUGGING"; |
// possibly even worse. |
bool GetIsInSigHandler(const ucontext_t* ctx) { |
// Note: on Android, sigismember does not take a pointer to const. |
- return sigismember(const_cast<sigset_t*>(&ctx->uc_sigmask), SIGBUS); |
+ return sigismember(const_cast<sigset_t*>(&ctx->uc_sigmask), LINUX_SIGBUS); |
} |
void SetIsInSigHandler() { |
sigset_t mask; |
- if (sigemptyset(&mask) || sigaddset(&mask, SIGBUS) || |
- sigprocmask(SIG_BLOCK, &mask, NULL)) { |
+ if (sigemptyset(&mask) || sigaddset(&mask, LINUX_SIGBUS) || |
+ sandbox::sys_sigprocmask(LINUX_SIG_BLOCK, &mask, NULL)) { |
SANDBOX_DIE("Failed to block SIGBUS"); |
} |
} |
@@ -82,10 +79,13 @@ Trap::Trap() |
has_unsafe_traps_(false) { |
// Set new SIGSYS handler |
struct sigaction sa = {}; |
- sa.sa_sigaction = SigSysAction; |
- sa.sa_flags = SA_SIGINFO | SA_NODEFER; |
- struct sigaction old_sa; |
- if (sigaction(SIGSYS, &sa, &old_sa) < 0) { |
+ // In some toolchain, sa_sigaction is not declared in struct sigaction. |
+ // So, here cast the pointer to the sa_handler's type. This works because |
+ // |sa_handler| and |sa_sigaction| shares the same memory. |
+ sa.sa_handler = reinterpret_cast<void (*)(int)>(SigSysAction); |
+ sa.sa_flags = LINUX_SA_SIGINFO | LINUX_SA_NODEFER; |
+ struct sigaction old_sa = {}; |
+ if (sys_sigaction(LINUX_SIGSYS, &sa, &old_sa) < 0) { |
SANDBOX_DIE("Failed to configure SIGSYS handler"); |
} |
@@ -99,8 +99,8 @@ Trap::Trap() |
// Unmask SIGSYS |
sigset_t mask; |
- if (sigemptyset(&mask) || sigaddset(&mask, SIGSYS) || |
- sigprocmask(SIG_UNBLOCK, &mask, NULL)) { |
+ if (sigemptyset(&mask) || sigaddset(&mask, LINUX_SIGSYS) || |
+ sys_sigprocmask(LINUX_SIG_UNBLOCK, &mask, NULL)) { |
SANDBOX_DIE("Failed to configure SIGSYS handler"); |
} |
} |
@@ -120,7 +120,7 @@ bpf_dsl::TrapRegistry* Trap::Registry() { |
return global_trap_; |
} |
-void Trap::SigSysAction(int nr, siginfo_t* info, void* void_context) { |
+void Trap::SigSysAction(int nr, LinuxSigInfo* info, void* void_context) { |
if (!global_trap_) { |
RAW_SANDBOX_DIE( |
"This can't happen. Found no global singleton instance " |
@@ -129,7 +129,7 @@ void Trap::SigSysAction(int nr, siginfo_t* info, void* void_context) { |
global_trap_->SigSys(nr, info, void_context); |
} |
-void Trap::SigSys(int nr, siginfo_t* info, void* void_context) { |
+void Trap::SigSys(int nr, LinuxSigInfo* info, void* void_context) { |
// Signal handlers should always preserve "errno". Otherwise, we could |
// trigger really subtle bugs. |
const int old_errno = errno; |
@@ -137,7 +137,7 @@ void Trap::SigSys(int nr, siginfo_t* info, void* void_context) { |
// Various sanity checks to make sure we actually received a signal |
// triggered by a BPF filter. If something else triggered SIGSYS |
// (e.g. kill()), there is really nothing we can do with this signal. |
- if (nr != SIGSYS || info->si_code != SYS_SECCOMP || !void_context || |
+ if (nr != LINUX_SIGSYS || info->si_code != SYS_SECCOMP || !void_context || |
info->si_errno <= 0 || |
static_cast<size_t>(info->si_errno) > trap_array_size_) { |
// ATI drivers seem to send SIGSYS, so this cannot be FATAL. |