Get current thread stack base

IRIX/Nekoware development, porting and related topics.
Forum rules
Any posts concerning pirated software or offering to buy/sell/trade commercial software are subject to removal.
Posts: 147
Joined: Thu Sep 28, 2006 6:50 pm
Location: Huntington Beach, CA

Get current thread stack base

Unread postby pip » Sat Mar 31, 2012 9:14 pm

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: Select all

#define STK_BASE_OFFSET 0x74    // N32
#elif (_MIPS_SIM == _MIPS_SIM_ABI64)
#define STK_BASE_OFFSET 0xB8    // 64
#error N32 and 64 only

void* IRIX_currentThreadStackBase()
        void **pstk = (void **)((char *)(PRDALIB->pthread_data[1]) + STK_BASE_OFFSET);
        return *pstk;

currentThreadStackBase() implemented for IRIX
(430 Bytes) Downloaded 27 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: Select all

Darwin uses:
    return pthread_get_stackaddr_np(pthread_self())

    stack_t s;
    return s.ss_sp;

    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;
        // e.g. on FreeBSD 5.4,
        pthread_attr_get_np(thread, &sattr);
        // FIXME: this function is non-portable; other POSIX systems may have different np alternatives
        pthread_getattr_np(thread, &sattr);
        int rc = pthread_attr_getstack(&sattr, &stackBase, &stackSize);
        (void)rc; // FIXME: deal with error code somehow?  seems fatal...
        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.
:Octane: R12K/300x2, MXE
:Indy: :O2: :1600SW: :ChallengeL:

Posts: 50
Joined: Tue Aug 03, 2010 9:08 am

Re: Get current thread stack base

Unread postby telackey » Sun Jul 22, 2012 11:30 am

Thanks for posting this! This is no doubt going to save me a chunk of time.
:1600SW: :O2: :O2+: :O2: :1600SW:

Return to “SGI: Development”

Who is online

Users browsing this forum: No registered users and 1 guest