2 #include <pthread/stack_np.h>
4 #include "darwintest_defaults.h"
5 #include <darwintest_utils.h>
8 #define call_chkstk(value) \
9 __asm__ volatile("orr x9, xzr, %0\t\n" \
10 "bl _thread_chkstk_darwin" : : "i"(value) : "x9")
11 #elif defined(__x86_64__)
12 #define call_chkstk(value) \
13 __asm__ volatile("movq %0, %%rax\t\n" \
14 "callq _thread_chkstk_darwin" : : "i"(value) : "rax")
15 #elif defined(__i386__)
16 #define call_chkstk(value) \
17 __asm__ volatile("movl %0, %%eax\t\n" \
18 "calll _thread_chkstk_darwin" : : "i"(value) : "eax")
22 got_signal(int signo __unused
)
24 T_PASS("calling with 1 << 24 crashed");
28 T_DECL(chkstk
, "chkstk",
29 T_META_ALL_VALID_ARCHS(YES
), T_META_CHECK_LEAKS(NO
))
32 T_SKIP("not on armv7");
36 T_PASS("calling with 1 << 8");
39 T_PASS("calling with 1 << 16");
42 .ss_sp
= malloc(MINSIGSTKSZ
),
43 .ss_size
= MINSIGSTKSZ
,
45 T_ASSERT_POSIX_SUCCESS(sigaltstack(&ss
, NULL
), "sigaltstack");
47 struct sigaction sa
= {
48 .sa_handler
= got_signal
,
49 .sa_flags
= SA_ONSTACK
,
51 T_ASSERT_POSIX_SUCCESS(sigaction(SIGSEGV
, &sa
, NULL
), "sigaction");
54 call_chkstk(1ul << 32);
56 call_chkstk(1ul << 24);
58 T_FAIL("should have crashed");
67 OS_NOINLINE OS_NOT_TAIL_CALLED
69 do_stack_frame_decode_test(struct frame frames
[], size_t n
, size_t count
)
72 frames
[n
].frame
= (uintptr_t)__builtin_frame_address(1);
73 frames
[n
].ret
= (uintptr_t)__builtin_return_address(0);
74 do_stack_frame_decode_test(frames
, n
+ 1, count
);
76 uintptr_t frame
= (uintptr_t)__builtin_frame_address(1);
79 frame
= pthread_stack_frame_decode_np(frame
, &ret
);
80 T_EXPECT_EQ(frames
[count
].frame
, frame
, "Frame %zd", count
);
81 T_EXPECT_EQ(frames
[count
].ret
, ret
, "Retaddr %zd", count
);
86 T_DECL(pthread_stack_frame_decode_np
, "pthread_stack_frame_decode_np",
87 T_META_ALL_VALID_ARCHS(YES
), T_META_CHECK_LEAKS(NO
))
89 struct frame frames
[10];
90 frames
[0].frame
= (uintptr_t)__builtin_frame_address(1);
91 frames
[0].ret
= (uintptr_t)__builtin_return_address(0);
92 do_stack_frame_decode_test(frames
, 1, 10);