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 #define TRAPSIG SIGTRAP
12 #elif defined(__x86_64__)
13 #define call_chkstk(value) \
14 __asm__ volatile("movq %0, %%rax\t\n" \
15 "callq _thread_chkstk_darwin" : : "i"(value) : "rax")
16 #define TRAPSIG SIGILL
17 #elif defined(__i386__)
18 #define call_chkstk(value) \
19 __asm__ volatile("movl %0, %%eax\t\n" \
20 "calll _thread_chkstk_darwin" : : "i"(value) : "eax")
21 #define TRAPSIG SIGILL
25 got_signal(int signo __unused
)
27 T_PASS("calling with 1 << 24 crashed");
31 T_DECL(chkstk
, "chkstk",
32 T_META_ALL_VALID_ARCHS(YES
), T_META_CHECK_LEAKS(NO
))
35 T_SKIP("not on armv7");
39 T_PASS("calling with 1 << 8");
42 T_PASS("calling with 1 << 16");
44 signal(TRAPSIG
, got_signal
);
47 T_FAIL("should have crashed");
56 OS_NOINLINE OS_NOT_TAIL_CALLED
58 do_stack_frame_decode_test(struct frame frames
[], size_t n
, size_t count
)
61 frames
[n
].frame
= (uintptr_t)__builtin_frame_address(1);
62 frames
[n
].ret
= (uintptr_t)__builtin_return_address(0);
63 do_stack_frame_decode_test(frames
, n
+ 1, count
);
65 uintptr_t frame
= (uintptr_t)__builtin_frame_address(1);
68 frame
= pthread_stack_frame_decode_np(frame
, &ret
);
69 T_EXPECT_EQ(frames
[count
].frame
, frame
, "Frame %zd", count
);
70 T_EXPECT_EQ(frames
[count
].ret
, ret
, "Retaddr %zd", count
);
75 T_DECL(pthread_stack_frame_decode_np
, "pthread_stack_frame_decode_np",
76 T_META_ALL_VALID_ARCHS(YES
), T_META_CHECK_LEAKS(NO
))
78 struct frame frames
[10];
79 frames
[0].frame
= (uintptr_t)__builtin_frame_address(1);
80 frames
[0].ret
= (uintptr_t)__builtin_return_address(0);
81 do_stack_frame_decode_test(frames
, 1, 10);