pthread: retrieve stack address and size

issue #2791
This commit is contained in:
Sebastian Sumpf 2018-04-24 13:55:08 +02:00 committed by Christian Helmuth
parent df3e4edd76
commit eccfa5e1e7

View File

@ -273,21 +273,40 @@ extern "C" {
void **stackaddr, void **stackaddr,
::size_t *stacksize) ::size_t *stacksize)
{ {
/* FIXME */
warning("pthread_attr_getstack() called, might not work correctly");
if (!attr || !*attr || !stackaddr || !stacksize) if (!attr || !*attr || !stackaddr || !stacksize)
return EINVAL; return EINVAL;
pthread_t pthread = (*attr)->pthread; pthread_t pthread = (*attr)->pthread;
*stackaddr = pthread->stack_top(); if (pthread != pthread_self()) {
*stacksize = (addr_t)pthread->stack_top() - (addr_t)pthread->stack_base(); error("pthread_attr_getstack() called, where pthread != phtread_self");
*stackaddr = nullptr;
*stacksize = 0;
return EINVAL;
}
Thread::Stack_info info = Thread::mystack();
*stackaddr = (void *)info.base;
*stacksize = info.top - info.base;
return 0; return 0;
} }
int pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr)
{
size_t stacksize;
return pthread_attr_getstack(attr, stackaddr, &stacksize);
}
int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize)
{
void *stackaddr;
return pthread_attr_getstack(attr, &stackaddr, stacksize);
}
int pthread_attr_get_np(pthread_t pthread, pthread_attr_t *attr) int pthread_attr_get_np(pthread_t pthread, pthread_attr_t *attr)
{ {
if (!attr) if (!attr)