891 // | |\
892 // | glibc guard page | - usually 1 page
893 // | |/
894 // P1 +------------------------+ Thread::stack_base() - Thread::stack_size()
895 // | |\
896 // | Normal Stack | -
897 // | |/
898 // P2 +------------------------+ Thread::stack_base()
899 //
900 // ** P1 (aka bottom) and size ( P2 = P1 - size) are the address and stack size returned from
901 // pthread_attr_getstack()
902
903 static void current_stack_region(address * bottom, size_t * size) {
904 #ifdef __APPLE__
905 pthread_t self = pthread_self();
906 void *stacktop = pthread_get_stackaddr_np(self);
907 *size = pthread_get_stacksize_np(self);
908 // workaround for OS X 10.9.0 (Mavericks)
909 // pthread_get_stacksize_np returns 128 pages even though the actual size is 2048 pages
910 if (pthread_main_np() == 1) {
911 if ((*size) < (DEFAULT_MAIN_THREAD_STACK_PAGES * (size_t)getpagesize())) {
912 char kern_osrelease[256];
913 size_t kern_osrelease_size = sizeof(kern_osrelease);
914 int ret = sysctlbyname("kern.osrelease", kern_osrelease, &kern_osrelease_size, NULL, 0);
915 if (ret == 0) {
916 // get the major number, atoi will ignore the minor amd micro portions of the version string
917 if (atoi(kern_osrelease) >= OS_X_10_9_0_KERNEL_MAJOR_VERSION) {
918 *size = (DEFAULT_MAIN_THREAD_STACK_PAGES*getpagesize());
919 }
920 }
921 }
922 }
923 *bottom = (address) stacktop - *size;
924 #elif defined(__OpenBSD__)
925 stack_t ss;
926 int rslt = pthread_stackseg_np(pthread_self(), &ss);
927
928 if (rslt != 0)
929 fatal("pthread_stackseg_np failed with error = %d", rslt);
930
|
891 // | |\
892 // | glibc guard page | - usually 1 page
893 // | |/
894 // P1 +------------------------+ Thread::stack_base() - Thread::stack_size()
895 // | |\
896 // | Normal Stack | -
897 // | |/
898 // P2 +------------------------+ Thread::stack_base()
899 //
900 // ** P1 (aka bottom) and size ( P2 = P1 - size) are the address and stack size returned from
901 // pthread_attr_getstack()
902
903 static void current_stack_region(address * bottom, size_t * size) {
904 #ifdef __APPLE__
905 pthread_t self = pthread_self();
906 void *stacktop = pthread_get_stackaddr_np(self);
907 *size = pthread_get_stacksize_np(self);
908 // workaround for OS X 10.9.0 (Mavericks)
909 // pthread_get_stacksize_np returns 128 pages even though the actual size is 2048 pages
910 if (pthread_main_np() == 1) {
911 // At least on Mac OS 10.12 we have observed stack sizes not alligned
912 // to pages boundries. This can be provoked by e.g. setrlimit() (ulimit -s xxxx in the
913 // shell). Apparently Mac OS actually rounds upwards to next multiple of page size,
914 // however, I round downwards here to be on the safe side.
915 *size = align_down(*size, getpagesize());
916
917 if ((*size) < (DEFAULT_MAIN_THREAD_STACK_PAGES * (size_t)getpagesize())) {
918 char kern_osrelease[256];
919 size_t kern_osrelease_size = sizeof(kern_osrelease);
920 int ret = sysctlbyname("kern.osrelease", kern_osrelease, &kern_osrelease_size, NULL, 0);
921 if (ret == 0) {
922 // get the major number, atoi will ignore the minor amd micro portions of the version string
923 if (atoi(kern_osrelease) >= OS_X_10_9_0_KERNEL_MAJOR_VERSION) {
924 *size = (DEFAULT_MAIN_THREAD_STACK_PAGES*getpagesize());
925 }
926 }
927 }
928 }
929 *bottom = (address) stacktop - *size;
930 #elif defined(__OpenBSD__)
931 stack_t ss;
932 int rslt = pthread_stackseg_np(pthread_self(), &ss);
933
934 if (rslt != 0)
935 fatal("pthread_stackseg_np failed with error = %d", rslt);
936
|