Skip to content

Commit

Permalink
Make go-bootstrap work with MAP_STACK.
Browse files Browse the repository at this point in the history
  • Loading branch information
4a6f656c committed Apr 5, 2018
1 parent 4742a6e commit 003c056
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lang/go-bootstrap/Makefile
@@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.8 2017/11/28 16:25:43 jsing Exp $
# $OpenBSD: Makefile,v 1.9 2018/04/05 17:47:30 jsing Exp $

ONLY_FOR_ARCHS = ${GO_ARCHS}

Expand All @@ -9,6 +9,7 @@ RELEASE = 20171003
DISTNAME = go${VERSION}-bootstrap-${RELEASE}
PKGNAME = go-bootstrap-${VERSION}.${RELEASE}
CATEGORIES = lang
REVISION = 0

HOMEPAGE = https://golang.org/

Expand Down
13 changes: 13 additions & 0 deletions lang/go-bootstrap/patches/patch-src_runtime_defs_openbsd_386_h
@@ -0,0 +1,13 @@
$OpenBSD: patch-src_runtime_defs_openbsd_386_h,v 1.1 2018/04/05 17:47:30 jsing Exp $

Index: src/runtime/defs_openbsd_386.h
--- src/runtime/defs_openbsd_386.h.orig
+++ src/runtime/defs_openbsd_386.h
@@ -14,6 +14,7 @@ enum {
MAP_ANON = 0x1000,
MAP_PRIVATE = 0x2,
MAP_FIXED = 0x10,
+ MAP_STACK = 0x4000,

MADV_FREE = 0x6,

13 changes: 13 additions & 0 deletions lang/go-bootstrap/patches/patch-src_runtime_defs_openbsd_amd64_h
@@ -0,0 +1,13 @@
$OpenBSD: patch-src_runtime_defs_openbsd_amd64_h,v 1.1 2018/04/05 17:47:30 jsing Exp $

Index: src/runtime/defs_openbsd_amd64.h
--- src/runtime/defs_openbsd_amd64.h.orig
+++ src/runtime/defs_openbsd_amd64.h
@@ -14,6 +14,7 @@ enum {
MAP_ANON = 0x1000,
MAP_PRIVATE = 0x2,
MAP_FIXED = 0x10,
+ MAP_STACK = 0x4000,

MADV_FREE = 0x6,

13 changes: 13 additions & 0 deletions lang/go-bootstrap/patches/patch-src_runtime_malloc_h
@@ -0,0 +1,13 @@
$OpenBSD: patch-src_runtime_malloc_h,v 1.1 2018/04/05 17:47:30 jsing Exp $

Index: src/runtime/malloc.h
--- src/runtime/malloc.h.orig
+++ src/runtime/malloc.h
@@ -197,6 +197,7 @@ struct MLink
// if accessed. Used only for debugging the runtime.

void* runtime·sysAlloc(uintptr nbytes, uint64 *stat);
+void runtime·sysMarkStack(void *v, uintptr nbytes);
void runtime·SysFree(void *v, uintptr nbytes, uint64 *stat);
void runtime·SysUnused(void *v, uintptr nbytes);
void runtime·SysUsed(void *v, uintptr nbytes);
23 changes: 23 additions & 0 deletions lang/go-bootstrap/patches/patch-src_runtime_mem_openbsd_c
@@ -0,0 +1,23 @@
$OpenBSD: patch-src_runtime_mem_openbsd_c,v 1.1 2018/04/05 17:47:30 jsing Exp $

Index: src/runtime/mem_openbsd.c
--- src/runtime/mem_openbsd.c.orig
+++ src/runtime/mem_openbsd.c
@@ -27,6 +27,17 @@ runtime·sysAlloc(uintptr n, uint64 *stat)
return v;
}

+#pragma textflag NOSPLIT
+void
+runtime·sysMarkStack(void *v, uintptr n)
+{
+ void *p;
+
+ p = runtime·mmap(v, n, PROT_READ|PROT_WRITE, MAP_FIXED|MAP_ANON|MAP_PRIVATE|MAP_STACK, -1, 0);
+ if (p == ((void *)-1) || p != v)
+ runtime·throw("runtime: failed to mark stack");
+}
+
void
runtime·SysUnused(void *v, uintptr n)
{
14 changes: 14 additions & 0 deletions lang/go-bootstrap/patches/patch-src_runtime_os_openbsd_c
@@ -0,0 +1,14 @@
$OpenBSD: patch-src_runtime_os_openbsd_c,v 1.1 2018/04/05 17:47:30 jsing Exp $

Index: src/runtime/os_openbsd.c
--- src/runtime/os_openbsd.c.orig
+++ src/runtime/os_openbsd.c
@@ -167,7 +167,7 @@ runtime·newosproc(M *mp, void *stk)

param.tf_tcb = (byte*)&mp->tls[0];
param.tf_tid = (int32*)&mp->procid;
- param.tf_stack = stk;
+ param.tf_stack = (void*)((uintptr)stk - 8);

oset = runtime·sigprocmask(SIG_SETMASK, sigset_all);
ret = runtime·tfork(&param, sizeof(param), mp, mp->g0, runtime·mstart);
21 changes: 21 additions & 0 deletions lang/go-bootstrap/patches/patch-src_runtime_stack_c
@@ -0,0 +1,21 @@
$OpenBSD: patch-src_runtime_stack_c,v 1.1 2018/04/05 17:47:30 jsing Exp $

Index: src/runtime/stack.c
--- src/runtime/stack.c.orig
+++ src/runtime/stack.c
@@ -67,6 +67,7 @@ poolalloc(uint8 order)
s = runtime·MHeap_AllocStack(&runtime·mheap, StackCacheSize >> PageShift);
if(s == nil)
runtime·throw("out of memory");
+ runtime·sysMarkStack((void *)(s->start << PageShift), s->npages << PageShift);
if(s->ref != 0)
runtime·throw("bad ref");
if(s->freelist != nil)
@@ -246,6 +247,7 @@ runtime·stackalloc(uint32 n)
s = runtime·MHeap_AllocStack(&runtime·mheap, ROUND(n, PageSize) >> PageShift);
if(s == nil)
runtime·throw("out of memory");
+ runtime·sysMarkStack((void *)(s->start << PageShift), s->npages << PageShift);
v = (byte*)(s->start<<PageShift);
}

0 comments on commit 003c056

Please sign in to comment.