Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: sandbox/linux/services/syscall_wrappers.cc

Issue 754433003: Update from https://crrev.com/305340 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "sandbox/linux/services/syscall_wrappers.h"
6
7 #include <sys/syscall.h>
8 #include <sys/types.h>
9 #include <unistd.h>
10
11 #include "base/logging.h"
12 #include "build/build_config.h"
13 #include "sandbox/linux/services/linux_syscalls.h"
14
15 namespace sandbox {
16
17 pid_t sys_getpid(void) {
18 return syscall(__NR_getpid);
19 }
20
21 pid_t sys_gettid(void) {
22 return syscall(__NR_gettid);
23 }
24
25 long sys_clone(unsigned long flags) {
26 return sys_clone(flags, nullptr, nullptr, nullptr, nullptr);
27 }
28
29 long sys_clone(unsigned long flags,
30 void* child_stack,
31 pid_t* ptid,
32 pid_t* ctid,
33 decltype(nullptr) tls) {
34 const bool clone_tls_used = flags & CLONE_SETTLS;
35 const bool invalid_ctid =
36 (flags & (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID)) && !ctid;
37 const bool invalid_ptid = (flags & CLONE_PARENT_SETTID) && !ptid;
38 const bool invalid_stack = (flags & CLONE_VM) && !child_stack;
39
40 if (clone_tls_used || invalid_ctid || invalid_ptid || invalid_stack) {
41 RAW_LOG(FATAL, "Invalid usage of sys_clone");
42 }
43
44 // See kernel/fork.c in Linux. There is different ordering of sys_clone
45 // parameters depending on CONFIG_CLONE_BACKWARDS* configuration options.
46 #if defined(ARCH_CPU_X86_64)
47 return syscall(__NR_clone, flags, child_stack, ptid, ctid, tls);
48 #elif defined(ARCH_CPU_X86) || defined(ARCH_CPU_ARM_FAMILY) || \
49 defined(ARCH_CPU_MIPS_FAMILY) || defined(ARCH_CPU_MIPS64_FAMILY)
50 // CONFIG_CLONE_BACKWARDS defined.
51 return syscall(__NR_clone, flags, child_stack, ptid, tls, ctid);
52 #endif
53 }
54
55 void sys_exit_group(int status) {
56 syscall(__NR_exit_group, status);
57 }
58
59 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/linux/services/syscall_wrappers.h ('k') | sandbox/linux/services/syscall_wrappers_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698