mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-06 06:38:20 +00:00
added get_page_size() to core:mem/virtual
This commit is contained in:
@@ -45,6 +45,17 @@ release :: proc "contextless" (data: rawptr, size: uint) {
|
||||
_release(data, size)
|
||||
}
|
||||
|
||||
get_page_size :: proc() -> int {
|
||||
// NOTE(tetra): The page size never changes, so why do anything complicated
|
||||
// if we don't have to.
|
||||
@static page_size := -1
|
||||
if page_size != -1 {
|
||||
return page_size
|
||||
}
|
||||
page_size = _get_page_size()
|
||||
return page_size
|
||||
}
|
||||
|
||||
Protect_Flag :: enum u32 {
|
||||
Read,
|
||||
Write,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
package mem_virtual
|
||||
|
||||
import "core:sys/linux"
|
||||
import "core:sys/posix"
|
||||
|
||||
_reserve :: proc "contextless" (size: uint) -> (data: []byte, err: Allocator_Error) {
|
||||
addr, errno := linux.mmap(0, size, {}, {.PRIVATE, .ANONYMOUS})
|
||||
@@ -33,6 +34,10 @@ _release :: proc "contextless" (data: rawptr, size: uint) {
|
||||
_ = linux.munmap(data, size)
|
||||
}
|
||||
|
||||
_get_page_size :: proc() -> int {
|
||||
return int(posix.sysconf(._PAGE_SIZE))
|
||||
}
|
||||
|
||||
_protect :: proc "contextless" (data: rawptr, size: uint, flags: Protect_Flags) -> bool {
|
||||
pflags: linux.Mem_Protection
|
||||
pflags = {}
|
||||
|
||||
@@ -21,6 +21,10 @@ _decommit :: proc "contextless" (data: rawptr, size: uint) {
|
||||
_release :: proc "contextless" (data: rawptr, size: uint) {
|
||||
}
|
||||
|
||||
_get_page_size :: proc() -> int {
|
||||
return 0
|
||||
}
|
||||
|
||||
_protect :: proc "contextless" (data: rawptr, size: uint, flags: Protect_Flags) -> bool {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -20,6 +20,10 @@ _release :: proc "contextless" (data: rawptr, size: uint) {
|
||||
posix.munmap(data, size)
|
||||
}
|
||||
|
||||
_get_page_size :: proc() -> int {
|
||||
return int(posix.sysconf(._PAGE_SIZE))
|
||||
}
|
||||
|
||||
_protect :: proc "contextless" (data: rawptr, size: uint, flags: Protect_Flags) -> bool {
|
||||
#assert(i32(posix.Prot_Flag_Bits.READ) == i32(Protect_Flag.Read))
|
||||
#assert(i32(posix.Prot_Flag_Bits.WRITE) == i32(Protect_Flag.Write))
|
||||
|
||||
@@ -123,6 +123,13 @@ _release :: proc "contextless" (data: rawptr, size: uint) {
|
||||
VirtualFree(data, 0, MEM_RELEASE)
|
||||
}
|
||||
|
||||
_get_page_size :: proc() -> int {
|
||||
info: SYSTEM_INFO
|
||||
GetSystemInfo(&info)
|
||||
|
||||
return int(info.dwPageSize)
|
||||
}
|
||||
|
||||
@(no_sanitize_address)
|
||||
_protect :: proc "contextless" (data: rawptr, size: uint, flags: Protect_Flags) -> bool {
|
||||
pflags: u32
|
||||
|
||||
Reference in New Issue
Block a user