1 /*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <dirent.h>
18 #include <inttypes.h>
19 #include <poll.h>
20 #include <sys/prctl.h>
21 #include <sys/ptrace.h>
22 #include <sys/types.h>
23 #include <sys/wait.h>
24 #include <unistd.h>
25
26 #include <csignal>
27 #include <cstdlib>
28 #include <cstring>
29 #include <iostream>
30 #include <thread>
31 #include <memory>
32 #include <set>
33 #include <string>
34
35 #include <android-base/file.h>
36 #include <android-base/logging.h>
37 #include <android-base/macros.h>
38 #include <android-base/parseint.h>
39 #include <android-base/stringprintf.h>
40 #include <android-base/strings.h>
41 #include <android-base/unique_fd.h>
42 #include <unwindstack/AndroidUnwinder.h>
43
44 namespace art {
45 namespace {
46
47 using android::base::StringPrintf;
48 using android::base::unique_fd;
49
50 constexpr bool kUseAddr2line = true;
51
52 namespace timeout_signal {
53
54 class SignalSet {
55 public:
SignalSet()56 SignalSet() {
57 if (sigemptyset(&set_) == -1) {
58 PLOG(FATAL) << "sigemptyset failed";
59 }
60 }
61
Add(int signal)62 void Add(int signal) {
63 if (sigaddset(&set_, signal) == -1) {
64 PLOG(FATAL) << "sigaddset " << signal << " failed";
65 }
66 }
67
Block()68 void Block() {
69 if (pthread_sigmask(SIG_BLOCK, &set_, nullptr) != 0) {
70 PLOG(FATAL) << "pthread_sigmask failed";
71 }
72 }
73
Wait()74 int Wait() {
75 // Sleep in sigwait() until a signal arrives. gdb causes EINTR failures.
76 int signal_number;
77 int rc = TEMP_FAILURE_RETRY(sigwait(&set_, &signal_number));
78 if (rc != 0) {
79 PLOG(FATAL) << "sigwait failed";
80 }
81 return signal_number;
82 }
83
84 private:
85 sigset_t set_;
86 };
87
88 } // namespace timeout_signal
89
90 namespace addr2line {
91
92 constexpr const char* kAddr2linePath =
93 "/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8/bin/x86_64-linux-addr2line";
94
FindAddr2line()95 std::unique_ptr<std::string> FindAddr2line() {
96 const char* env_value = getenv("ANDROID_BUILD_TOP");
97 if (env_value != nullptr) {
98 std::string path = std::string(env_value) + kAddr2linePath;
99 if (access(path.c_str(), X_OK) == 0) {
100 return std::make_unique<std::string>(path);
101 }
102 }
103
104 {
105 std::string path = std::string(".") + kAddr2linePath;
106 if (access(path.c_str(), X_OK) == 0) {
107 return std::make_unique<std::string>(path);
108 }
109 }
110
111 {
112 using android::base::Dirname;
113
114 std::string exec_dir = android::base::GetExecutableDirectory();
115 std::string derived_top = Dirname(Dirname(Dirname(Dirname(exec_dir))));
116 std::string path = derived_top + kAddr2linePath;
117 if (access(path.c_str(), X_OK) == 0) {
118 return std::make_unique<std::string>(path);
119 }
120 }
121
122 constexpr const char* kHostAddr2line = "/usr/bin/addr2line";
123 if (access(kHostAddr2line, F_OK) == 0) {
124 return std::make_unique<std::string>(kHostAddr2line);
125 }
126
127 return nullptr;
128 }
129
130 // The state of an open pipe to addr2line. In "server" mode, addr2line takes input on stdin
131 // and prints the result to stdout. This struct keeps the state of the open connection.
132 struct Addr2linePipe {
Addr2linePipeart::__anonfaf643200111::addr2line::Addr2linePipe133 Addr2linePipe(int in_fd, int out_fd, const std::string& file_name, pid_t pid)
134 : in(in_fd), out(out_fd), file(file_name), child_pid(pid), odd(true) {}
135
~Addr2linePipeart::__anonfaf643200111::addr2line::Addr2linePipe136 ~Addr2linePipe() {
137 kill(child_pid, SIGKILL);
138 }
139
140 unique_fd in; // The file descriptor that is connected to the output of addr2line.
141 unique_fd out; // The file descriptor that is connected to the input of addr2line.
142
143 const std::string file; // The file addr2line is working on, so that we know when to close
144 // and restart.
145 const pid_t child_pid; // The pid of the child, which we should kill when we're done.
146 bool odd; // Print state for indentation of lines.
147 };
148
Connect(const std::string & name,const char * args[])149 std::unique_ptr<Addr2linePipe> Connect(const std::string& name, const char* args[]) {
150 int caller_to_addr2line[2];
151 int addr2line_to_caller[2];
152
153 if (pipe(caller_to_addr2line) == -1) {
154 return nullptr;
155 }
156 if (pipe(addr2line_to_caller) == -1) {
157 close(caller_to_addr2line[0]);
158 close(caller_to_addr2line[1]);
159 return nullptr;
160 }
161
162 pid_t pid = fork();
163 if (pid == -1) {
164 close(caller_to_addr2line[0]);
165 close(caller_to_addr2line[1]);
166 close(addr2line_to_caller[0]);
167 close(addr2line_to_caller[1]);
168 return nullptr;
169 }
170
171 if (pid == 0) {
172 dup2(caller_to_addr2line[0], STDIN_FILENO);
173 dup2(addr2line_to_caller[1], STDOUT_FILENO);
174
175 close(caller_to_addr2line[0]);
176 close(caller_to_addr2line[1]);
177 close(addr2line_to_caller[0]);
178 close(addr2line_to_caller[1]);
179
180 execv(args[0], const_cast<char* const*>(args));
181 exit(1);
182 } else {
183 close(caller_to_addr2line[0]);
184 close(addr2line_to_caller[1]);
185 return std::make_unique<Addr2linePipe>(addr2line_to_caller[0],
186 caller_to_addr2line[1],
187 name,
188 pid);
189 }
190 }
191
WritePrefix(std::ostream & os,const char * prefix,bool odd)192 void WritePrefix(std::ostream& os, const char* prefix, bool odd) {
193 if (prefix != nullptr) {
194 os << prefix;
195 }
196 os << " ";
197 if (!odd) {
198 os << " ";
199 }
200 }
201
Drain(size_t expected,const char * prefix,std::unique_ptr<Addr2linePipe> * pipe,std::ostream & os)202 void Drain(size_t expected,
203 const char* prefix,
204 std::unique_ptr<Addr2linePipe>* pipe /* inout */,
205 std::ostream& os) {
206 DCHECK(pipe != nullptr);
207 DCHECK(pipe->get() != nullptr);
208 int in = pipe->get()->in.get();
209 DCHECK_GE(in, 0);
210
211 bool prefix_written = false;
212
213 for (;;) {
214 constexpr uint32_t kWaitTimeExpectedMilli = 500;
215 constexpr uint32_t kWaitTimeUnexpectedMilli = 50;
216
217 int timeout = expected > 0 ? kWaitTimeExpectedMilli : kWaitTimeUnexpectedMilli;
218 struct pollfd read_fd{in, POLLIN, 0};
219 int retval = TEMP_FAILURE_RETRY(poll(&read_fd, 1, timeout));
220 if (retval == -1) {
221 // An error occurred.
222 pipe->reset();
223 return;
224 }
225
226 if (retval == 0) {
227 // Timeout.
228 return;
229 }
230
231 if (!(read_fd.revents & POLLIN)) {
232 // addr2line call exited.
233 pipe->reset();
234 return;
235 }
236
237 constexpr size_t kMaxBuffer = 128; // Relatively small buffer. Should be OK as we're on an
238 // alt stack, but just to be sure...
239 char buffer[kMaxBuffer];
240 memset(buffer, 0, kMaxBuffer);
241 int bytes_read = TEMP_FAILURE_RETRY(read(in, buffer, kMaxBuffer - 1));
242 if (bytes_read <= 0) {
243 // This should not really happen...
244 pipe->reset();
245 return;
246 }
247 buffer[bytes_read] = '\0';
248
249 char* tmp = buffer;
250 while (*tmp != 0) {
251 if (!prefix_written) {
252 WritePrefix(os, prefix, (*pipe)->odd);
253 prefix_written = true;
254 }
255 char* new_line = strchr(tmp, '\n');
256 if (new_line == nullptr) {
257 os << tmp;
258
259 break;
260 } else {
261 os << std::string(tmp, new_line - tmp + 1);
262
263 tmp = new_line + 1;
264 prefix_written = false;
265 (*pipe)->odd = !(*pipe)->odd;
266
267 if (expected > 0) {
268 expected--;
269 }
270 }
271 }
272 }
273 }
274
Addr2line(const std::string & addr2line,const std::string & map_src,uintptr_t offset,std::ostream & os,const char * prefix,std::unique_ptr<Addr2linePipe> * pipe)275 void Addr2line(const std::string& addr2line,
276 const std::string& map_src,
277 uintptr_t offset,
278 std::ostream& os,
279 const char* prefix,
280 std::unique_ptr<Addr2linePipe>* pipe /* inout */) {
281 DCHECK(pipe != nullptr);
282
283 if (map_src == "[vdso]" || map_src.ends_with(".vdex")) {
284 // addr2line will not work on the vdso.
285 // vdex files are special frames injected for the interpreter
286 // so they don't have any line number information available.
287 return;
288 }
289
290 if (*pipe == nullptr || (*pipe)->file != map_src) {
291 if (*pipe != nullptr) {
292 Drain(0, prefix, pipe, os);
293 }
294 pipe->reset(); // Close early.
295
296 const char* args[] = {
297 addr2line.c_str(),
298 "--functions",
299 "--inlines",
300 "--demangle",
301 "-e",
302 map_src.c_str(),
303 nullptr
304 };
305 *pipe = Connect(map_src, args);
306 }
307
308 Addr2linePipe* pipe_ptr = pipe->get();
309 if (pipe_ptr == nullptr) {
310 // Failed...
311 return;
312 }
313
314 // Send the offset.
315 const std::string hex_offset = StringPrintf("%zx\n", offset);
316
317 if (!android::base::WriteFully(pipe_ptr->out.get(), hex_offset.data(), hex_offset.length())) {
318 // Error. :-(
319 pipe->reset();
320 return;
321 }
322
323 // Now drain (expecting two lines).
324 Drain(2U, prefix, pipe, os);
325 }
326
327 } // namespace addr2line
328
329 namespace ptrace {
330
PtraceSiblings(pid_t pid)331 std::set<pid_t> PtraceSiblings(pid_t pid) {
332 std::set<pid_t> ret;
333 std::string task_path = android::base::StringPrintf("/proc/%d/task", pid);
334
335 std::unique_ptr<DIR, int (*)(DIR*)> d(opendir(task_path.c_str()), closedir);
336
337 // Bail early if the task directory cannot be opened.
338 if (d == nullptr) {
339 PLOG(ERROR) << "Failed to scan task folder";
340 return ret;
341 }
342
343 struct dirent* de;
344 while ((de = readdir(d.get())) != nullptr) {
345 // Ignore "." and "..".
346 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) {
347 continue;
348 }
349
350 char* end;
351 pid_t tid = strtoul(de->d_name, &end, 10);
352 if (*end) {
353 continue;
354 }
355
356 if (tid == pid) {
357 continue;
358 }
359
360 if (::ptrace(PTRACE_ATTACH, tid, 0, 0) != 0) {
361 PLOG(ERROR) << "Failed to attach to tid " << tid;
362 continue;
363 }
364
365 ret.insert(tid);
366 }
367 return ret;
368 }
369
DumpABI(pid_t forked_pid)370 void DumpABI(pid_t forked_pid) {
371 enum class ABI { kArm, kArm64, kRiscv64, kX86, kX86_64 };
372 #if defined(__arm__)
373 constexpr ABI kDumperABI = ABI::kArm;
374 #elif defined(__aarch64__)
375 constexpr ABI kDumperABI = ABI::kArm64;
376 #elif defined(__riscv)
377 constexpr ABI kDumperABI = ABI::kRiscv64;
378 #elif defined(__i386__)
379 constexpr ABI kDumperABI = ABI::kX86;
380 #elif defined(__x86_64__)
381 constexpr ABI kDumperABI = ABI::kX86_64;
382 #else
383 #error Unsupported architecture
384 #endif
385
386 char data[1024]; // Should be more than enough.
387 struct iovec io_vec;
388 io_vec.iov_base = &data;
389 io_vec.iov_len = 1024;
390 ABI to_print;
391 if (0 != ::ptrace(PTRACE_GETREGSET, forked_pid, /* NT_PRSTATUS */ 1, &io_vec)) {
392 LOG(ERROR) << "Could not get registers to determine abi.";
393 // Use 64-bit as default.
394 switch (kDumperABI) {
395 case ABI::kArm:
396 case ABI::kArm64:
397 to_print = ABI::kArm64;
398 break;
399 case ABI::kRiscv64:
400 to_print = ABI::kRiscv64;
401 break;
402 case ABI::kX86:
403 case ABI::kX86_64:
404 to_print = ABI::kX86_64;
405 break;
406 }
407 } else {
408 // Check the length of the data. Assume that it's the same arch as the tool.
409 switch (kDumperABI) {
410 case ABI::kArm:
411 case ABI::kArm64:
412 to_print = io_vec.iov_len == 18 * sizeof(uint32_t) ? ABI::kArm : ABI::kArm64;
413 break;
414 case ABI::kRiscv64:
415 to_print = ABI::kRiscv64;
416 break;
417 case ABI::kX86:
418 case ABI::kX86_64:
419 to_print = io_vec.iov_len == 17 * sizeof(uint32_t) ? ABI::kX86 : ABI::kX86_64;
420 break;
421 }
422 }
423 std::string abi_str;
424 switch (to_print) {
425 case ABI::kArm:
426 abi_str = "arm";
427 break;
428 case ABI::kArm64:
429 abi_str = "arm64";
430 break;
431 case ABI::kRiscv64:
432 abi_str = "riscv64";
433 break;
434 case ABI::kX86:
435 abi_str = "x86";
436 break;
437 case ABI::kX86_64:
438 abi_str = "x86_64";
439 break;
440 }
441 LOG(ERROR) << "ABI: '" << abi_str << "'" << std::endl;
442 }
443
444 } // namespace ptrace
445
446 template <typename T>
WaitLoop(uint32_t max_wait_micros,const T & handler)447 bool WaitLoop(uint32_t max_wait_micros, const T& handler) {
448 constexpr uint32_t kWaitMicros = 10;
449 const size_t kMaxLoopCount = max_wait_micros / kWaitMicros;
450
451 for (size_t loop_count = 1; loop_count <= kMaxLoopCount; ++loop_count) {
452 bool ret;
453 if (handler(&ret)) {
454 return ret;
455 }
456 usleep(kWaitMicros);
457 }
458 return false;
459 }
460
WaitForMainSigStop(const std::atomic<bool> & saw_wif_stopped_for_main)461 bool WaitForMainSigStop(const std::atomic<bool>& saw_wif_stopped_for_main) {
462 auto handler = [&](bool* res) {
463 if (saw_wif_stopped_for_main) {
464 *res = true;
465 return true;
466 }
467 return false;
468 };
469 constexpr uint32_t kMaxWaitMicros = 30 * 1000 * 1000; // 30s wait.
470 return WaitLoop(kMaxWaitMicros, handler);
471 }
472
WaitForSigStopped(pid_t pid,uint32_t max_wait_micros)473 bool WaitForSigStopped(pid_t pid, uint32_t max_wait_micros) {
474 auto handler = [&](bool* res) {
475 int status;
476 pid_t rc = TEMP_FAILURE_RETRY(waitpid(pid, &status, WNOHANG));
477 if (rc == -1) {
478 PLOG(ERROR) << "Failed to waitpid for " << pid;
479 *res = false;
480 return true;
481 }
482 if (rc == pid) {
483 if (!(WIFSTOPPED(status))) {
484 LOG(ERROR) << "Did not get expected stopped signal for " << pid;
485 *res = false;
486 } else {
487 *res = true;
488 }
489 return true;
490 }
491 return false;
492 };
493 return WaitLoop(max_wait_micros, handler);
494 }
495
496 #ifdef __LP64__
497 constexpr bool kIs64Bit = true;
498 #else
499 constexpr bool kIs64Bit = false;
500 #endif
501
DumpThread(unwindstack::AndroidRemoteUnwinder & unwinder,pid_t pid,pid_t tid,const std::string * addr2line_path,const char * prefix)502 void DumpThread(unwindstack::AndroidRemoteUnwinder& unwinder, pid_t pid,
503 pid_t tid,
504 const std::string* addr2line_path,
505 const char* prefix) {
506 LOG(ERROR) << std::endl << "=== pid: " << pid << " tid: " << tid << " ===" << std::endl;
507
508 constexpr uint32_t kMaxWaitMicros = 1000 * 1000; // 1s.
509 if (pid != tid && !WaitForSigStopped(tid, kMaxWaitMicros)) {
510 LOG(ERROR) << "Failed to wait for sigstop on " << tid;
511 }
512
513 unwindstack::AndroidUnwinderData data;
514 if (!unwinder.Unwind(tid, data)) {
515 LOG(ERROR) << prefix << "(Unwind failed for thread " << tid << ": "
516 << data.GetErrorString() << ")";
517 return;
518 }
519
520 std::unique_ptr<addr2line::Addr2linePipe> addr2line_state;
521 data.DemangleFunctionNames();
522 for (const unwindstack::FrameData& frame : data.frames) {
523 std::ostringstream oss;
524 oss << prefix << StringPrintf("#%02zu pc ", frame.num);
525 bool try_addr2line = false;
526 if (frame.map_info == nullptr) {
527 oss << StringPrintf(kIs64Bit ? "%016" PRIx64 " ???" : "%08" PRIx64 " ???", frame.pc);
528 } else {
529 oss << StringPrintf(kIs64Bit ? "%016" PRIx64 " " : "%08" PRIx64 " ", frame.rel_pc);
530 if (frame.map_info->name().empty()) {
531 oss << StringPrintf("<anonymous:%" PRIx64 ">", frame.map_info->start());
532 } else {
533 oss << frame.map_info->name().c_str();
534 }
535 if (frame.map_info->offset() != 0) {
536 oss << StringPrintf(" (offset %" PRIx64 ")", frame.map_info->offset());
537 }
538 oss << " (";
539 const std::string& function_name = frame.function_name;
540 if (!function_name.empty()) {
541 oss << function_name;
542 if (frame.function_offset != 0) {
543 oss << "+" << frame.function_offset;
544 }
545 // Functions found using the gdb jit interface will be in an empty
546 // map that cannot be found using addr2line.
547 if (!frame.map_info->name().empty()) {
548 try_addr2line = true;
549 }
550 } else {
551 oss << "???";
552 }
553 oss << ")";
554 }
555 LOG(ERROR) << oss.str() << std::endl;
556 if (try_addr2line && addr2line_path != nullptr) {
557 addr2line::Addr2line(*addr2line_path,
558 frame.map_info->name(),
559 frame.rel_pc,
560 LOG_STREAM(ERROR),
561 prefix,
562 &addr2line_state);
563 }
564 }
565
566 if (addr2line_state != nullptr) {
567 addr2line::Drain(0, prefix, &addr2line_state, LOG_STREAM(ERROR));
568 }
569 }
570
DumpProcess(pid_t forked_pid,const std::atomic<bool> & saw_wif_stopped_for_main)571 void DumpProcess(pid_t forked_pid, const std::atomic<bool>& saw_wif_stopped_for_main) {
572 LOG(ERROR) << "Timeout for process " << forked_pid;
573
574 CHECK_EQ(0, ::ptrace(PTRACE_ATTACH, forked_pid, 0, 0));
575 std::set<pid_t> tids = ptrace::PtraceSiblings(forked_pid);
576 tids.insert(forked_pid);
577
578 ptrace::DumpABI(forked_pid);
579
580 // Check whether we have and should use addr2line.
581 std::unique_ptr<std::string> addr2line_path;
582 if (kUseAddr2line) {
583 addr2line_path = addr2line::FindAddr2line();
584 if (addr2line_path == nullptr) {
585 LOG(ERROR) << "Did not find usable addr2line";
586 }
587 }
588
589 if (!WaitForMainSigStop(saw_wif_stopped_for_main)) {
590 LOG(ERROR) << "Did not receive SIGSTOP for pid " << forked_pid;
591 }
592
593 unwindstack::AndroidRemoteUnwinder unwinder(forked_pid);
594 for (pid_t tid : tids) {
595 DumpThread(unwinder, forked_pid, tid, addr2line_path.get(), " ");
596 }
597 }
598
599 [[noreturn]]
WaitMainLoop(pid_t forked_pid,std::atomic<bool> * saw_wif_stopped_for_main)600 void WaitMainLoop(pid_t forked_pid, std::atomic<bool>* saw_wif_stopped_for_main) {
601 for (;;) {
602 // Consider switching to waitid to not get woken up for WIFSTOPPED.
603 int status;
604 pid_t res = TEMP_FAILURE_RETRY(waitpid(forked_pid, &status, 0));
605 if (res == -1) {
606 PLOG(FATAL) << "Failure during waitpid";
607 __builtin_unreachable();
608 }
609
610 if (WIFEXITED(status)) {
611 _exit(WEXITSTATUS(status));
612 __builtin_unreachable();
613 }
614 if (WIFSIGNALED(status)) {
615 _exit(1);
616 __builtin_unreachable();
617 }
618 if (WIFSTOPPED(status)) {
619 *saw_wif_stopped_for_main = true;
620 continue;
621 }
622 if (WIFCONTINUED(status)) {
623 continue;
624 }
625
626 LOG(FATAL) << "Unknown status " << std::hex << status;
627 }
628 }
629
630 [[noreturn]]
SetupAndWait(pid_t forked_pid,int signal,int timeout_exit_code)631 void SetupAndWait(pid_t forked_pid, int signal, int timeout_exit_code) {
632 timeout_signal::SignalSet signals;
633 signals.Add(signal);
634 signals.Block();
635
636 std::atomic<bool> saw_wif_stopped_for_main(false);
637
638 std::thread signal_catcher([&]() {
639 signals.Block();
640 int sig = signals.Wait();
641 CHECK_EQ(sig, signal);
642
643 DumpProcess(forked_pid, saw_wif_stopped_for_main);
644
645 // Don't clean up. Just kill the child and exit.
646 kill(forked_pid, SIGKILL);
647 _exit(timeout_exit_code);
648 });
649
650 WaitMainLoop(forked_pid, &saw_wif_stopped_for_main);
651 }
652
653 } // namespace
654 } // namespace art
655
main(int argc,char ** argv)656 int main([[maybe_unused]] int argc, char** argv) {
657 android::base::InitLogging(argv);
658
659 int signal = SIGRTMIN + 2;
660 int timeout_exit_code = 1;
661
662 size_t index = 1u;
663 CHECK(argv[index] != nullptr);
664
665 bool to_logcat = false;
666 #ifdef __ANDROID__
667 if (strcmp(argv[index], "-l") == 0) {
668 index++;
669 CHECK(argv[index] != nullptr);
670 to_logcat = true;
671 }
672 #endif
673 if (!to_logcat) {
674 android::base::SetLogger(android::base::StderrLogger);
675 }
676
677 if (strcmp(argv[index], "-s") == 0) {
678 index++;
679 CHECK(argv[index] != nullptr);
680 uint32_t signal_uint;
681 CHECK(android::base::ParseUint(argv[index], &signal_uint)) << "Signal not a number.";
682 signal = signal_uint;
683 index++;
684 CHECK(argv[index] != nullptr);
685 }
686
687 if (strcmp(argv[index], "-e") == 0) {
688 index++;
689 CHECK(argv[index] != nullptr);
690 uint32_t timeout_exit_code_uint;
691 CHECK(android::base::ParseUint(argv[index], &timeout_exit_code_uint))
692 << "Exit code not a number.";
693 timeout_exit_code = timeout_exit_code_uint;
694 index++;
695 CHECK(argv[index] != nullptr);
696 }
697
698 pid_t orig_ppid = getpid();
699
700 pid_t pid = fork();
701 if (pid == 0) {
702 if (prctl(PR_SET_PDEATHSIG, SIGTERM) == -1) {
703 _exit(1);
704 }
705
706 if (getppid() != orig_ppid) {
707 _exit(2);
708 }
709
710 execvp(argv[index], &argv[index]);
711
712 _exit(3);
713 __builtin_unreachable();
714 }
715
716 art::SetupAndWait(pid, signal, timeout_exit_code);
717 __builtin_unreachable();
718 }
719