It seems like a recurring problem for anyone trying to compile a modern web browser/JS engine (whether it's KJS/WebKit or Firefox) on IRIX is the lack of a function to get the stack base for the current thread. Well, here you go:
Code:
#if (_MIPS_SIM == _MIPS_SIM_NABI32)
#define STK_BASE_OFFSET 0x74 // N32
#elif (_MIPS_SIM == _MIPS_SIM_ABI64)
#define STK_BASE_OFFSET 0xB8 // 64
#else
#error N32 and 64 only
#endif
void* IRIX_currentThreadStackBase()
{
void **pstk = (void **)((char *)(PRDALIB->pthread_data[1]) + STK_BASE_OFFSET);
return *pstk;
}
Attachment:
File comment: currentThreadStackBase() implemented for IRIX
irix_currentThreadStackBase.c [430 Bytes]
Downloaded 8 times
I figured this out when trying to compile WebKit a few years ago--KJS implements a function called currentThreadStackBase() (in kjs/Collector.cpp) which returns the base address for the current thread's stack (with #ifdefs for a bunch of different OSes, and none of the paths worked on IRIX).
For example (and as search keywords), here's how it's done in other OSes (from qt 4.4.3's WebKit):
Code:
Darwin uses:
return pthread_get_stackaddr_np(pthread_self())
Solaris:
stack_t s;
thr_stksegment(&s);
return s.ss_sp;
Linux/FreeBSD:
static void *stackBase = 0;
static size_t stackSize = 0;
static pthread_t stackThread;
pthread_t thread = pthread_self();
if (stackBase == 0 || thread != stackThread) {
pthread_attr_t sattr;
pthread_attr_init(&sattr);
#if HAVE(PTHREAD_NP_H)
// e.g. on FreeBSD 5.4, neundorf@kde.org
pthread_attr_get_np(thread, &sattr);
#else
// FIXME: this function is non-portable; other POSIX systems may have different np alternatives
pthread_getattr_np(thread, &sattr);
#endif
int rc = pthread_attr_getstack(&sattr, &stackBase, &stackSize);
(void)rc; // FIXME: deal with error code somehow? seems fatal...
ASSERT(stackBase);
pthread_attr_destroy(&sattr);
stackThread = thread;
}
return (void*)(size_t(stackBase) + stackSize);
I never looked into getting the stack size (since WebKit didn't need it), but if something else (Firefox?) does, we can try to figure that out also.