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
3 // found in the LICENSE file.
5 #include "sandbox/linux/services/syscall_wrappers.h"
10 #include <sys/resource.h>
11 #include <sys/syscall.h>
13 #include <sys/types.h>
16 #include "base/compiler_specific.h"
17 #include "base/logging.h"
18 #include "base/third_party/valgrind/valgrind.h"
19 #include "build/build_config.h"
20 #include "sandbox/linux/system_headers/linux_syscalls.h"
24 pid_t
sys_getpid(void) {
25 return syscall(__NR_getpid
);
28 pid_t
sys_gettid(void) {
29 return syscall(__NR_gettid
);
32 long sys_clone(unsigned long flags
,
33 decltype(nullptr) child_stack
,
36 decltype(nullptr) tls
) {
37 const bool clone_tls_used
= flags
& CLONE_SETTLS
;
38 const bool invalid_ctid
=
39 (flags
& (CLONE_CHILD_SETTID
| CLONE_CHILD_CLEARTID
)) && !ctid
;
40 const bool invalid_ptid
= (flags
& CLONE_PARENT_SETTID
) && !ptid
;
42 // We do not support CLONE_VM.
43 const bool clone_vm_used
= flags
& CLONE_VM
;
44 if (clone_tls_used
|| invalid_ctid
|| invalid_ptid
|| clone_vm_used
) {
45 RAW_LOG(FATAL
, "Invalid usage of sys_clone");
48 // See kernel/fork.c in Linux. There is different ordering of sys_clone
49 // parameters depending on CONFIG_CLONE_BACKWARDS* configuration options.
50 #if defined(ARCH_CPU_X86_64)
51 return syscall(__NR_clone
, flags
, child_stack
, ptid
, ctid
, tls
);
52 #elif defined(ARCH_CPU_X86) || defined(ARCH_CPU_ARM_FAMILY) || \
53 defined(ARCH_CPU_MIPS_FAMILY) || defined(ARCH_CPU_MIPS64_FAMILY)
54 // CONFIG_CLONE_BACKWARDS defined.
55 return syscall(__NR_clone
, flags
, child_stack
, ptid
, tls
, ctid
);
59 long sys_clone(unsigned long flags
) {
60 return sys_clone(flags
, nullptr, nullptr, nullptr, nullptr);
63 void sys_exit_group(int status
) {
64 syscall(__NR_exit_group
, status
);
67 int sys_seccomp(unsigned int operation
,
69 const struct sock_fprog
* args
) {
70 return syscall(__NR_seccomp
, operation
, flags
, args
);
73 int sys_prlimit64(pid_t pid
,
75 const struct rlimit64
* new_limit
,
76 struct rlimit64
* old_limit
) {
77 return syscall(__NR_prlimit64
, pid
, resource
, new_limit
, old_limit
);
80 } // namespace sandbox