• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2011 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include <stddef.h>
6 
7 #include <limits>
8 #include <sstream>
9 #include <string>
10 
11 #include "base/debug/debugging_buildflags.h"
12 #include "base/debug/stack_trace.h"
13 #include "base/immediate_crash.h"
14 #include "base/logging.h"
15 #include "base/process/kill.h"
16 #include "base/process/process_handle.h"
17 #include "base/profiler/stack_buffer.h"
18 #include "base/profiler/stack_copier.h"
19 #include "base/test/test_timeouts.h"
20 #include "build/build_config.h"
21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "testing/multiprocess_func_list.h"
23 
24 #include "base/allocator/buildflags.h"
25 #include "base/allocator/partition_allocator/src/partition_alloc/partition_alloc.h"
26 #if BUILDFLAG(USE_ALLOCATOR_SHIM)
27 #include "base/allocator/partition_allocator/src/partition_alloc/shim/allocator_shim.h"
28 #endif
29 
30 #if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
31 #include "base/test/multiprocess_test.h"
32 #endif
33 
34 namespace base {
35 namespace debug {
36 
37 #if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
38 typedef MultiProcessTest StackTraceTest;
39 #else
40 typedef testing::Test StackTraceTest;
41 #endif
42 typedef testing::Test StackTraceDeathTest;
43 
44 #if !defined(__UCLIBC__) && !defined(_AIX)
45 // StackTrace::OutputToStream() is not implemented under uclibc, nor AIX.
46 // See https://crbug.com/706728
47 
TEST_F(StackTraceTest,OutputToStream)48 TEST_F(StackTraceTest, OutputToStream) {
49   StackTrace trace;
50 
51   // Dump the trace into a string.
52   std::ostringstream os;
53   trace.OutputToStream(&os);
54   std::string backtrace_message = os.str();
55 
56   // ToString() should produce the same output.
57   EXPECT_EQ(backtrace_message, trace.ToString());
58 
59   span<const void* const> addresses = trace.addresses();
60 
61 #if defined(OFFICIAL_BUILD) && \
62     ((BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_APPLE)) || BUILDFLAG(IS_FUCHSIA))
63   // Stack traces require an extra data table that bloats our binaries,
64   // so they're turned off for official builds. Stop the test here, so
65   // it at least verifies that StackTrace calls don't crash.
66   return;
67 #endif  // defined(OFFICIAL_BUILD) &&
68         // ((BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_APPLE)) ||
69         // BUILDFLAG(IS_FUCHSIA))
70 
71   ASSERT_GT(addresses.size(), 5u) << "Too few frames found.";
72   ASSERT_TRUE(addresses[0]);
73 
74   if (!StackTrace::WillSymbolizeToStreamForTesting())
75     return;
76 
77   // Check if the output has symbol initialization warning.  If it does, fail.
78   ASSERT_EQ(backtrace_message.find("Dumping unresolved backtrace"),
79             std::string::npos)
80       << "Unable to resolve symbols.";
81 
82   // Expect a demangled symbol.
83   // Note that Windows Release builds omit the function parameters from the
84   // demangled stack output, otherwise this could be "testing::UnitTest::Run()".
85   EXPECT_TRUE(backtrace_message.find("testing::UnitTest::Run") !=
86               std::string::npos)
87       << "Expected a demangled symbol in backtrace:\n"
88       << backtrace_message;
89 
90   // Expect to at least find main.
91   EXPECT_TRUE(backtrace_message.find("main") != std::string::npos)
92       << "Expected to find main in backtrace:\n"
93       << backtrace_message;
94 
95   // Expect to find this function as well.
96   // Note: This will fail if not linked with -rdynamic (aka -export_dynamic)
97   EXPECT_TRUE(backtrace_message.find(__func__) != std::string::npos)
98       << "Expected to find " << __func__ << " in backtrace:\n"
99       << backtrace_message;
100 }
101 
102 #if !defined(OFFICIAL_BUILD) && !defined(NO_UNWIND_TABLES)
103 // Disabled in Official builds, where Link-Time Optimization can result in two
104 // or fewer stack frames being available, causing the test to fail.
TEST_F(StackTraceTest,TruncatedTrace)105 TEST_F(StackTraceTest, TruncatedTrace) {
106   StackTrace trace;
107 
108   ASSERT_LT(2u, trace.addresses().size());
109 
110   StackTrace truncated(2);
111   EXPECT_EQ(2u, truncated.addresses().size());
112 }
113 #endif  // !defined(OFFICIAL_BUILD) && !defined(NO_UNWIND_TABLES)
114 
115 // The test is used for manual testing, e.g., to see the raw output.
TEST_F(StackTraceTest,DebugOutputToStream)116 TEST_F(StackTraceTest, DebugOutputToStream) {
117   StackTrace trace;
118   std::ostringstream os;
119   trace.OutputToStream(&os);
120   VLOG(1) << os.str();
121 }
122 
123 // The test is used for manual testing, e.g., to see the raw output.
TEST_F(StackTraceTest,DebugPrintBacktrace)124 TEST_F(StackTraceTest, DebugPrintBacktrace) {
125   StackTrace().Print();
126 }
127 
128 // The test is used for manual testing, e.g., to see the raw output.
TEST_F(StackTraceTest,DebugPrintWithPrefixBacktrace)129 TEST_F(StackTraceTest, DebugPrintWithPrefixBacktrace) {
130   StackTrace().PrintWithPrefix("[test]");
131 }
132 
133 // Make sure nullptr prefix doesn't crash. Output not examined, much
134 // like the DebugPrintBacktrace test above.
TEST_F(StackTraceTest,DebugPrintWithNullPrefixBacktrace)135 TEST_F(StackTraceTest, DebugPrintWithNullPrefixBacktrace) {
136   StackTrace().PrintWithPrefix(nullptr);
137 }
138 
139 // Test OutputToStreamWithPrefix, mainly to make sure it doesn't
140 // crash. Any "real" stack trace testing happens above.
TEST_F(StackTraceTest,DebugOutputToStreamWithPrefix)141 TEST_F(StackTraceTest, DebugOutputToStreamWithPrefix) {
142   StackTrace trace;
143   const char* prefix_string = "[test]";
144   std::ostringstream os;
145   trace.OutputToStreamWithPrefix(&os, prefix_string);
146   std::string backtrace_message = os.str();
147 
148   // ToStringWithPrefix() should produce the same output.
149   EXPECT_EQ(backtrace_message, trace.ToStringWithPrefix(prefix_string));
150 }
151 
152 // Make sure nullptr prefix doesn't crash. Output not examined, much
153 // like the DebugPrintBacktrace test above.
TEST_F(StackTraceTest,DebugOutputToStreamWithNullPrefix)154 TEST_F(StackTraceTest, DebugOutputToStreamWithNullPrefix) {
155   StackTrace trace;
156   std::ostringstream os;
157   trace.OutputToStreamWithPrefix(&os, nullptr);
158   trace.ToStringWithPrefix(nullptr);
159 }
160 
161 #endif  // !defined(__UCLIBC__) && !defined(_AIX)
162 
163 #if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID)
164 // Since Mac's base::debug::StackTrace().Print() is not malloc-free, skip
165 // StackDumpSignalHandlerIsMallocFree if BUILDFLAG(IS_MAC).
166 #if BUILDFLAG(USE_ALLOCATOR_SHIM) && !BUILDFLAG(IS_MAC)
167 
168 namespace {
169 
170 // ImmediateCrash if a signal handler incorrectly uses malloc().
171 // In an actual implementation, this could cause infinite recursion into the
172 // signal handler or other problems. Because malloc() is not guaranteed to be
173 // async signal safe.
BadMalloc(const allocator_shim::AllocatorDispatch *,size_t,void *)174 void* BadMalloc(const allocator_shim::AllocatorDispatch*, size_t, void*) {
175   base::ImmediateCrash();
176 }
177 
BadCalloc(const allocator_shim::AllocatorDispatch *,size_t,size_t,void * context)178 void* BadCalloc(const allocator_shim::AllocatorDispatch*,
179                 size_t,
180                 size_t,
181                 void* context) {
182   base::ImmediateCrash();
183 }
184 
BadAlignedAlloc(const allocator_shim::AllocatorDispatch *,size_t,size_t,void *)185 void* BadAlignedAlloc(const allocator_shim::AllocatorDispatch*,
186                       size_t,
187                       size_t,
188                       void*) {
189   base::ImmediateCrash();
190 }
191 
BadAlignedRealloc(const allocator_shim::AllocatorDispatch *,void *,size_t,size_t,void *)192 void* BadAlignedRealloc(const allocator_shim::AllocatorDispatch*,
193                         void*,
194                         size_t,
195                         size_t,
196                         void*) {
197   base::ImmediateCrash();
198 }
199 
BadRealloc(const allocator_shim::AllocatorDispatch *,void *,size_t,void *)200 void* BadRealloc(const allocator_shim::AllocatorDispatch*,
201                  void*,
202                  size_t,
203                  void*) {
204   base::ImmediateCrash();
205 }
206 
BadFree(const allocator_shim::AllocatorDispatch *,void *,void *)207 void BadFree(const allocator_shim::AllocatorDispatch*, void*, void*) {
208   base::ImmediateCrash();
209 }
210 
211 allocator_shim::AllocatorDispatch g_bad_malloc_dispatch = {
212     &BadMalloc,         /* alloc_function */
213     &BadMalloc,         /* alloc_unchecked_function */
214     &BadCalloc,         /* alloc_zero_initialized_function */
215     &BadAlignedAlloc,   /* alloc_aligned_function */
216     &BadRealloc,        /* realloc_function */
217     &BadFree,           /* free_function */
218     nullptr,            /* get_size_estimate_function */
219     nullptr,            /* good_size_function */
220     nullptr,            /* claimed_address_function */
221     nullptr,            /* batch_malloc_function */
222     nullptr,            /* batch_free_function */
223     nullptr,            /* free_definite_size_function */
224     nullptr,            /* try_free_default_function */
225     &BadAlignedAlloc,   /* aligned_malloc_function */
226     &BadAlignedRealloc, /* aligned_realloc_function */
227     &BadFree,           /* aligned_free_function */
228     nullptr,            /* next */
229 };
230 
231 }  // namespace
232 
233 // Regression test for StackDumpSignalHandler async-signal unsafety.
234 // Since malloc() is not guaranteed to be async signal safe, it is not allowed
235 // to use malloc() inside StackDumpSignalHandler().
TEST_F(StackTraceDeathTest,StackDumpSignalHandlerIsMallocFree)236 TEST_F(StackTraceDeathTest, StackDumpSignalHandlerIsMallocFree) {
237   EXPECT_DEATH_IF_SUPPORTED(
238       [] {
239         // On Android, base::debug::EnableInProcessStackDumping() does not
240         // change any actions taken by signals to be StackDumpSignalHandler. So
241         // the StackDumpSignalHandlerIsMallocFree test doesn't work on Android.
242         EnableInProcessStackDumping();
243         allocator_shim::InsertAllocatorDispatch(&g_bad_malloc_dispatch);
244         // Raise SIGSEGV to invoke StackDumpSignalHandler().
245         kill(getpid(), SIGSEGV);
246       }(),
247       "\\[end of stack trace\\]\n");
248 }
249 #endif  // BUILDFLAG(USE_ALLOCATOR_SHIM)
250 
251 namespace {
252 
itoa_r_wrapper(intptr_t i,size_t sz,int base,size_t padding)253 std::string itoa_r_wrapper(intptr_t i, size_t sz, int base, size_t padding) {
254   char buffer[1024];
255   CHECK_LE(sz, sizeof(buffer));
256 
257   char* result = internal::itoa_r(i, buffer, sz, base, padding);
258   EXPECT_TRUE(result);
259   return std::string(buffer);
260 }
261 
262 }  // namespace
263 
TEST_F(StackTraceTest,itoa_r)264 TEST_F(StackTraceTest, itoa_r) {
265   EXPECT_EQ("0", itoa_r_wrapper(0, 128, 10, 0));
266   EXPECT_EQ("-1", itoa_r_wrapper(-1, 128, 10, 0));
267 
268   // Test edge cases.
269   if (sizeof(intptr_t) == 4) {
270     EXPECT_EQ("ffffffff", itoa_r_wrapper(-1, 128, 16, 0));
271     EXPECT_EQ("-2147483648",
272               itoa_r_wrapper(std::numeric_limits<intptr_t>::min(), 128, 10, 0));
273     EXPECT_EQ("2147483647",
274               itoa_r_wrapper(std::numeric_limits<intptr_t>::max(), 128, 10, 0));
275 
276     EXPECT_EQ("80000000",
277               itoa_r_wrapper(std::numeric_limits<intptr_t>::min(), 128, 16, 0));
278     EXPECT_EQ("7fffffff",
279               itoa_r_wrapper(std::numeric_limits<intptr_t>::max(), 128, 16, 0));
280   } else if (sizeof(intptr_t) == 8) {
281     EXPECT_EQ("ffffffffffffffff", itoa_r_wrapper(-1, 128, 16, 0));
282     EXPECT_EQ("-9223372036854775808",
283               itoa_r_wrapper(std::numeric_limits<intptr_t>::min(), 128, 10, 0));
284     EXPECT_EQ("9223372036854775807",
285               itoa_r_wrapper(std::numeric_limits<intptr_t>::max(), 128, 10, 0));
286 
287     EXPECT_EQ("8000000000000000",
288               itoa_r_wrapper(std::numeric_limits<intptr_t>::min(), 128, 16, 0));
289     EXPECT_EQ("7fffffffffffffff",
290               itoa_r_wrapper(std::numeric_limits<intptr_t>::max(), 128, 16, 0));
291   } else {
292     ADD_FAILURE() << "Missing test case for your size of intptr_t ("
293                   << sizeof(intptr_t) << ")";
294   }
295 
296   // Test hex output.
297   EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 0));
298   EXPECT_EQ("deadbeef", itoa_r_wrapper(0xdeadbeef, 128, 16, 0));
299 
300   // Check that itoa_r respects passed buffer size limit.
301   char buffer[1024];
302   EXPECT_TRUE(internal::itoa_r(0xdeadbeef, buffer, 10, 16, 0));
303   EXPECT_TRUE(internal::itoa_r(0xdeadbeef, buffer, 9, 16, 0));
304   EXPECT_FALSE(internal::itoa_r(0xdeadbeef, buffer, 8, 16, 0));
305   EXPECT_FALSE(internal::itoa_r(0xdeadbeef, buffer, 7, 16, 0));
306   EXPECT_TRUE(internal::itoa_r(0xbeef, buffer, 5, 16, 4));
307   EXPECT_FALSE(internal::itoa_r(0xbeef, buffer, 5, 16, 5));
308   EXPECT_FALSE(internal::itoa_r(0xbeef, buffer, 5, 16, 6));
309 
310   // Test padding.
311   EXPECT_EQ("1", itoa_r_wrapper(1, 128, 10, 0));
312   EXPECT_EQ("1", itoa_r_wrapper(1, 128, 10, 1));
313   EXPECT_EQ("01", itoa_r_wrapper(1, 128, 10, 2));
314   EXPECT_EQ("001", itoa_r_wrapper(1, 128, 10, 3));
315   EXPECT_EQ("0001", itoa_r_wrapper(1, 128, 10, 4));
316   EXPECT_EQ("00001", itoa_r_wrapper(1, 128, 10, 5));
317   EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 0));
318   EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 1));
319   EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 2));
320   EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 3));
321   EXPECT_EQ("0688", itoa_r_wrapper(0x688, 128, 16, 4));
322   EXPECT_EQ("00688", itoa_r_wrapper(0x688, 128, 16, 5));
323 }
324 #endif  // BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID)
325 
326 #if BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
327 
328 class CopyFunction : public StackCopier {
329  public:
330   using StackCopier::CopyStackContentsAndRewritePointers;
331 };
332 
333 // Copies the current stack segment, starting from the frame pointer of the
334 // caller frame. Also fills in |stack_end| for the copied stack.
CopyCurrentStackAndRewritePointers(uintptr_t * out_fp,uintptr_t * stack_end)335 NOINLINE static std::unique_ptr<StackBuffer> CopyCurrentStackAndRewritePointers(
336     uintptr_t* out_fp,
337     uintptr_t* stack_end) {
338   const uint8_t* fp =
339       reinterpret_cast<const uint8_t*>(__builtin_frame_address(0));
340   uintptr_t original_stack_end = GetStackEnd();
341   size_t stack_size = original_stack_end - reinterpret_cast<uintptr_t>(fp);
342   auto buffer = std::make_unique<StackBuffer>(stack_size);
343   *out_fp = reinterpret_cast<uintptr_t>(
344       CopyFunction::CopyStackContentsAndRewritePointers(
345           fp, reinterpret_cast<const uintptr_t*>(original_stack_end),
346           StackBuffer::kPlatformStackAlignment, buffer->buffer()));
347   *stack_end = *out_fp + stack_size;
348   return buffer;
349 }
350 
351 template <size_t Depth>
ExpectStackFramePointers(const void ** frames,size_t max_depth,bool copy_stack)352 NOINLINE NOOPT void ExpectStackFramePointers(const void** frames,
353                                              size_t max_depth,
354                                              bool copy_stack) {
355 code_start:
356   // Calling __builtin_frame_address() forces compiler to emit
357   // frame pointers, even if they are not enabled.
358   EXPECT_NE(nullptr, __builtin_frame_address(0));
359   ExpectStackFramePointers<Depth - 1>(frames, max_depth, copy_stack);
360 
361   constexpr size_t frame_index = Depth - 1;
362   const void* frame = frames[frame_index];
363   EXPECT_GE(frame, &&code_start) << "For frame at index " << frame_index;
364   EXPECT_LE(frame, &&code_end) << "For frame at index " << frame_index;
365 code_end:
366   return;
367 }
368 
369 template <>
ExpectStackFramePointers(const void ** frames,size_t max_depth,bool copy_stack)370 NOINLINE NOOPT void ExpectStackFramePointers<1>(const void** frames,
371                                                 size_t max_depth,
372                                                 bool copy_stack) {
373 code_start:
374   // Calling __builtin_frame_address() forces compiler to emit
375   // frame pointers, even if they are not enabled.
376   EXPECT_NE(nullptr, __builtin_frame_address(0));
377   size_t count = 0;
378   if (copy_stack) {
379     uintptr_t stack_end = 0, fp = 0;
380     std::unique_ptr<StackBuffer> copy =
381         CopyCurrentStackAndRewritePointers(&fp, &stack_end);
382     count =
383         TraceStackFramePointersFromBuffer(fp, stack_end, frames, max_depth, 0);
384   } else {
385     count = TraceStackFramePointers(frames, max_depth, 0);
386   }
387   ASSERT_EQ(max_depth, count);
388 
389   const void* frame = frames[0];
390   EXPECT_GE(frame, &&code_start) << "For the top frame";
391   EXPECT_LE(frame, &&code_end) << "For the top frame";
392 code_end:
393   return;
394 }
395 
396 #if defined(MEMORY_SANITIZER)
397 // The test triggers use-of-uninitialized-value errors on MSan bots.
398 // This is expected because we're walking and reading the stack, and
399 // sometimes we read fp / pc from the place that previously held
400 // uninitialized value.
401 #define MAYBE_TraceStackFramePointers DISABLED_TraceStackFramePointers
402 #else
403 #define MAYBE_TraceStackFramePointers TraceStackFramePointers
404 #endif
TEST_F(StackTraceTest,MAYBE_TraceStackFramePointers)405 TEST_F(StackTraceTest, MAYBE_TraceStackFramePointers) {
406   constexpr size_t kDepth = 5;
407   const void* frames[kDepth];
408   ExpectStackFramePointers<kDepth>(frames, kDepth, /*copy_stack=*/false);
409 }
410 
411 // The test triggers use-of-uninitialized-value errors on MSan bots.
412 // This is expected because we're walking and reading the stack, and
413 // sometimes we read fp / pc from the place that previously held
414 // uninitialized value.
415 // TODO(crbug.com/1132511): Enable this test on Fuchsia.
416 #if defined(MEMORY_SANITIZER) || BUILDFLAG(IS_FUCHSIA)
417 #define MAYBE_TraceStackFramePointersFromBuffer \
418   DISABLED_TraceStackFramePointersFromBuffer
419 #else
420 #define MAYBE_TraceStackFramePointersFromBuffer \
421   TraceStackFramePointersFromBuffer
422 #endif
TEST_F(StackTraceTest,MAYBE_TraceStackFramePointersFromBuffer)423 TEST_F(StackTraceTest, MAYBE_TraceStackFramePointersFromBuffer) {
424   constexpr size_t kDepth = 5;
425   const void* frames[kDepth];
426   ExpectStackFramePointers<kDepth>(frames, kDepth, /*copy_stack=*/true);
427 }
428 
429 #if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_APPLE)
430 #define MAYBE_StackEnd StackEnd
431 #else
432 #define MAYBE_StackEnd DISABLED_StackEnd
433 #endif
434 
TEST_F(StackTraceTest,MAYBE_StackEnd)435 TEST_F(StackTraceTest, MAYBE_StackEnd) {
436   EXPECT_NE(0u, GetStackEnd());
437 }
438 
439 #endif  // BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
440 
441 #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID)
442 
443 #if !defined(ADDRESS_SANITIZER) && !defined(UNDEFINED_SANITIZER)
444 
445 #if !defined(ARCH_CPU_ARM_FAMILY)
446 // On Arm architecture invalid math operations such as division by zero are not
447 // trapped and do not trigger a SIGFPE.
448 // Hence disable the test for Arm platforms.
TEST(CheckExitCodeAfterSignalHandlerDeathTest,CheckSIGFPE)449 TEST(CheckExitCodeAfterSignalHandlerDeathTest, CheckSIGFPE) {
450   // Values are volatile to prevent reordering of instructions, i.e. for
451   // optimization. Reordering may lead to tests erroneously failing due to
452   // SIGFPE being raised outside of EXPECT_EXIT.
453   volatile int const nominator = 23;
454   volatile int const denominator = 0;
455   [[maybe_unused]] volatile int result;
456 
457   EXPECT_EXIT(result = nominator / denominator,
458               ::testing::KilledBySignal(SIGFPE), "");
459 }
460 #endif  // !defined(ARCH_CPU_ARM_FAMILY)
461 
TEST(CheckExitCodeAfterSignalHandlerDeathTest,CheckSIGSEGV)462 TEST(CheckExitCodeAfterSignalHandlerDeathTest, CheckSIGSEGV) {
463   // Pointee and pointer are volatile to prevent reordering of instructions,
464   // i.e. for optimization. Reordering may lead to tests erroneously failing due
465   // to SIGSEGV being raised outside of EXPECT_EXIT.
466   volatile int* const volatile p_int = nullptr;
467 
468   EXPECT_EXIT(*p_int = 1234, ::testing::KilledBySignal(SIGSEGV), "");
469 }
470 
471 #if defined(ARCH_CPU_X86_64)
TEST(CheckExitCodeAfterSignalHandlerDeathTest,CheckSIGSEGVNonCanonicalAddress)472 TEST(CheckExitCodeAfterSignalHandlerDeathTest,
473      CheckSIGSEGVNonCanonicalAddress) {
474   // Pointee and pointer are volatile to prevent reordering of instructions,
475   // i.e. for optimization. Reordering may lead to tests erroneously failing due
476   // to SIGSEGV being raised outside of EXPECT_EXIT.
477   //
478   // On Linux, the upper half of the address space is reserved by the kernel, so
479   // all upper bits must be 0 for canonical addresses.
480   volatile int* const volatile p_int =
481       reinterpret_cast<int*>(0xabcdabcdabcdabcdULL);
482 
483   EXPECT_EXIT(*p_int = 1234, ::testing::KilledBySignal(SIGSEGV), "SI_KERNEL");
484 }
485 #endif
486 
487 #endif  // #if !defined(ADDRESS_SANITIZER) && !defined(UNDEFINED_SANITIZER)
488 
TEST(CheckExitCodeAfterSignalHandlerDeathTest,CheckSIGILL)489 TEST(CheckExitCodeAfterSignalHandlerDeathTest, CheckSIGILL) {
490   auto const raise_sigill = []() {
491 #if defined(ARCH_CPU_X86_FAMILY)
492     asm("ud2");
493 #elif defined(ARCH_CPU_ARM_FAMILY)
494     asm("udf 0");
495 #else
496 #error Unsupported platform!
497 #endif
498   };
499 
500   EXPECT_EXIT(raise_sigill(), ::testing::KilledBySignal(SIGILL), "");
501 }
502 
503 #endif  // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID)
504 
505 }  // namespace debug
506 }  // namespace base
507