diff options
author | John <50754967+j-bm@users.noreply.github.com> | 2020-05-16 12:56:52 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-16 21:56:52 +0200 |
commit | 40ac19572a86b5bfa7b57cf0482ae3a30432176a (patch) | |
tree | 0e24853e8d0ee67f0123615517ca653645a81b48 /lib | |
parent | 7f377da1d2191bdf73e4ce8961fb982b2da253cb (diff) | |
download | Nim-40ac19572a86b5bfa7b57cf0482ae3a30432176a.tar.gz |
add OpenBSD MAP_STACK for coroutines (#14353)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/system/osalloc.nim | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/system/osalloc.nim b/lib/system/osalloc.nim index aa86ee379..32d3b166d 100644 --- a/lib/system/osalloc.nim +++ b/lib/system/osalloc.nim @@ -196,7 +196,13 @@ elif defined(posix) and not defined(StandaloneHeapSize): PROT_READ = 1 # page can be read PROT_WRITE = 2 # page can be written - when defined(macosx) or defined(bsd): + when defined(netbsd) or defined(openbsd): + # OpenBSD security for setjmp/longjmp coroutines + var MAP_STACK {.importc: "MAP_STACK", header: "<sys/mman.h>".}: cint + else: + const MAP_STACK = 0 # avoid sideeffects + + when defined(macosx) or defined(freebsd): const MAP_ANONYMOUS = 0x1000 const MAP_PRIVATE = 0x02 # Changes are private elif defined(solaris): @@ -210,7 +216,7 @@ elif defined(posix) and not defined(StandaloneHeapSize): elif defined(haiku): const MAP_ANONYMOUS = 0x08 const MAP_PRIVATE = 0x02 - else: + else: # posix including netbsd or openbsd var MAP_ANONYMOUS {.importc: "MAP_ANONYMOUS", header: "<sys/mman.h>".}: cint MAP_PRIVATE {.importc: "MAP_PRIVATE", header: "<sys/mman.h>".}: cint @@ -222,13 +228,13 @@ elif defined(posix) and not defined(StandaloneHeapSize): proc osAllocPages(size: int): pointer {.inline.} = result = mmap(nil, cast[csize_t](size), PROT_READ or PROT_WRITE, - MAP_PRIVATE or MAP_ANONYMOUS, -1, 0) + MAP_ANONYMOUS or MAP_PRIVATE or MAP_STACK, -1, 0) if result == nil or result == cast[pointer](-1): raiseOutOfMem() proc osTryAllocPages(size: int): pointer {.inline.} = result = mmap(nil, cast[csize_t](size), PROT_READ or PROT_WRITE, - MAP_PRIVATE or MAP_ANONYMOUS, -1, 0) + MAP_ANONYMOUS or MAP_PRIVATE or MAP_STACK, -1, 0) if result == cast[pointer](-1): result = nil proc osDeallocPages(p: pointer, size: int) {.inline.} = |