From 06f401d46d2aea0cfd912b6053417460eddf281e Mon Sep 17 00:00:00 2001 From: ahgamut <41098605+ahgamut@users.noreply.github.com> Date: Fri, 9 Sep 2022 09:16:16 +0530 Subject: [PATCH] set stackaddr if mmap is called in pthread_create when calling pthread_create with a pthread_attr_t *attr, if attr != NULL AND attr->stackaddr != 0, then stack is not managed by cosmo pt->spawn.stk = attr->stackaddr, and so pt->attr.stackaddr = pt->spawn.stk is a no op if attr == NULL OR attr->stackaddr == 0, the stack is managed by cosmo, pt->spawn.stk is from a successful mmap, (and this is the oneline change) so pt->attr.stackaddr SHOULD BE SET AS pt->spawn.stk --- libc/thread/pthread_create.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libc/thread/pthread_create.c b/libc/thread/pthread_create.c index b384ef6a5..25a6cd15a 100644 --- a/libc/thread/pthread_create.c +++ b/libc/thread/pthread_create.c @@ -196,6 +196,15 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr, // we only need to save this to support pthread_getattr_np() pt->attr = *attr; + // if attr->stackaddr == 0, + // the stack is managed by cosmo, + // pt->spawn.stk is from a successful mmap, + // and so pt->attr.stackaddr = pt->spawn.stk + pt->attr.stackaddr = pt->spawn.stk; + // if attr->stackaddr != 0, + // then stack is not managed by cosmo + // pt->attr.stackaddr = pt->spawn.stk = attr->stackaddr + // so the above line is a no-op. // set initial status switch (attr->detachstate) {