]> git.saurik.com Git - apple/libpthread.git/blame - tests/main_stack_custom.c
libpthread-218.1.3.tar.gz
[apple/libpthread.git] / tests / main_stack_custom.c
CommitLineData
2546420a
A
1#include <stdlib.h>
2#include <pthread.h>
3#include <darwintest.h>
4#include <machine/vmparam.h>
5
6T_DECL(main_stack_custom, "tests the reported values for a custom main thread stack"){
7 T_EXPECT_EQ((size_t)STACKSIZE, pthread_get_stacksize_np(pthread_self()), NULL);
8
9 const uintptr_t stackaddr = (uintptr_t)pthread_get_stackaddr_np(pthread_self());
10 size_t stacksize = pthread_get_stacksize_np(pthread_self());
11 T_LOG("stack: %zx -> %zx (+%zx)", stackaddr - stacksize, stackaddr, stacksize);
12 T_EXPECT_LT((uintptr_t)__builtin_frame_address(0), stackaddr, NULL);
13 T_EXPECT_GT((uintptr_t)__builtin_frame_address(0), stackaddr - stacksize, NULL);
14
15 struct rlimit lim;
16 T_QUIET; T_ASSERT_POSIX_SUCCESS(getrlimit(RLIMIT_STACK, &lim), NULL);
17 lim.rlim_cur = lim.rlim_cur / 8;
18 T_EXPECT_EQ(setrlimit(RLIMIT_STACK, &lim), -1, "setrlimit for stack should fail with custom stack");
19 T_EXPECT_EQ((size_t)STACKSIZE, pthread_get_stacksize_np(pthread_self()), "reported stacksize shouldn't change");
20}