how to find the thread stack limit?

Dan Connolly dckc at madmode.com
Thu Aug 5 04:27:24 CEST 2021


I'm trying to port this XS JavaScript engine to genode. It wants to know
the stack limit. Any suggestions on how to do this?


https://github.com/Moddable-OpenSource/moddable/blob/public/xs/sources/xsCommon.c#L518-L542

char* fxCStackLimit()
{
#if mxWindows
ULONG_PTR low, high;
GetCurrentThreadStackLimits(&low, &high);
return (char*)low + (32 * 1024);
#elif mxMacOSX
pthread_t self = pthread_self();
void* stackAddr = pthread_get_stackaddr_np(self);
size_t stackSize = pthread_get_stacksize_np(self);
return (char*)stackAddr - stackSize + (8 * 1024);
#elif mxLinux
pthread_attr_t attrs;
if (pthread_getattr_np(pthread_self(), &attrs) == 0) {
void* stackAddr;
size_t stackSize;
if (pthread_attr_getstack(&attrs, &stackAddr, &stackSize) == 0) {
return (char*)stackAddr + (4 * 1024);
}
}
return C_NULL;
#else
return C_NULL;
#endif
}
-- 
Dan Connolly
http://www.madmode.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.genode.org/pipermail/users/attachments/20210804/767b4b23/attachment.html>


More information about the users mailing list