OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/syscall_wrappers.h" | 5 #include "sandbox/linux/services/syscall_wrappers.h" |
6 | 6 |
7 #include <sys/syscall.h> | 7 #include <sys/syscall.h> |
8 #include <sys/types.h> | 8 #include <sys/types.h> |
9 #include <sys/wait.h> | 9 #include <sys/wait.h> |
10 #include <unistd.h> | 10 #include <unistd.h> |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 _exit(1); | 53 _exit(1); |
54 } | 54 } |
55 | 55 |
56 ASSERT_NE(-1, pid); | 56 ASSERT_NE(-1, pid); |
57 int status = 0; | 57 int status = 0; |
58 ASSERT_EQ(pid, HANDLE_EINTR(waitpid(pid, &status, 0))); | 58 ASSERT_EQ(pid, HANDLE_EINTR(waitpid(pid, &status, 0))); |
59 ASSERT_TRUE(WIFEXITED(status)); | 59 ASSERT_TRUE(WIFEXITED(status)); |
60 EXPECT_EQ(kSuccessExit, WEXITSTATUS(status)); | 60 EXPECT_EQ(kSuccessExit, WEXITSTATUS(status)); |
61 } | 61 } |
62 | 62 |
63 TEST(SyscallWrappers, ForkWithFlagsUpdatesPidCache) { | |
64 // The libc clone function, which allows ForkWithFlags to keep the pid cache | |
65 // up to date, does not work on Valgrind. | |
66 if (IsRunningOnValgrind()) { | |
67 return; | |
68 } | |
69 | |
70 // Warm up the libc pid cache, if there is one. | |
71 ASSERT_EQ(sys_getpid(), getpid()); | |
72 | |
73 pid_t ctid = 0; | |
74 pid_t pid = ForkWithFlags(CLONE_CHILD_SETTID | SIGCHLD, nullptr, &ctid); | |
75 | |
76 const int kSuccessExit = 0; | |
77 if (0 == pid) { | |
78 // In child. Check both the raw getpid syscall and the libc getpid wrapper | |
79 // (which may rely on a pid cache). | |
80 if (sys_getpid() == ctid && getpid() == ctid) | |
81 _exit(kSuccessExit); | |
82 _exit(1); | |
83 } | |
84 | |
85 ASSERT_NE(-1, pid); | |
86 int status = 0; | |
87 ASSERT_EQ(pid, HANDLE_EINTR(waitpid(pid, &status, 0))); | |
88 ASSERT_TRUE(WIFEXITED(status)); | |
89 EXPECT_EQ(kSuccessExit, WEXITSTATUS(status)); | |
90 } | |
91 | |
92 } // namespace | 63 } // namespace |
93 | 64 |
94 } // namespace sandbox | 65 } // namespace sandbox |
OLD | NEW |