|
67 | 67 | # include <stdio.h> |
68 | 68 | # include <unistd.h> |
69 | 69 | # include <sys/resource.h> |
| 70 | +# include <pthread.h> |
70 | 71 | # include <sys/stat.h> |
71 | 72 | # include <sys/time.h> |
72 | 73 | # include <sys/utsname.h> |
|
82 | 83 | # include <pthread_np.h> |
83 | 84 | #endif |
84 | 85 |
|
| 86 | +// needed by current_stack_region() workaround for Mavericks |
| 87 | +#if defined(__APPLE__) |
| 88 | +# include <errno.h> |
| 89 | +# include <sys/types.h> |
| 90 | +# include <sys/sysctl.h> |
| 91 | +# define DEFAULT_MAIN_THREAD_STACK_PAGES 2048 |
| 92 | +# define OS_X_10_9_0_KERNEL_MAJOR_VERSION 13 |
| 93 | +#endif |
| 94 | + |
85 | 95 | #define SPELL_REG_SP "sp" |
86 | 96 | #define SPELL_REG_FP "fp" |
87 | 97 |
|
88 | 98 | #ifdef __APPLE__ |
89 | 99 | // see darwin-xnu/osfmk/mach/arm/_structs.h |
90 | 100 |
|
91 | | -// 10.5 UNIX03 member name prefixes |
92 | | -#define DU3_PREFIX(s, m) __ ## s.__ ## m |
| 101 | +# if __DARWIN_UNIX03 && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) |
| 102 | + // 10.5 UNIX03 member name prefixes |
| 103 | + #define DU3_PREFIX(s, m) __ ## s.__ ## m |
| 104 | +# else |
| 105 | + #define DU3_PREFIX(s, m) s ## . ## m |
| 106 | +# endif |
93 | 107 | #endif |
94 | 108 |
|
95 | 109 | #define context_x uc_mcontext->DU3_PREFIX(ss,x) |
@@ -199,6 +213,15 @@ bool PosixSignals::pd_hotspot_signal_handler(int sig, siginfo_t* info, |
199 | 213 | // point of execution. |
200 | 214 | ThreadWXEnable wx(WXWrite, thread); |
201 | 215 |
|
| 216 | +/* |
| 217 | + NOTE: does not seem to work on bsd. |
| 218 | + if (info == NULL || info->si_code <= 0 || info->si_code == SI_NOINFO) { |
| 219 | + // can't decode this kind of signal |
| 220 | + info = NULL; |
| 221 | + } else { |
| 222 | + assert(sig == info->si_signo, "bad siginfo"); |
| 223 | + } |
| 224 | +*/ |
202 | 225 | // decide if this trap can be handled by a stub |
203 | 226 | address stub = NULL; |
204 | 227 |
|
@@ -356,6 +379,27 @@ static void current_stack_region(address * bottom, size_t * size) { |
356 | 379 | pthread_t self = pthread_self(); |
357 | 380 | void *stacktop = pthread_get_stackaddr_np(self); |
358 | 381 | *size = pthread_get_stacksize_np(self); |
| 382 | + // workaround for OS X 10.9.0 (Mavericks) |
| 383 | + // pthread_get_stacksize_np returns 128 pages even though the actual size is 2048 pages |
| 384 | + if (pthread_main_np() == 1) { |
| 385 | + // At least on Mac OS 10.12 we have observed stack sizes not aligned |
| 386 | + // to pages boundaries. This can be provoked by e.g. setrlimit() (ulimit -s xxxx in the |
| 387 | + // shell). Apparently Mac OS actually rounds upwards to next multiple of page size, |
| 388 | + // however, we round downwards here to be on the safe side. |
| 389 | + *size = align_down(*size, getpagesize()); |
| 390 | + |
| 391 | + if ((*size) < (DEFAULT_MAIN_THREAD_STACK_PAGES * (size_t)getpagesize())) { |
| 392 | + char kern_osrelease[256]; |
| 393 | + size_t kern_osrelease_size = sizeof(kern_osrelease); |
| 394 | + int ret = sysctlbyname("kern.osrelease", kern_osrelease, &kern_osrelease_size, NULL, 0); |
| 395 | + if (ret == 0) { |
| 396 | + // get the major number, atoi will ignore the minor amd micro portions of the version string |
| 397 | + if (atoi(kern_osrelease) >= OS_X_10_9_0_KERNEL_MAJOR_VERSION) { |
| 398 | + *size = (DEFAULT_MAIN_THREAD_STACK_PAGES*getpagesize()); |
| 399 | + } |
| 400 | + } |
| 401 | + } |
| 402 | + } |
359 | 403 | *bottom = (address) stacktop - *size; |
360 | 404 | #elif defined(__OpenBSD__) |
361 | 405 | stack_t ss; |
|
0 commit comments