mem/virtual: specify max protection on mmap call in NetBSD and FreeBSD

This commit is contained in:
Laytan Laats
2025-02-18 18:33:19 +01:00
parent ae0f69fbe2
commit cae3f13d9f
6 changed files with 99 additions and 24 deletions
+20
View File
@@ -0,0 +1,20 @@
package mem_virtual
import "core:sys/posix"
_reserve :: proc "contextless" (size: uint) -> (data: []byte, err: Allocator_Error) {
result := posix.mmap(nil, size, {}, {.ANONYMOUS, .PRIVATE})
if result == posix.MAP_FAILED {
assert_contextless(posix.errno() == .ENOMEM)
return nil, .Out_Of_Memory
}
return ([^]byte)(uintptr(result))[:size], nil
}
_decommit :: proc "contextless" (data: rawptr, size: uint) {
MADV_FREE :: 6
posix.mprotect(data, size, {})
posix.posix_madvise(data, size, transmute(posix.MAdvice)i32(MADV_FREE))
}