| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/credentials.h" | 5 #include "sandbox/linux/services/credentials.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <limits.h> | 8 #include <limits.h> |
| 9 #include <signal.h> | 9 #include <signal.h> |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 // process die. | 89 // process die. |
| 90 // 1. We don't want to simply fork() because duplicating the page tables is | 90 // 1. We don't want to simply fork() because duplicating the page tables is |
| 91 // slow with a big address space. | 91 // slow with a big address space. |
| 92 // 2. We do not use a regular thread (that would unshare CLONE_FILES) because | 92 // 2. We do not use a regular thread (that would unshare CLONE_FILES) because |
| 93 // when we are in a PID namespace, we cannot easily get a handle to the | 93 // when we are in a PID namespace, we cannot easily get a handle to the |
| 94 // /proc/tid directory for the thread (since /proc may not be aware of the | 94 // /proc/tid directory for the thread (since /proc may not be aware of the |
| 95 // PID namespace). With a process, we can just use /proc/self. | 95 // PID namespace). With a process, we can just use /proc/self. |
| 96 pid_t pid = -1; | 96 pid_t pid = -1; |
| 97 char stack_buf[PTHREAD_STACK_MIN] ALIGNAS(16); | 97 char stack_buf[PTHREAD_STACK_MIN] ALIGNAS(16); |
| 98 #if defined(ARCH_CPU_X86_FAMILY) || defined(ARCH_CPU_ARM_FAMILY) || \ | 98 #if defined(ARCH_CPU_X86_FAMILY) || defined(ARCH_CPU_ARM_FAMILY) || \ |
| 99 defined(ARCH_CPU_MIPS64_FAMILY) || defined(ARCH_CPU_MIPS_FAMILY) | 99 defined(ARCH_CPU_MIPS_FAMILY) |
| 100 // The stack grows downward. | 100 // The stack grows downward. |
| 101 void* stack = stack_buf + sizeof(stack_buf); | 101 void* stack = stack_buf + sizeof(stack_buf); |
| 102 #else | 102 #else |
| 103 #error "Unsupported architecture" | 103 #error "Unsupported architecture" |
| 104 #endif | 104 #endif |
| 105 | 105 |
| 106 int clone_flags = CLONE_FS | LINUX_SIGCHLD; | 106 int clone_flags = CLONE_FS | LINUX_SIGCHLD; |
| 107 void* tls = nullptr; | 107 void* tls = nullptr; |
| 108 #if defined(ARCH_CPU_X86_64) || defined(ARCH_CPU_ARM_FAMILY) | 108 #if defined(ARCH_CPU_X86_64) || defined(ARCH_CPU_ARM_FAMILY) |
| 109 // Use CLONE_VM | CLONE_VFORK as an optimization to avoid copying page tables. | 109 // Use CLONE_VM | CLONE_VFORK as an optimization to avoid copying page tables. |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 if (pid != 0) { | 326 if (pid != 0) { |
| 327 return pid; | 327 return pid; |
| 328 } | 328 } |
| 329 | 329 |
| 330 // Since we just forked, we are single threaded. | 330 // Since we just forked, we are single threaded. |
| 331 PCHECK(DropAllCapabilitiesOnCurrentThread()); | 331 PCHECK(DropAllCapabilitiesOnCurrentThread()); |
| 332 return 0; | 332 return 0; |
| 333 } | 333 } |
| 334 | 334 |
| 335 } // namespace sandbox. | 335 } // namespace sandbox. |
| OLD | NEW |