mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-31 11:50:07 +00:00
mem/virtual: specify max protection on mmap call in NetBSD and FreeBSD
This commit is contained in:
@@ -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))
|
||||
}
|
||||
Reference in New Issue
Block a user