make plan9port work with MAP_STACK

initial diff from Aaron Poffenberger <akp () hypernote ! com>
This commit is contained in:
gsoares 2018-04-09 15:14:33 +00:00
parent 9ce39b3e90
commit 7ee94eb614
3 changed files with 62 additions and 1 deletions

View File

@ -1,9 +1,10 @@
# $OpenBSD: Makefile,v 1.24 2018/01/20 03:29:56 gsoares Exp $
# $OpenBSD: Makefile,v 1.25 2018/04/09 15:14:33 gsoares Exp $
ONLY_FOR_ARCHS = amd64 i386 powerpc
BROKEN-powerpc = threading issues
COMMENT = Plan 9 from user space
REVISION = 0
DISTNAME = plan9port-20180117

View File

@ -0,0 +1,46 @@
$OpenBSD: patch-src_libthread_thread_c,v 1.1 2018/04/09 15:14:33 gsoares Exp $
Index: src/libthread/thread.c
--- src/libthread/thread.c.orig
+++ src/libthread/thread.c
@@ -107,12 +107,18 @@ threadalloc(void (*fn)(void*), void *arg, uint stack)
uint x, y;
ulong z;
- /* allocate the task and stack together */
- t = malloc(sizeof *t+stack);
+ /* allocate the task */
+ t = malloc(sizeof *t);
if(t == nil)
sysfatal("threadalloc malloc: %r");
memset(t, 0, sizeof *t);
- t->stk = (uchar*)(t+1);
+ /* allocate the real stack */
+ t->stk = mmap(NULL, stack, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANON | MAP_STACK, -1, 0);
+ if (t->stk == MAP_FAILED) {
+ free(t);
+ sysfatal("threadalloc malloc: %r");
+ }
t->stksize = stack;
t->id = incref(&threadidref);
//print("fn=%p arg=%p\n", fn, arg);
@@ -133,8 +139,8 @@ threadalloc(void (*fn)(void*), void *arg, uint stack)
/* call makecontext to do the real work. */
/* leave a few words open on both ends */
- t->context.uc.uc_stack.ss_sp = (void*)(t->stk+8);
- t->context.uc.uc_stack.ss_size = t->stksize-64;
+ t->context.uc.uc_stack.ss_sp = t->stk;
+ t->context.uc.uc_stack.ss_size = t->stksize;
#if defined(__sun__) && !defined(__MAKECONTEXT_V2_SOURCE) /* sigh */
/* can avoid this with __MAKECONTEXT_V2_SOURCE but only on SunOS 5.9 */
t->context.uc.uc_stack.ss_sp =
@@ -364,6 +370,7 @@ procscheduler(Proc *p)
delthreadinproc(p, t);
p->nthread--;
/*print("nthread %d\n", p->nthread); */
+ munmap(t->stk, t->stksize);
free(t);
}
}

View File

@ -0,0 +1,14 @@
$OpenBSD: patch-src_libthread_threadimpl_h,v 1.3 2018/04/09 15:14:33 gsoares Exp $
Index: src/libthread/threadimpl.h
--- src/libthread/threadimpl.h.orig
+++ src/libthread/threadimpl.h
@@ -10,6 +10,8 @@
# define _XOPEN_SOURCE /* for Snow Leopard */
# endif
# include <ucontext.h>
+#elif defined(__OpenBSD__)
+# include <sys/mman.h>
#endif
#include <sys/utsname.h>
#include "libc.h"