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