1 /*- 2 * Copyright (c) 2023 Dmitry Chagin <dchagin@FreeBSD.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7 #include <sys/param.h> 8 #include <sys/wait.h> 9 10 #include <execinfo.h> 11 #include <signal.h> 12 #include <stdio.h> 13 #include <string.h> 14 #include <unistd.h> 15 16 #include <atf-c.h> 17 18 #define BT_FUNCTIONS 10 19 20 void handler(int); 21 22 __noinline void 23 handler(int signum __unused) 24 { 25 void *addresses[BT_FUNCTIONS]; 26 char **symbols; 27 size_t n, i, match; 28 29 n = backtrace(addresses, nitems(addresses)); 30 ATF_REQUIRE(n > 1); 31 symbols = backtrace_symbols(addresses, n); 32 ATF_REQUIRE(symbols != NULL); 33 34 match = -1; 35 for (i = 0; i < n; i++) { 36 printf("%zu: %p, %s\n", i, addresses[i], symbols[i]); 37 if (strstr(symbols[i], "<main+") != NULL) 38 match = i; 39 } 40 ATF_REQUIRE(match > 0); 41 printf("match at %zu, symbols %zu\n", match, n); 42 43 } 44 45 ATF_TC_WITHOUT_HEAD(test_backtrace_sigtramp); 46 ATF_TC_BODY(test_backtrace_sigtramp, tc) 47 { 48 #if defined(__aarch64__) 49 /* 50 * https://reviews.llvm.org is deprecated and 51 * this review is never going to be updated or completed 52 */ 53 atf_tc_expect_fail("https://reviews.llvm.org/D155066"); 54 #endif 55 56 struct sigaction act; 57 pid_t child; 58 int status; 59 60 memset(&act, 0, sizeof(act)); 61 act.sa_handler = handler; 62 sigemptyset(&act.sa_mask); 63 sigaction(SIGUSR1, &act, NULL); 64 65 child = fork(); 66 ATF_REQUIRE(child != -1); 67 68 if (child == 0) { 69 kill(getppid(), SIGUSR1); 70 _exit(0); 71 } else 72 wait(&status); 73 } 74 75 ATF_TP_ADD_TCS(tp) 76 { 77 78 ATF_TP_ADD_TC(tp, test_backtrace_sigtramp); 79 80 return (atf_no_error()); 81 } 82