X-Git-Url: https://git.saurik.com/apple/libpthread.git/blobdiff_plain/3404ec80a22ac38c97e573f77f7cbdf4bddc8ca9..964d3577b041867f776d8eb940bf4a1108ffb97c:/tests/custom_stack.c diff --git a/tests/custom_stack.c b/tests/custom_stack.c new file mode 100644 index 0000000..1066ea0 --- /dev/null +++ b/tests/custom_stack.c @@ -0,0 +1,38 @@ +#include +#include +#include +#include +#include + +void *function(void *arg) { + // Use the stack... + char buffer[BUFSIZ]; + strlcpy(buffer, arg, sizeof(buffer)); + strlcat(buffer, arg, sizeof(buffer)); + + printf("%s", buffer); + sleep(30); + return (void *)(uintptr_t)strlen(buffer); +} + +int main(int argc, char *argv[]) { + char *arg = "This is a test and only a test of the pthread stackaddr system.\n"; + size_t stacksize = 4096 * 5; + uintptr_t stackaddr = (uintptr_t)valloc(stacksize); + stackaddr += stacksize; // address starts at top of stack. + + pthread_t thread; + pthread_attr_t attr; + + os_assumes_zero(pthread_attr_init(&attr)); + os_assumes_zero(pthread_attr_setstacksize(&attr, stacksize)); + os_assumes_zero(pthread_attr_setstackaddr(&attr, (void *)stackaddr)); + + os_assumes_zero(pthread_create(&thread, &attr, function, arg)); + + void *result; + os_assumes_zero(pthread_join(thread, &result)); + os_assumes((uintptr_t)result == (uintptr_t)strlen(arg)*2); + + return 0; +}