OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/process/launch.h" | 5 #include "base/process/launch.h" |
6 | 6 |
7 #include <dirent.h> | 7 #include <dirent.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <sched.h> | 10 #include <sched.h> |
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 #endif | 704 #endif |
705 NOINLINE pid_t CloneAndLongjmpInChild(unsigned long flags, | 705 NOINLINE pid_t CloneAndLongjmpInChild(unsigned long flags, |
706 pid_t* ptid, | 706 pid_t* ptid, |
707 pid_t* ctid, | 707 pid_t* ctid, |
708 jmp_buf* env) { | 708 jmp_buf* env) { |
709 // We use the libc clone wrapper instead of making the syscall | 709 // We use the libc clone wrapper instead of making the syscall |
710 // directly because making the syscall may fail to update the libc's | 710 // directly because making the syscall may fail to update the libc's |
711 // internal pid cache. The libc interface unfortunately requires | 711 // internal pid cache. The libc interface unfortunately requires |
712 // specifying a new stack, so we use setjmp/longjmp to emulate | 712 // specifying a new stack, so we use setjmp/longjmp to emulate |
713 // fork-like behavior. | 713 // fork-like behavior. |
714 char stack_buf[PTHREAD_STACK_MIN] ALIGNAS(16); | 714 alignas(16) char stack_buf[PTHREAD_STACK_MIN]; |
715 #if defined(ARCH_CPU_X86_FAMILY) || defined(ARCH_CPU_ARM_FAMILY) || \ | 715 #if defined(ARCH_CPU_X86_FAMILY) || defined(ARCH_CPU_ARM_FAMILY) || \ |
716 defined(ARCH_CPU_MIPS_FAMILY) | 716 defined(ARCH_CPU_MIPS_FAMILY) |
717 // The stack grows downward. | 717 // The stack grows downward. |
718 void* stack = stack_buf + sizeof(stack_buf); | 718 void* stack = stack_buf + sizeof(stack_buf); |
719 #else | 719 #else |
720 #error "Unsupported architecture" | 720 #error "Unsupported architecture" |
721 #endif | 721 #endif |
722 return clone(&CloneHelper, stack, flags, env, ptid, nullptr, ctid); | 722 return clone(&CloneHelper, stack, flags, env, ptid, nullptr, ctid); |
723 } | 723 } |
724 | 724 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 jmp_buf env; | 758 jmp_buf env; |
759 if (setjmp(env) == 0) { | 759 if (setjmp(env) == 0) { |
760 return CloneAndLongjmpInChild(flags, ptid, ctid, &env); | 760 return CloneAndLongjmpInChild(flags, ptid, ctid, &env); |
761 } | 761 } |
762 | 762 |
763 return 0; | 763 return 0; |
764 } | 764 } |
765 #endif // defined(OS_LINUX) || defined(OS_NACL_NONSFI) | 765 #endif // defined(OS_LINUX) || defined(OS_NACL_NONSFI) |
766 | 766 |
767 } // namespace base | 767 } // namespace base |
OLD | NEW |