OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "sandbox/linux/services/syscall_wrappers.h" | 5 #include "sandbox/linux/services/syscall_wrappers.h" |
6 | 6 |
7 #include <pthread.h> | 7 #include <pthread.h> |
8 #include <sched.h> | 8 #include <sched.h> |
9 #include <setjmp.h> | 9 #include <setjmp.h> |
10 #include <sys/resource.h> | 10 #include <sys/resource.h> |
11 #include <sys/syscall.h> | 11 #include <sys/syscall.h> |
12 #include <sys/time.h> | 12 #include <sys/time.h> |
13 #include <sys/types.h> | 13 #include <sys/types.h> |
14 #include <unistd.h> | 14 #include <unistd.h> |
15 | 15 |
16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/third_party/valgrind/valgrind.h" | 18 #include "base/third_party/valgrind/valgrind.h" |
19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
20 #include "sandbox/linux/system_headers/capability.h" | 20 #include "sandbox/linux/system_headers/capability.h" |
21 #include "sandbox/linux/system_headers/linux_signal.h" | |
21 #include "sandbox/linux/system_headers/linux_syscalls.h" | 22 #include "sandbox/linux/system_headers/linux_syscalls.h" |
22 | 23 |
23 namespace sandbox { | 24 namespace sandbox { |
24 | 25 |
25 pid_t sys_getpid(void) { | 26 pid_t sys_getpid(void) { |
26 return syscall(__NR_getpid); | 27 return syscall(__NR_getpid); |
27 } | 28 } |
28 | 29 |
29 pid_t sys_gettid(void) { | 30 pid_t sys_gettid(void) { |
30 return syscall(__NR_gettid); | 31 return syscall(__NR_gettid); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 } | 131 } |
131 | 132 |
132 int sys_chroot(const char* path) { | 133 int sys_chroot(const char* path) { |
133 return syscall(__NR_chroot, path); | 134 return syscall(__NR_chroot, path); |
134 } | 135 } |
135 | 136 |
136 int sys_unshare(int flags) { | 137 int sys_unshare(int flags) { |
137 return syscall(__NR_unshare, flags); | 138 return syscall(__NR_unshare, flags); |
138 } | 139 } |
139 | 140 |
141 int sys_sigprocmask( | |
142 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.
| |
143 // 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.
| |
144 // sigset_t is 32 bits, but Linux ABI requires 64 bits. | |
145 uint64_t linux_value = 0; | |
146 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.
| |
147 return syscall( | |
148 __NR_rt_sigprocmask, how, &linux_value, nullptr, sizeof(linux_value)); | |
149 } | |
150 | |
151 // struct sigaction is different ABI from the Linux's. | |
152 struct KernelSigAction { | |
153 void (*kernel_handler)(int); | |
154 uint32_t sa_flags; | |
155 void (*sa_restorer)(void); | |
156 uint64_t sa_mask; | |
157 }; | |
158 | |
159 // On X86_64 arch, it is necessary to set sa_restorer always. | |
160 #if defined(ARCH_CPU_X86_64) | |
161 #if !defined(SA_RESTORER) | |
162 #define SA_RESTORER 0x04000000 | |
163 #endif | |
164 | |
165 static void sys_rt_sigreturn() { | |
166 syscall(__NR_rt_sigreturn); | |
167 } | |
168 #endif | |
169 | |
170 int sys_sigaction(int signum, const struct sigaction* act, | |
171 struct sigaction* oldact) { | |
172 KernelSigAction kernel_act = {}; | |
173 if (act) { | |
174 kernel_act.kernel_handler = act->sa_handler; | |
175 std::memcpy(&kernel_act.sa_mask, &act->sa_mask, | |
176 std::min(sizeof(kernel_act.sa_mask), sizeof(act->sa_mask))); | |
177 kernel_act.sa_flags = act->sa_flags; | |
178 | |
179 #if defined(ARCH_CPU_X86_64) | |
180 if (!(kernel_act.sa_flags & SA_RESTORER)) { | |
181 kernel_act.sa_flags |= SA_RESTORER; | |
182 kernel_act.sa_restorer = sys_rt_sigreturn; | |
183 } | |
184 #endif | |
185 } | |
186 | |
187 KernelSigAction kernel_oldact = {}; | |
188 int result = syscall( | |
189 __NR_rt_sigaction, signum, act ? &kernel_act : nullptr, | |
190 oldact ? &kernel_oldact : nullptr, sizeof(uint64_t)); | |
191 if (result == 0 && oldact) { | |
192 oldact->sa_handler = kernel_oldact.kernel_handler; | |
193 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.
| |
194 std::min(sizeof(kernel_act.sa_mask), sizeof(act->sa_mask))); | |
195 oldact->sa_flags = kernel_oldact.sa_flags; | |
196 } | |
197 return result; | |
198 } | |
199 | |
140 } // namespace sandbox | 200 } // namespace sandbox |
OLD | NEW |