Fix crash on app list start page keyboard navigation with <4 apps.
[chromium-blink-merge.git] / sandbox / linux / services / syscall_wrappers.cc
blobaf9dc462f861fa99e7e8b11909bc237e9a8e8a30
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"
7 #include <pthread.h>
8 #include <sched.h>
9 #include <setjmp.h>
10 #include <sys/resource.h>
11 #include <sys/syscall.h>
12 #include <sys/time.h>
13 #include <sys/types.h>
14 #include <unistd.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"
22 namespace sandbox {
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,
34 pid_t* ptid,
35 pid_t* ctid,
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);
56 #endif
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,
68 unsigned int flags,
69 const struct sock_fprog* args) {
70 return syscall(__NR_seccomp, operation, flags, args);
73 int sys_prlimit64(pid_t pid,
74 int resource,
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