/* $OpenBSD: uthread_stackseg_np.c,v 1.5 2007/05/18 19:28:50 kurt Exp $ */ /* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman */ #include #include #include #include #include #include #include #include #include #include "pthread_private.h" /* * Return stack info from the given thread. Based upon the solaris * thr_stksegment function. */ int pthread_stackseg_np(pthread_t thread, stack_t *sinfo) { char *base; size_t pgsz; int ret; if (thread->stack) { base = thread->stack->base; #if !defined(MACHINE_STACK_GROWS_UP) base += (ptrdiff_t)thread->stack->size; #endif sinfo->ss_sp = base; sinfo->ss_size = thread->stack->size; sinfo->ss_flags = 0; ret = 0; } else if (thread == _thread_initial) { pgsz = (size_t)sysconf(_SC_PAGESIZE); if (pgsz == (size_t)-1) ret = EAGAIN; else { #if defined(MACHINE_STACK_GROWS_UP) base = (caddr_t) USRSTACK; #else base = (caddr_t) ((USRSTACK - DFLSSIZ) & ~(pgsz - 1)); base += DFLSSIZ; #endif sinfo->ss_sp = base; sinfo->ss_size = DFLSSIZ; sinfo->ss_flags = 0; ret = 0; } } else ret = EAGAIN; return ret; }