Use of Threads under HPUX currently raise rb_eNotImpError ("ruby engine can initialize only in the main thread") since the STACKADDR_AVAILABLE is not available. This brings basic support for the get_stack() under HPUX. This patch also resolves issue under HPUX where signals usually cause the coredump since the stack size is too small. Signed-off-by: Michal Rokos diff --git a/thread_pthread.c b/thread_pthread.c index e08f3de..66ef3a8 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -511,6 +511,14 @@ size_t pthread_get_stacksize_np(pthread_t); #define STACKADDR_AVAILABLE 1 #elif defined HAVE_PTHREAD_GETTHRDS_NP #define STACKADDR_AVAILABLE 1 +#elif defined __ia64 && defined _HPUX_SOURCE +#define STACKADDR_AVAILABLE 1 +/* + * Do not lower the thread's stack to PTHREAD_STACK_MIN, + * otherwise one would receive a 'sendsig: useracc failed.' + * and a coredump. + */ +#undef PTHREAD_STACK_MIN #endif #ifndef MAINSTACKADDR_AVAILABLE @@ -582,6 +590,30 @@ get_stack(void **addr, size_t *size) *addr = thinfo.__pi_stackaddr; *size = thinfo.__pi_stacksize; STACK_DIR_UPPER((void)0, (void)(*addr = (char *)*addr + *size)); +#elif defined __ia64 && defined _HPUX_SOURCE + /* + * Although HP-UX defines _pthread_stack_info_np(), it cannot be + * used since it returns an error when the thread is not suspended. + * So lets use some other way to get the stack information... + */ + pthread_attr_t attr; + + /* + * Using value of sp is very rough... To make it more real, + * addr would need to be aligned to vps_pagesize. + * The vps_pagesize is 'Default user page size (kBytes)' + * and could be retrieved by gettune(). + */ + *addr = _Asm_get_sp(); + + /* + * As the PTHREAD_STACK_MIN is undefined and + * noone touches the default stacksize, + * it is just fine to use the default. + */ + CHECK_ERR(pthread_attr_init(&attr)); + CHECK_ERR(pthread_attr_getstacksize(&attr, size)); + pthread_attr_destroy(&attr); #else #error STACKADDR_AVAILABLE is defined but not implemented. #endif