Index: sandbox/linux/services/syscall_wrappers.cc |
diff --git a/sandbox/linux/services/syscall_wrappers.cc b/sandbox/linux/services/syscall_wrappers.cc |
index e793fad5de0a9a72dd3afa83c84f8c99b36ffe41..e4e078861c775d8653c312d2e3588c4ed5e47ca5 100644 |
--- a/sandbox/linux/services/syscall_wrappers.cc |
+++ b/sandbox/linux/services/syscall_wrappers.cc |
@@ -18,6 +18,7 @@ |
#include "base/third_party/valgrind/valgrind.h" |
#include "build/build_config.h" |
#include "sandbox/linux/system_headers/capability.h" |
+#include "sandbox/linux/system_headers/linux_signal.h" |
#include "sandbox/linux/system_headers/linux_syscalls.h" |
namespace sandbox { |
@@ -137,4 +138,63 @@ int sys_unshare(int flags) { |
return syscall(__NR_unshare, flags); |
} |
+int sys_sigprocmask( |
+ int how, const sigset_t* set, decltype(nullptr) oldset) { |
mdempsky
2015/04/13 18:55:07
Nit: This line breaking seems odd. Can you please
hidehiko
2015/04/14 11:56:41
Done.
|
+ // In some toolchain (in particular ANDROID and PNaCl toolchain), |
mdempsky
2015/04/13 18:55:07
Nit: Just "Android".
hidehiko
2015/04/14 11:56:41
Done.
|
+ // sigset_t is 32 bits, but Linux ABI requires 64 bits. |
+ uint64_t linux_value = 0; |
+ std::memcpy(&linux_value, set, std::min(sizeof(sigset_t), sizeof(uint64_t))); |
mdempsky
2015/04/13 18:55:07
Nit: You need <cstring> for std::memcpy (or <strin
hidehiko
2015/04/14 11:56:41
Done.
|
+ return syscall( |
+ __NR_rt_sigprocmask, how, &linux_value, nullptr, sizeof(linux_value)); |
+} |
+ |
+// struct sigaction is different ABI from the Linux's. |
+struct KernelSigAction { |
+ void (*kernel_handler)(int); |
+ uint32_t sa_flags; |
+ void (*sa_restorer)(void); |
+ uint64_t sa_mask; |
+}; |
+ |
+// On X86_64 arch, it is necessary to set sa_restorer always. |
+#if defined(ARCH_CPU_X86_64) |
+#if !defined(SA_RESTORER) |
+#define SA_RESTORER 0x04000000 |
+#endif |
+ |
+static void sys_rt_sigreturn() { |
+ syscall(__NR_rt_sigreturn); |
+} |
+#endif |
+ |
+int sys_sigaction(int signum, const struct sigaction* act, |
+ struct sigaction* oldact) { |
+ KernelSigAction kernel_act = {}; |
+ if (act) { |
+ kernel_act.kernel_handler = act->sa_handler; |
+ std::memcpy(&kernel_act.sa_mask, &act->sa_mask, |
+ std::min(sizeof(kernel_act.sa_mask), sizeof(act->sa_mask))); |
+ kernel_act.sa_flags = act->sa_flags; |
+ |
+#if defined(ARCH_CPU_X86_64) |
+ if (!(kernel_act.sa_flags & SA_RESTORER)) { |
+ kernel_act.sa_flags |= SA_RESTORER; |
+ kernel_act.sa_restorer = sys_rt_sigreturn; |
+ } |
+#endif |
+ } |
+ |
+ KernelSigAction kernel_oldact = {}; |
+ int result = syscall( |
+ __NR_rt_sigaction, signum, act ? &kernel_act : nullptr, |
+ oldact ? &kernel_oldact : nullptr, sizeof(uint64_t)); |
+ if (result == 0 && oldact) { |
+ oldact->sa_handler = kernel_oldact.kernel_handler; |
+ std::memcpy(&oldact->sa_mask, &kernel_oldact.sa_mask, |
mdempsky
2015/04/13 18:55:07
I think you also want to memset &oldact->sa_mask t
hidehiko
2015/04/14 11:56:40
Good catch. Done.
|
+ std::min(sizeof(kernel_act.sa_mask), sizeof(act->sa_mask))); |
+ oldact->sa_flags = kernel_oldact.sa_flags; |
+ } |
+ return result; |
+} |
+ |
} // namespace sandbox |