mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 23:58:50 +00:00
Improve mem/virtual handling of out of memory on Windows
This commit is contained in:
@@ -63,6 +63,7 @@ memory_block_alloc :: proc(committed, reserved: uint, flags: Memory_Block_Flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
page_size := DEFAULT_PAGE_SIZE
|
page_size := DEFAULT_PAGE_SIZE
|
||||||
|
assert(mem.is_power_of_two(uintptr(page_size)))
|
||||||
committed := committed
|
committed := committed
|
||||||
committed = clamp(committed, 0, reserved)
|
committed = clamp(committed, 0, reserved)
|
||||||
|
|
||||||
@@ -82,8 +83,7 @@ memory_block_alloc :: proc(committed, reserved: uint, flags: Memory_Block_Flags)
|
|||||||
pmblock := platform_memory_alloc(0, total_size) or_return
|
pmblock := platform_memory_alloc(0, total_size) or_return
|
||||||
|
|
||||||
pmblock.block.base = ([^]byte)(uintptr(pmblock) + base_offset)
|
pmblock.block.base = ([^]byte)(uintptr(pmblock) + base_offset)
|
||||||
commit_err := platform_memory_commit(pmblock, uint(base_offset) + committed)
|
platform_memory_commit(pmblock, uint(base_offset) + committed) or_return
|
||||||
assert(commit_err == nil)
|
|
||||||
|
|
||||||
// Should be zeroed
|
// Should be zeroed
|
||||||
assert(pmblock.block.used == 0)
|
assert(pmblock.block.used == 0)
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ PAGE_TARGETS_INVALID :: 0x40000000
|
|||||||
PAGE_TARGETS_NO_UPDATE :: 0x40000000
|
PAGE_TARGETS_NO_UPDATE :: 0x40000000
|
||||||
|
|
||||||
ERROR_INVALID_ADDRESS :: 487
|
ERROR_INVALID_ADDRESS :: 487
|
||||||
|
ERROR_COMMITMENT_LIMIT :: 1455
|
||||||
|
|
||||||
@(default_calling_convention="stdcall")
|
@(default_calling_convention="stdcall")
|
||||||
foreign Kernel32 {
|
foreign Kernel32 {
|
||||||
@@ -76,12 +77,13 @@ _commit :: proc "contextless" (data: rawptr, size: uint) -> Allocator_Error {
|
|||||||
result := VirtualAlloc(data, size, MEM_COMMIT, PAGE_READWRITE)
|
result := VirtualAlloc(data, size, MEM_COMMIT, PAGE_READWRITE)
|
||||||
if result == nil {
|
if result == nil {
|
||||||
switch err := GetLastError(); err {
|
switch err := GetLastError(); err {
|
||||||
case ERROR_INVALID_ADDRESS:
|
case 0:
|
||||||
|
return .Invalid_Argument
|
||||||
|
case ERROR_INVALID_ADDRESS, ERROR_COMMITMENT_LIMIT:
|
||||||
return .Out_Of_Memory
|
return .Out_Of_Memory
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(bill): Handle errors correctly
|
return .Out_Of_Memory
|
||||||
return .Invalid_Argument
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user