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