]>
git.saurik.com Git - apple/libpthread.git/blob - tests/custom_stack.c
5 #include <os/assumes.h>
7 #include <darwintest.h>
9 static uintptr_t stackaddr
;
10 static const size_t stacksize
= 4096 * 8;
12 static void *function(void *arg
) {
15 strlcpy(buffer
, arg
, sizeof(buffer
));
16 strlcat(buffer
, arg
, sizeof(buffer
));
18 T_ASSERT_LT((uintptr_t)__builtin_frame_address(0), stackaddr
, NULL
);
19 T_ASSERT_GT((uintptr_t)__builtin_frame_address(0), stackaddr
- stacksize
, NULL
);
21 return (void *)(uintptr_t)strlen(buffer
);
24 T_DECL(custom_stack
, "creating a pthread with a custom stack",
25 T_META_ALL_VALID_ARCHS(YES
)){
26 char *arg
= "This is a test and only a test of the pthread stackaddr system.\n";
27 stackaddr
= (uintptr_t)valloc(stacksize
);
28 stackaddr
+= stacksize
; // address starts at top of stack.
33 T_ASSERT_POSIX_ZERO(pthread_attr_init(&attr
), NULL
);
34 T_ASSERT_POSIX_ZERO(pthread_attr_setstacksize(&attr
, stacksize
), NULL
);
35 T_ASSERT_POSIX_ZERO(pthread_attr_setstackaddr(&attr
, (void *)stackaddr
), NULL
);
37 T_ASSERT_POSIX_ZERO(pthread_create(&thread
, &attr
, function
, arg
), NULL
);
40 T_ASSERT_POSIX_ZERO(pthread_join(thread
, &result
), NULL
);
41 T_ASSERT_EQ((uintptr_t)result
, (uintptr_t)strlen(arg
)*2, "thread should return correct value");
43 free((void*)(stackaddr
- stacksize
));