Nekochan Net

Official Chat Channel: #nekochan // irc.nekochan.net
It is currently Mon Nov 24, 2014 1:00 am

All times are UTC - 8 hours [ DST ]


Forum rules


Any posts concerning pirated software or offering to buy/sell/trade commercial software are subject to removal.



Post new topic Reply to topic  [ 2 posts ] 
Author Message
Unread postPosted: Sat Mar 31, 2012 9:14 pm 
Offline

Joined: Thu Sep 28, 2006 6:50 pm
Posts: 139
Location: Long Beach, CA
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 21 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.

_________________
:Octane: R12K/300x2, MXE
:1600SW: :ChallengeL:


Top
 Profile  
 
Unread postPosted: Sun Jul 22, 2012 11:30 am 
Offline

Joined: Tue Aug 03, 2010 9:08 am
Posts: 48
Thanks for posting this! This is no doubt going to save me a chunk of time.

_________________
:1600SW: :O2: :O2+: :O2: :1600SW:


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: Bing [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group