• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2009, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 //     * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 //     * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 //     * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30 // linux_ptrace_dumper_unittest.cc:
31 // Unit tests for google_breakpad::LinuxPtraceDumper.
32 //
33 // This file was renamed from linux_dumper_unittest.cc and modified due
34 // to LinuxDumper being splitted into two classes.
35 
36 #include <errno.h>
37 #include <fcntl.h>
38 #include <limits.h>
39 #include <poll.h>
40 #include <unistd.h>
41 #include <signal.h>
42 #include <stdint.h>
43 #include <string.h>
44 #include <sys/mman.h>
45 #include <sys/prctl.h>
46 #include <sys/stat.h>
47 #include <sys/types.h>
48 
49 #include <string>
50 
51 #include "breakpad_googletest_includes.h"
52 #include "client/linux/minidump_writer/linux_ptrace_dumper.h"
53 #include "client/linux/minidump_writer/minidump_writer_unittest_utils.h"
54 #include "common/linux/eintr_wrapper.h"
55 #include "common/linux/file_id.h"
56 #include "common/linux/ignore_ret.h"
57 #include "common/linux/safe_readlink.h"
58 #include "common/memory_allocator.h"
59 #include "common/using_std_string.h"
60 
61 #ifndef PR_SET_PTRACER
62 #define PR_SET_PTRACER 0x59616d61
63 #endif
64 
65 using namespace google_breakpad;
66 
67 namespace {
68 
SetupChildProcess(int number_of_threads)69 pid_t SetupChildProcess(int number_of_threads) {
70   char kNumberOfThreadsArgument[2];
71   sprintf(kNumberOfThreadsArgument, "%d", number_of_threads);
72 
73   int fds[2];
74   EXPECT_NE(-1, pipe(fds));
75 
76   pid_t child_pid = fork();
77   if (child_pid == 0) {
78     // In child process.
79     close(fds[0]);
80 
81     string helper_path(GetHelperBinary());
82     if (helper_path.empty()) {
83       fprintf(stderr, "Couldn't find helper binary\n");
84       _exit(1);
85     }
86 
87     // Pass the pipe fd and the number of threads as arguments.
88     char pipe_fd_string[8];
89     sprintf(pipe_fd_string, "%d", fds[1]);
90     execl(helper_path.c_str(),
91           "linux_dumper_unittest_helper",
92           pipe_fd_string,
93           kNumberOfThreadsArgument,
94           NULL);
95     // Kill if we get here.
96     printf("Errno from exec: %d", errno);
97     std::string err_str = "Exec of  " + helper_path + " failed";
98     perror(err_str.c_str());
99     _exit(1);
100   }
101   close(fds[1]);
102 
103   // Wait for all child threads to indicate that they have started
104   for (int threads = 0; threads < number_of_threads; threads++) {
105     struct pollfd pfd;
106     memset(&pfd, 0, sizeof(pfd));
107     pfd.fd = fds[0];
108     pfd.events = POLLIN | POLLERR;
109 
110     const int r = HANDLE_EINTR(poll(&pfd, 1, 1000));
111     EXPECT_EQ(1, r);
112     EXPECT_TRUE(pfd.revents & POLLIN);
113     uint8_t junk;
114     EXPECT_EQ(read(fds[0], &junk, sizeof(junk)),
115               static_cast<ssize_t>(sizeof(junk)));
116   }
117   close(fds[0]);
118 
119   // There is a race here because we may stop a child thread before
120   // it is actually running the busy loop. Empirically this sleep
121   // is sufficient to avoid the race.
122   usleep(100000);
123   return child_pid;
124 }
125 
126 typedef wasteful_vector<uint8_t> id_vector;
127 typedef testing::Test LinuxPtraceDumperTest;
128 
129 /* Fixture for running tests in a child process. */
130 class LinuxPtraceDumperChildTest : public testing::Test {
131  protected:
SetUp()132   virtual void SetUp() {
133     child_pid_ = fork();
134 #ifndef __ANDROID__
135     prctl(PR_SET_PTRACER, child_pid_);
136 #endif
137   }
138 
139   /* Gtest is calling TestBody from this class, which sets up a child
140    * process in which the RealTestBody virtual member is called.
141    * As such, TestBody is not supposed to be overridden in derived classes.
142    */
TestBody()143   virtual void TestBody() /* final */ {
144     if (child_pid_ == 0) {
145       // child process
146       RealTestBody();
147       _exit(HasFatalFailure() ? kFatalFailure :
148             (HasNonfatalFailure() ? kNonFatalFailure : 0));
149     }
150 
151     ASSERT_TRUE(child_pid_ > 0);
152     int status;
153     waitpid(child_pid_, &status, 0);
154     if (WEXITSTATUS(status) == kFatalFailure) {
155       GTEST_FATAL_FAILURE_("Test failed in child process");
156     } else if (WEXITSTATUS(status) == kNonFatalFailure) {
157       GTEST_NONFATAL_FAILURE_("Test failed in child process");
158     }
159   }
160 
161   /* Gtest defines TestBody functions through its macros, but classes
162    * derived from this one need to define RealTestBody instead.
163    * This is achieved by defining a TestBody macro further below.
164    */
165   virtual void RealTestBody() = 0;
166 
make_vector()167   id_vector make_vector() {
168     return id_vector(&allocator, kDefaultBuildIdSize);
169   }
170 
171  private:
172   static const int kFatalFailure = 1;
173   static const int kNonFatalFailure = 2;
174 
175   pid_t child_pid_;
176   PageAllocator allocator;
177 };
178 
179 }  // namespace
180 
181 /* Replace TestBody declarations within TEST*() with RealTestBody
182  * declarations */
183 #define TestBody RealTestBody
184 
TEST_F(LinuxPtraceDumperChildTest,Setup)185 TEST_F(LinuxPtraceDumperChildTest, Setup) {
186   LinuxPtraceDumper dumper(getppid());
187 }
188 
TEST_F(LinuxPtraceDumperChildTest,FindMappings)189 TEST_F(LinuxPtraceDumperChildTest, FindMappings) {
190   LinuxPtraceDumper dumper(getppid());
191   ASSERT_TRUE(dumper.Init());
192 
193   ASSERT_TRUE(dumper.FindMapping(reinterpret_cast<void*>(getpid)));
194   ASSERT_TRUE(dumper.FindMapping(reinterpret_cast<void*>(printf)));
195   ASSERT_FALSE(dumper.FindMapping(NULL));
196 }
197 
TEST_F(LinuxPtraceDumperChildTest,ThreadList)198 TEST_F(LinuxPtraceDumperChildTest, ThreadList) {
199   LinuxPtraceDumper dumper(getppid());
200   ASSERT_TRUE(dumper.Init());
201 
202   ASSERT_GE(dumper.threads().size(), (size_t)1);
203   bool found = false;
204   for (size_t i = 0; i < dumper.threads().size(); ++i) {
205     if (dumper.threads()[i] == getppid()) {
206       ASSERT_FALSE(found);
207       found = true;
208     }
209   }
210   ASSERT_TRUE(found);
211 }
212 
213 // Helper stack class to close a file descriptor and unmap
214 // a mmap'ed mapping.
215 class StackHelper {
216  public:
StackHelper()217   StackHelper()
218     : fd_(-1), mapping_(NULL), size_(0) {}
~StackHelper()219   ~StackHelper() {
220     if (size_)
221       munmap(mapping_, size_);
222     if (fd_ >= 0)
223       close(fd_);
224   }
Init(int fd,char * mapping,size_t size)225   void Init(int fd, char* mapping, size_t size) {
226     fd_ = fd;
227     mapping_ = mapping;
228     size_ = size;
229   }
230 
mapping() const231   char* mapping() const { return mapping_; }
size() const232   size_t size() const { return size_; }
233 
234  private:
235   int fd_;
236   char* mapping_;
237   size_t size_;
238 };
239 
240 class LinuxPtraceDumperMappingsTest : public LinuxPtraceDumperChildTest {
241  protected:
242   virtual void SetUp();
243 
244   string helper_path_;
245   size_t page_size_;
246   StackHelper helper_;
247 };
248 
SetUp()249 void LinuxPtraceDumperMappingsTest::SetUp() {
250   helper_path_ = GetHelperBinary();
251   if (helper_path_.empty()) {
252     FAIL() << "Couldn't find helper binary";
253     _exit(1);
254   }
255 
256   // mmap two segments out of the helper binary, one
257   // enclosed in the other, but with different protections.
258   page_size_ = sysconf(_SC_PAGESIZE);
259   const size_t kMappingSize = 3 * page_size_;
260   int fd = open(helper_path_.c_str(), O_RDONLY);
261   ASSERT_NE(-1, fd) << "Failed to open file: " << helper_path_
262                     << ", Error: " << strerror(errno);
263   char* mapping =
264     reinterpret_cast<char*>(mmap(NULL,
265                                  kMappingSize,
266                                  PROT_READ,
267                                  MAP_SHARED,
268                                  fd,
269                                  0));
270   ASSERT_TRUE(mapping);
271 
272   // Ensure that things get cleaned up.
273   helper_.Init(fd, mapping, kMappingSize);
274 
275   // Carve a page out of the first mapping with different permissions.
276   char* inside_mapping =  reinterpret_cast<char*>(
277       mmap(mapping + 2 * page_size_,
278            page_size_,
279            PROT_NONE,
280            MAP_SHARED | MAP_FIXED,
281            fd,
282            // Map a different offset just to
283            // better test real-world conditions.
284            page_size_));
285   ASSERT_TRUE(inside_mapping);
286 
287   LinuxPtraceDumperChildTest::SetUp();
288 }
289 
TEST_F(LinuxPtraceDumperMappingsTest,MergedMappings)290 TEST_F(LinuxPtraceDumperMappingsTest, MergedMappings) {
291   // Now check that LinuxPtraceDumper interpreted the mappings properly.
292   LinuxPtraceDumper dumper(getppid());
293   ASSERT_TRUE(dumper.Init());
294   int mapping_count = 0;
295   for (unsigned i = 0; i < dumper.mappings().size(); ++i) {
296     const MappingInfo& mapping = *dumper.mappings()[i];
297     if (strcmp(mapping.name, this->helper_path_.c_str()) == 0) {
298       // This mapping should encompass the entire original mapped
299       // range.
300       EXPECT_EQ(reinterpret_cast<uintptr_t>(this->helper_.mapping()),
301                 mapping.start_addr);
302       EXPECT_EQ(this->helper_.size(), mapping.size);
303       EXPECT_EQ(0U, mapping.offset);
304       mapping_count++;
305     }
306   }
307   EXPECT_EQ(1, mapping_count);
308 }
309 
TEST_F(LinuxPtraceDumperChildTest,BuildProcPath)310 TEST_F(LinuxPtraceDumperChildTest, BuildProcPath) {
311   const pid_t pid = getppid();
312   LinuxPtraceDumper dumper(pid);
313 
314   char maps_path[NAME_MAX] = "";
315   char maps_path_expected[NAME_MAX];
316   snprintf(maps_path_expected, sizeof(maps_path_expected),
317            "/proc/%d/maps", pid);
318   EXPECT_TRUE(dumper.BuildProcPath(maps_path, pid, "maps"));
319   EXPECT_STREQ(maps_path_expected, maps_path);
320 
321   EXPECT_FALSE(dumper.BuildProcPath(NULL, pid, "maps"));
322   EXPECT_FALSE(dumper.BuildProcPath(maps_path, 0, "maps"));
323   EXPECT_FALSE(dumper.BuildProcPath(maps_path, pid, ""));
324   EXPECT_FALSE(dumper.BuildProcPath(maps_path, pid, NULL));
325 
326   char long_node[NAME_MAX];
327   size_t long_node_len = NAME_MAX - strlen("/proc/123") - 1;
328   memset(long_node, 'a', long_node_len);
329   long_node[long_node_len] = '\0';
330   EXPECT_FALSE(dumper.BuildProcPath(maps_path, 123, long_node));
331 }
332 
333 #if !defined(__ARM_EABI__) && !defined(__mips__)
334 // Ensure that the linux-gate VDSO is included in the mapping list.
TEST_F(LinuxPtraceDumperChildTest,MappingsIncludeLinuxGate)335 TEST_F(LinuxPtraceDumperChildTest, MappingsIncludeLinuxGate) {
336   LinuxPtraceDumper dumper(getppid());
337   ASSERT_TRUE(dumper.Init());
338 
339   void* linux_gate_loc =
340     reinterpret_cast<void *>(dumper.auxv()[AT_SYSINFO_EHDR]);
341   ASSERT_TRUE(linux_gate_loc);
342   bool found_linux_gate = false;
343 
344   const wasteful_vector<MappingInfo*> mappings = dumper.mappings();
345   const MappingInfo* mapping;
346   for (unsigned i = 0; i < mappings.size(); ++i) {
347     mapping = mappings[i];
348     if (!strcmp(mapping->name, kLinuxGateLibraryName)) {
349       found_linux_gate = true;
350       break;
351     }
352   }
353   EXPECT_TRUE(found_linux_gate);
354   EXPECT_EQ(linux_gate_loc, reinterpret_cast<void*>(mapping->start_addr));
355   EXPECT_EQ(0, memcmp(linux_gate_loc, ELFMAG, SELFMAG));
356 }
357 
358 // Ensure that the linux-gate VDSO can generate a non-zeroed File ID.
TEST_F(LinuxPtraceDumperChildTest,LinuxGateMappingID)359 TEST_F(LinuxPtraceDumperChildTest, LinuxGateMappingID) {
360   LinuxPtraceDumper dumper(getppid());
361   ASSERT_TRUE(dumper.Init());
362 
363   bool found_linux_gate = false;
364   const wasteful_vector<MappingInfo*> mappings = dumper.mappings();
365   unsigned index = 0;
366   for (unsigned i = 0; i < mappings.size(); ++i) {
367     if (!strcmp(mappings[i]->name, kLinuxGateLibraryName)) {
368       found_linux_gate = true;
369       index = i;
370       break;
371     }
372   }
373   ASSERT_TRUE(found_linux_gate);
374 
375   // Need to suspend the child so ptrace actually works.
376   ASSERT_TRUE(dumper.ThreadsSuspend());
377   id_vector identifier(make_vector());
378   ASSERT_TRUE(dumper.ElfFileIdentifierForMapping(*mappings[index],
379                                                  true,
380                                                  index,
381                                                  identifier));
382 
383   id_vector empty_identifier(make_vector());
384   empty_identifier.resize(kDefaultBuildIdSize, 0);
385   EXPECT_NE(empty_identifier, identifier);
386   EXPECT_TRUE(dumper.ThreadsResume());
387 }
388 #endif
389 
TEST_F(LinuxPtraceDumperChildTest,FileIDsMatch)390 TEST_F(LinuxPtraceDumperChildTest, FileIDsMatch) {
391   // Calculate the File ID of our binary using both
392   // FileID::ElfFileIdentifier and LinuxDumper::ElfFileIdentifierForMapping
393   // and ensure that we get the same result from both.
394   char exe_name[PATH_MAX];
395   ASSERT_TRUE(SafeReadLink("/proc/self/exe", exe_name));
396 
397   LinuxPtraceDumper dumper(getppid());
398   ASSERT_TRUE(dumper.Init());
399   const wasteful_vector<MappingInfo*> mappings = dumper.mappings();
400   bool found_exe = false;
401   unsigned i;
402   for (i = 0; i < mappings.size(); ++i) {
403     const MappingInfo* mapping = mappings[i];
404     if (!strcmp(mapping->name, exe_name)) {
405       found_exe = true;
406       break;
407     }
408   }
409   ASSERT_TRUE(found_exe);
410 
411   id_vector identifier1(make_vector());
412   id_vector identifier2(make_vector());
413   EXPECT_TRUE(dumper.ElfFileIdentifierForMapping(*mappings[i], true, i,
414                                                  identifier1));
415   FileID fileid(exe_name);
416   EXPECT_TRUE(fileid.ElfFileIdentifier(identifier2));
417 
418   string identifier_string1 =
419       FileID::ConvertIdentifierToUUIDString(identifier1);
420   string identifier_string2 =
421       FileID::ConvertIdentifierToUUIDString(identifier2);
422   EXPECT_EQ(identifier_string1, identifier_string2);
423 }
424 
425 /* Get back to normal behavior of TEST*() macros wrt TestBody. */
426 #undef TestBody
427 
TEST(LinuxPtraceDumperTest,VerifyStackReadWithMultipleThreads)428 TEST(LinuxPtraceDumperTest, VerifyStackReadWithMultipleThreads) {
429   static const size_t kNumberOfThreadsInHelperProgram = 5;
430 
431   pid_t child_pid = SetupChildProcess(kNumberOfThreadsInHelperProgram);
432   ASSERT_NE(child_pid, -1);
433 
434   // Children are ready now.
435   LinuxPtraceDumper dumper(child_pid);
436   ASSERT_TRUE(dumper.Init());
437 #if defined(THREAD_SANITIZER)
438   EXPECT_GE(dumper.threads().size(), (size_t)kNumberOfThreadsInHelperProgram);
439 #else
440   EXPECT_EQ(dumper.threads().size(), (size_t)kNumberOfThreadsInHelperProgram);
441 #endif
442   EXPECT_TRUE(dumper.ThreadsSuspend());
443 
444   ThreadInfo one_thread;
445   size_t matching_threads = 0;
446   for (size_t i = 0; i < dumper.threads().size(); ++i) {
447     EXPECT_TRUE(dumper.GetThreadInfoByIndex(i, &one_thread));
448     const void* stack;
449     size_t stack_len;
450     EXPECT_TRUE(dumper.GetStackInfo(&stack, &stack_len,
451         one_thread.stack_pointer));
452     // In the helper program, we stored a pointer to the thread id in a
453     // specific register. Check that we can recover its value.
454 #if defined(__ARM_EABI__)
455     pid_t* process_tid_location = (pid_t*)(one_thread.regs.uregs[3]);
456 #elif defined(__aarch64__)
457     pid_t* process_tid_location = (pid_t*)(one_thread.regs.regs[3]);
458 #elif defined(__i386)
459     pid_t* process_tid_location = (pid_t*)(one_thread.regs.ecx);
460 #elif defined(__x86_64)
461     pid_t* process_tid_location = (pid_t*)(one_thread.regs.rcx);
462 #elif defined(__mips__)
463     pid_t* process_tid_location =
464         reinterpret_cast<pid_t*>(one_thread.mcontext.gregs[1]);
465 #else
466 #error This test has not been ported to this platform.
467 #endif
468     pid_t one_thread_id;
469     dumper.CopyFromProcess(&one_thread_id,
470                            dumper.threads()[i],
471                            process_tid_location,
472                            4);
473     matching_threads += (dumper.threads()[i] == one_thread_id) ? 1 : 0;
474   }
475   EXPECT_EQ(matching_threads, kNumberOfThreadsInHelperProgram);
476   EXPECT_TRUE(dumper.ThreadsResume());
477   kill(child_pid, SIGKILL);
478 
479   // Reap child
480   int status;
481   ASSERT_NE(-1, HANDLE_EINTR(waitpid(child_pid, &status, 0)));
482   ASSERT_TRUE(WIFSIGNALED(status));
483   ASSERT_EQ(SIGKILL, WTERMSIG(status));
484 }
485 
TEST_F(LinuxPtraceDumperTest,SanitizeStackCopy)486 TEST_F(LinuxPtraceDumperTest, SanitizeStackCopy) {
487   static const size_t kNumberOfThreadsInHelperProgram = 1;
488 
489   pid_t child_pid = SetupChildProcess(kNumberOfThreadsInHelperProgram);
490   ASSERT_NE(child_pid, -1);
491 
492   LinuxPtraceDumper dumper(child_pid);
493   ASSERT_TRUE(dumper.Init());
494   EXPECT_TRUE(dumper.ThreadsSuspend());
495 
496   ThreadInfo thread_info;
497   EXPECT_TRUE(dumper.GetThreadInfoByIndex(0, &thread_info));
498 
499   const uintptr_t defaced =
500 #if defined(__LP64__)
501       0x0defaced0defaced;
502 #else
503       0x0defaced;
504 #endif
505 
506   uintptr_t simulated_stack[2];
507 
508   // Pointers into the stack shouldn't be sanitized.
509   memset(simulated_stack, 0xff, sizeof(simulated_stack));
510   simulated_stack[1] = thread_info.stack_pointer;
511   dumper.SanitizeStackCopy(reinterpret_cast<uint8_t*>(&simulated_stack),
512                            sizeof(simulated_stack), thread_info.stack_pointer,
513                            sizeof(uintptr_t));
514   ASSERT_NE(simulated_stack[1], defaced);
515 
516   // Memory prior to the stack pointer should be cleared.
517   ASSERT_EQ(simulated_stack[0], 0u);
518 
519   // Small integers should not be sanitized.
520   for (int i = -4096; i <= 4096; ++i) {
521     memset(simulated_stack, 0, sizeof(simulated_stack));
522     simulated_stack[0] = static_cast<uintptr_t>(i);
523     dumper.SanitizeStackCopy(reinterpret_cast<uint8_t*>(&simulated_stack),
524                              sizeof(simulated_stack), thread_info.stack_pointer,
525                              0u);
526     ASSERT_NE(simulated_stack[0], defaced);
527   }
528 
529   // The instruction pointer definitely should point into an executable mapping.
530   const MappingInfo* mapping_info = dumper.FindMappingNoBias(
531       reinterpret_cast<uintptr_t>(thread_info.GetInstructionPointer()));
532   ASSERT_NE(mapping_info, nullptr);
533   ASSERT_TRUE(mapping_info->exec);
534 
535   // Pointers to code shouldn't be sanitized.
536   memset(simulated_stack, 0, sizeof(simulated_stack));
537   simulated_stack[1] = thread_info.GetInstructionPointer();
538   dumper.SanitizeStackCopy(reinterpret_cast<uint8_t*>(&simulated_stack),
539                            sizeof(simulated_stack), thread_info.stack_pointer,
540                            0u);
541   ASSERT_NE(simulated_stack[0], defaced);
542 
543   // String fragments should be sanitized.
544   memcpy(simulated_stack, "abcdefghijklmnop", sizeof(simulated_stack));
545   dumper.SanitizeStackCopy(reinterpret_cast<uint8_t*>(&simulated_stack),
546                            sizeof(simulated_stack), thread_info.stack_pointer,
547                            0u);
548   ASSERT_EQ(simulated_stack[0], defaced);
549   ASSERT_EQ(simulated_stack[1], defaced);
550 
551   // Heap pointers should be sanititzed.
552 #if defined(__ARM_EABI__)
553   uintptr_t heap_addr = thread_info.regs.uregs[3];
554 #elif defined(__aarch64__)
555   uintptr_t heap_addr = thread_info.regs.regs[3];
556 #elif defined(__i386)
557   uintptr_t heap_addr = thread_info.regs.ecx;
558 #elif defined(__x86_64)
559   uintptr_t heap_addr = thread_info.regs.rcx;
560 #elif defined(__mips__)
561   uintptr_t heap_addr = thread_info.mcontext.gregs[1];
562 #else
563 #error This test has not been ported to this platform.
564 #endif
565   memset(simulated_stack, 0, sizeof(simulated_stack));
566   simulated_stack[0] = heap_addr;
567   dumper.SanitizeStackCopy(reinterpret_cast<uint8_t*>(&simulated_stack),
568                            sizeof(simulated_stack), thread_info.stack_pointer,
569                            0u);
570   ASSERT_EQ(simulated_stack[0], defaced);
571 
572   EXPECT_TRUE(dumper.ThreadsResume());
573   kill(child_pid, SIGKILL);
574 
575   // Reap child.
576   int status;
577   ASSERT_NE(-1, HANDLE_EINTR(waitpid(child_pid, &status, 0)));
578   ASSERT_TRUE(WIFSIGNALED(status));
579   ASSERT_EQ(SIGKILL, WTERMSIG(status));
580 }
581