--- /dev/null
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build !openbsd
+
+package runtime
+
+// osStackAlloc performs OS-specific initialization before s is used
+// as stack memory.
+func osStackAlloc(s *mspan) {
+}
+
+// osStackFree undoes the effect of osStackAlloc before s is returned
+// to the heap.
+func osStackFree(s *mspan) {
+}
// From OpenBSD's <sys/sysctl.h>
const (
+ _CTL_KERN = 1
+ _KERN_OSREV = 3
+
_CTL_HW = 6
_HW_NCPU = 3
_HW_PAGESIZE = 7
return 0
}
+func getOSRev() int32 {
+ mib := [2]uint32{_CTL_KERN, _KERN_OSREV}
+ out := uint32(0)
+ nout := unsafe.Sizeof(out)
+ ret := sysctl(&mib[0], 2, (*byte)(unsafe.Pointer(&out)), &nout, nil, 0)
+ if ret >= 0 {
+ return int32(out)
+ }
+ return 0
+}
+
//go:nosplit
func semacreate(mp *m) {
}
func osinit() {
ncpu = getncpu()
physPageSize = getPageSize()
+ haveMapStack = getOSRev() >= 201805 // OpenBSD 6.3
}
var urandom_dev = []byte("/dev/urandom\x00")
func (c *sigctxt) fixsigcode(sig uint32) {
}
+
+var haveMapStack = false
+
+func osStackAlloc(s *mspan) {
+ // OpenBSD 6.4+ requires that stacks be mapped with MAP_STACK.
+ // It will check this on entry to system calls, traps, and
+ // when switching to the alternate system stack.
+ //
+ // This function is called before s is used for any data, so
+ // it's safe to simply re-map it.
+ osStackRemap(s, _MAP_STACK)
+}
+
+func osStackFree(s *mspan) {
+ // Undo MAP_STACK.
+ osStackRemap(s, 0)
+}
+
+func osStackRemap(s *mspan, flags int32) {
+ if !haveMapStack {
+ // OpenBSD prior to 6.3 did not have MAP_STACK and so
+ // the following mmap will fail. But it also didn't
+ // require MAP_STACK (obviously), so there's no need
+ // to do the mmap.
+ return
+ }
+ a, err := mmap(unsafe.Pointer(s.base()), s.npages*pageSize, _PROT_READ|_PROT_WRITE, _MAP_PRIVATE|_MAP_ANON|_MAP_FIXED|flags, -1, 0)
+ if err != 0 || uintptr(a) != s.base() {
+ print("runtime: remapping stack memory ", hex(s.base()), " ", s.npages*pageSize, " a=", a, " err=", err, "\n")
+ throw("remapping stack memory failed")
+ }
+}
if s.manualFreeList.ptr() != nil {
throw("bad manualFreeList")
}
+ osStackAlloc(s)
s.elemsize = _FixedStack << order
for i := uintptr(0); i < _StackCacheSize; i += s.elemsize {
x := gclinkptr(s.base() + i)
// By not freeing, we prevent step #4 until GC is done.
stackpool[order].remove(s)
s.manualFreeList = 0
+ osStackFree(s)
mheap_.freeManual(s, &memstats.stacks_inuse)
}
}
if s == nil {
throw("out of memory")
}
+ osStackAlloc(s)
s.elemsize = uintptr(n)
}
v = unsafe.Pointer(s.base())
if gcphase == _GCoff {
// Free the stack immediately if we're
// sweeping.
+ osStackFree(s)
mheap_.freeManual(s, &memstats.stacks_inuse)
} else {
// If the GC is running, we can't return a
if s.allocCount == 0 {
list.remove(s)
s.manualFreeList = 0
+ osStackFree(s)
mheap_.freeManual(s, &memstats.stacks_inuse)
}
s = next
for s := stackLarge.free[i].first; s != nil; {
next := s.next
stackLarge.free[i].remove(s)
+ osStackFree(s)
mheap_.freeManual(s, &memstats.stacks_inuse)
s = next
}