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::__anon1006f6110111::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::__anon1006f6110111::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]" || android::base::EndsWith(map_src, ".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 default:
407 __builtin_unreachable();
408 }
409 } else {
410 // Check the length of the data. Assume that it's the same arch as the tool.
411 switch (kDumperABI) {
412 case ABI::kArm:
413 case ABI::kArm64:
414 to_print = io_vec.iov_len == 18 * sizeof(uint32_t) ? ABI::kArm : ABI::kArm64;
415 break;
416 case ABI::kRiscv64:
417 to_print = ABI::kRiscv64;
418 break;
419 case ABI::kX86:
420 case ABI::kX86_64:
421 to_print = io_vec.iov_len == 17 * sizeof(uint32_t) ? ABI::kX86 : ABI::kX86_64;
422 break;
423 default:
424 __builtin_unreachable();
425 }
426 }
427 std::string abi_str;
428 switch (to_print) {
429 case ABI::kArm:
430 abi_str = "arm";
431 break;
432 case ABI::kArm64:
433 abi_str = "arm64";
434 break;
435 case ABI::kRiscv64:
436 abi_str = "riscv64";
437 break;
438 case ABI::kX86:
439 abi_str = "x86";
440 break;
441 case ABI::kX86_64:
442 abi_str = "x86_64";
443 break;
444 }
445 LOG(ERROR) << "ABI: '" << abi_str << "'" << std::endl;
446 }
447
448 } // namespace ptrace
449
450 template <typename T>
WaitLoop(uint32_t max_wait_micros,const T & handler)451 bool WaitLoop(uint32_t max_wait_micros, const T& handler) {
452 constexpr uint32_t kWaitMicros = 10;
453 const size_t kMaxLoopCount = max_wait_micros / kWaitMicros;
454
455 for (size_t loop_count = 1; loop_count <= kMaxLoopCount; ++loop_count) {
456 bool ret;
457 if (handler(&ret)) {
458 return ret;
459 }
460 usleep(kWaitMicros);
461 }
462 return false;
463 }
464
WaitForMainSigStop(const std::atomic<bool> & saw_wif_stopped_for_main)465 bool WaitForMainSigStop(const std::atomic<bool>& saw_wif_stopped_for_main) {
466 auto handler = [&](bool* res) {
467 if (saw_wif_stopped_for_main) {
468 *res = true;
469 return true;
470 }
471 return false;
472 };
473 constexpr uint32_t kMaxWaitMicros = 30 * 1000 * 1000; // 30s wait.
474 return WaitLoop(kMaxWaitMicros, handler);
475 }
476
WaitForSigStopped(pid_t pid,uint32_t max_wait_micros)477 bool WaitForSigStopped(pid_t pid, uint32_t max_wait_micros) {
478 auto handler = [&](bool* res) {
479 int status;
480 pid_t rc = TEMP_FAILURE_RETRY(waitpid(pid, &status, WNOHANG));
481 if (rc == -1) {
482 PLOG(ERROR) << "Failed to waitpid for " << pid;
483 *res = false;
484 return true;
485 }
486 if (rc == pid) {
487 if (!(WIFSTOPPED(status))) {
488 LOG(ERROR) << "Did not get expected stopped signal for " << pid;
489 *res = false;
490 } else {
491 *res = true;
492 }
493 return true;
494 }
495 return false;
496 };
497 return WaitLoop(max_wait_micros, handler);
498 }
499
500 #ifdef __LP64__
501 constexpr bool kIs64Bit = true;
502 #else
503 constexpr bool kIs64Bit = false;
504 #endif
505
DumpThread(unwindstack::AndroidRemoteUnwinder & unwinder,pid_t pid,pid_t tid,const std::string * addr2line_path,const char * prefix)506 void DumpThread(unwindstack::AndroidRemoteUnwinder& unwinder, pid_t pid,
507 pid_t tid,
508 const std::string* addr2line_path,
509 const char* prefix) {
510 LOG(ERROR) << std::endl << "=== pid: " << pid << " tid: " << tid << " ===" << std::endl;
511
512 constexpr uint32_t kMaxWaitMicros = 1000 * 1000; // 1s.
513 if (pid != tid && !WaitForSigStopped(tid, kMaxWaitMicros)) {
514 LOG(ERROR) << "Failed to wait for sigstop on " << tid;
515 }
516
517 unwindstack::AndroidUnwinderData data;
518 if (!unwinder.Unwind(tid, data)) {
519 LOG(ERROR) << prefix << "(Unwind failed for thread " << tid << ": "
520 << data.GetErrorString() << ")";
521 return;
522 }
523
524 std::unique_ptr<addr2line::Addr2linePipe> addr2line_state;
525 data.DemangleFunctionNames();
526 for (const unwindstack::FrameData& frame : data.frames) {
527 std::ostringstream oss;
528 oss << prefix << StringPrintf("#%02zu pc ", frame.num);
529 bool try_addr2line = false;
530 if (frame.map_info == nullptr) {
531 oss << StringPrintf(kIs64Bit ? "%016" PRIx64 " ???" : "%08" PRIx64 " ???", frame.pc);
532 } else {
533 oss << StringPrintf(kIs64Bit ? "%016" PRIx64 " " : "%08" PRIx64 " ", frame.rel_pc);
534 if (frame.map_info->name().empty()) {
535 oss << StringPrintf("<anonymous:%" PRIx64 ">", frame.map_info->start());
536 } else {
537 oss << frame.map_info->name().c_str();
538 }
539 if (frame.map_info->offset() != 0) {
540 oss << StringPrintf(" (offset %" PRIx64 ")", frame.map_info->offset());
541 }
542 oss << " (";
543 const std::string& function_name = frame.function_name;
544 if (!function_name.empty()) {
545 oss << function_name;
546 if (frame.function_offset != 0) {
547 oss << "+" << frame.function_offset;
548 }
549 // Functions found using the gdb jit interface will be in an empty
550 // map that cannot be found using addr2line.
551 if (!frame.map_info->name().empty()) {
552 try_addr2line = true;
553 }
554 } else {
555 oss << "???";
556 }
557 oss << ")";
558 }
559 LOG(ERROR) << oss.str() << std::endl;
560 if (try_addr2line && addr2line_path != nullptr) {
561 addr2line::Addr2line(*addr2line_path,
562 frame.map_info->name(),
563 frame.rel_pc,
564 LOG_STREAM(ERROR),
565 prefix,
566 &addr2line_state);
567 }
568 }
569
570 if (addr2line_state != nullptr) {
571 addr2line::Drain(0, prefix, &addr2line_state, LOG_STREAM(ERROR));
572 }
573 }
574
DumpProcess(pid_t forked_pid,const std::atomic<bool> & saw_wif_stopped_for_main)575 void DumpProcess(pid_t forked_pid, const std::atomic<bool>& saw_wif_stopped_for_main) {
576 LOG(ERROR) << "Timeout for process " << forked_pid;
577
578 CHECK_EQ(0, ::ptrace(PTRACE_ATTACH, forked_pid, 0, 0));
579 std::set<pid_t> tids = ptrace::PtraceSiblings(forked_pid);
580 tids.insert(forked_pid);
581
582 ptrace::DumpABI(forked_pid);
583
584 // Check whether we have and should use addr2line.
585 std::unique_ptr<std::string> addr2line_path;
586 if (kUseAddr2line) {
587 addr2line_path = addr2line::FindAddr2line();
588 if (addr2line_path == nullptr) {
589 LOG(ERROR) << "Did not find usable addr2line";
590 }
591 }
592
593 if (!WaitForMainSigStop(saw_wif_stopped_for_main)) {
594 LOG(ERROR) << "Did not receive SIGSTOP for pid " << forked_pid;
595 }
596
597 unwindstack::AndroidRemoteUnwinder unwinder(forked_pid);
598 for (pid_t tid : tids) {
599 DumpThread(unwinder, forked_pid, tid, addr2line_path.get(), " ");
600 }
601 }
602
603 [[noreturn]]
WaitMainLoop(pid_t forked_pid,std::atomic<bool> * saw_wif_stopped_for_main)604 void WaitMainLoop(pid_t forked_pid, std::atomic<bool>* saw_wif_stopped_for_main) {
605 for (;;) {
606 // Consider switching to waitid to not get woken up for WIFSTOPPED.
607 int status;
608 pid_t res = TEMP_FAILURE_RETRY(waitpid(forked_pid, &status, 0));
609 if (res == -1) {
610 PLOG(FATAL) << "Failure during waitpid";
611 __builtin_unreachable();
612 }
613
614 if (WIFEXITED(status)) {
615 _exit(WEXITSTATUS(status));
616 __builtin_unreachable();
617 }
618 if (WIFSIGNALED(status)) {
619 _exit(1);
620 __builtin_unreachable();
621 }
622 if (WIFSTOPPED(status)) {
623 *saw_wif_stopped_for_main = true;
624 continue;
625 }
626 if (WIFCONTINUED(status)) {
627 continue;
628 }
629
630 LOG(FATAL) << "Unknown status " << std::hex << status;
631 }
632 }
633
634 [[noreturn]]
SetupAndWait(pid_t forked_pid,int signal,int timeout_exit_code)635 void SetupAndWait(pid_t forked_pid, int signal, int timeout_exit_code) {
636 timeout_signal::SignalSet signals;
637 signals.Add(signal);
638 signals.Block();
639
640 std::atomic<bool> saw_wif_stopped_for_main(false);
641
642 std::thread signal_catcher([&]() {
643 signals.Block();
644 int sig = signals.Wait();
645 CHECK_EQ(sig, signal);
646
647 DumpProcess(forked_pid, saw_wif_stopped_for_main);
648
649 // Don't clean up. Just kill the child and exit.
650 kill(forked_pid, SIGKILL);
651 _exit(timeout_exit_code);
652 });
653
654 WaitMainLoop(forked_pid, &saw_wif_stopped_for_main);
655 }
656
657 } // namespace
658 } // namespace art
659
main(int argc ATTRIBUTE_UNUSED,char ** argv)660 int main(int argc ATTRIBUTE_UNUSED, char** argv) {
661 android::base::InitLogging(argv);
662
663 int signal = SIGRTMIN + 2;
664 int timeout_exit_code = 1;
665
666 size_t index = 1u;
667 CHECK(argv[index] != nullptr);
668
669 bool to_logcat = false;
670 #ifdef __ANDROID__
671 if (strcmp(argv[index], "-l") == 0) {
672 index++;
673 CHECK(argv[index] != nullptr);
674 to_logcat = true;
675 }
676 #endif
677 if (!to_logcat) {
678 android::base::SetLogger(android::base::StderrLogger);
679 }
680
681 if (strcmp(argv[index], "-s") == 0) {
682 index++;
683 CHECK(argv[index] != nullptr);
684 uint32_t signal_uint;
685 CHECK(android::base::ParseUint(argv[index], &signal_uint)) << "Signal not a number.";
686 signal = signal_uint;
687 index++;
688 CHECK(argv[index] != nullptr);
689 }
690
691 if (strcmp(argv[index], "-e") == 0) {
692 index++;
693 CHECK(argv[index] != nullptr);
694 uint32_t timeout_exit_code_uint;
695 CHECK(android::base::ParseUint(argv[index], &timeout_exit_code_uint))
696 << "Exit code not a number.";
697 timeout_exit_code = timeout_exit_code_uint;
698 index++;
699 CHECK(argv[index] != nullptr);
700 }
701
702 pid_t orig_ppid = getpid();
703
704 pid_t pid = fork();
705 if (pid == 0) {
706 if (prctl(PR_SET_PDEATHSIG, SIGTERM) == -1) {
707 _exit(1);
708 }
709
710 if (getppid() != orig_ppid) {
711 _exit(2);
712 }
713
714 execvp(argv[index], &argv[index]);
715
716 _exit(3);
717 __builtin_unreachable();
718 }
719
720 art::SetupAndWait(pid, signal, timeout_exit_code);
721 __builtin_unreachable();
722 }
723