Browse Source

Correct core:os/os2 mock-up

gingerBill 4 years ago
parent
commit
6667b78c12
2 changed files with 13 additions and 13 deletions
  1. 2 2
      core/os/os2/heap.odin
  2. 11 11
      core/os/os2/heap_windows.odin

+ 2 - 2
core/os/os2/heap.odin

@@ -12,8 +12,8 @@ heap_allocator :: proc() -> runtime.Allocator {
 
 
 heap_allocator_proc :: proc(allocator_data: rawptr, mode: runtime.Allocator_Mode,
 heap_allocator_proc :: proc(allocator_data: rawptr, mode: runtime.Allocator_Mode,
                             size, alignment: int,
                             size, alignment: int,
-                            old_memory: rawptr, old_size: int, flags: u64 = 0, loc := #caller_location) -> rawptr {
-	return _heap_allocator_proc(allocator_data, mode, size, alignment, old_memory, old_size, flags, loc);
+                            old_memory: rawptr, old_size: int, loc := #caller_location) -> ([]byte, runtime.Allocator_Error) {
+	return _heap_allocator_proc(allocator_data, mode, size, alignment, old_memory, old_size, loc);
 }
 }
 
 
 
 

+ 11 - 11
core/os/os2/heap_windows.odin

@@ -27,9 +27,9 @@ heap_free :: proc(ptr: rawptr) {
 	win32.HeapFree(win32.GetProcessHeap(), 0, ptr);
 	win32.HeapFree(win32.GetProcessHeap(), 0, ptr);
 }
 }
 
 
-_heap_allocator_proc :: proc(allocator_data: rawptr, mode: runtime.Allocator_Mode,
+_heap_allocator_proc :: proc(allocator_data: rawptr, mode: mem.Allocator_Mode,
                             size, alignment: int,
                             size, alignment: int,
-                            old_memory: rawptr, old_size: int, flags: u64 = 0, loc := #caller_location) -> rawptr {
+                            old_memory: rawptr, old_size: int, loc := #caller_location) -> ([]byte, mem.Allocator_Error) {
 	//
 	//
 	// NOTE(tetra, 2020-01-14): The heap doesn't respect alignment.
 	// NOTE(tetra, 2020-01-14): The heap doesn't respect alignment.
 	// Instead, we overallocate by `alignment + size_of(rawptr) - 1`, and insert
 	// Instead, we overallocate by `alignment + size_of(rawptr) - 1`, and insert
@@ -37,7 +37,7 @@ _heap_allocator_proc :: proc(allocator_data: rawptr, mode: runtime.Allocator_Mod
 	// the pointer we return to the user.
 	// the pointer we return to the user.
 	//
 	//
 
 
-	aligned_alloc :: proc(size, alignment: int, old_ptr: rawptr = nil) -> rawptr {
+	aligned_alloc :: proc(size, alignment: int, old_ptr: rawptr = nil) -> ([]byte, mem.Allocator_Error) {
 		a := max(alignment, align_of(rawptr));
 		a := max(alignment, align_of(rawptr));
 		space := size + a - 1;
 		space := size + a - 1;
 
 
@@ -54,13 +54,13 @@ _heap_allocator_proc :: proc(allocator_data: rawptr, mode: runtime.Allocator_Mod
 		aligned_ptr := (ptr - 1 + uintptr(a)) & -uintptr(a);
 		aligned_ptr := (ptr - 1 + uintptr(a)) & -uintptr(a);
 		diff := int(aligned_ptr - ptr);
 		diff := int(aligned_ptr - ptr);
 		if (size + diff) > space {
 		if (size + diff) > space {
-			return nil;
+			return nil, .Out_Of_Memory;
 		}
 		}
 
 
 		aligned_mem = rawptr(aligned_ptr);
 		aligned_mem = rawptr(aligned_ptr);
 		mem.ptr_offset((^rawptr)(aligned_mem), -1)^ = allocated_mem;
 		mem.ptr_offset((^rawptr)(aligned_mem), -1)^ = allocated_mem;
 
 
-		return aligned_mem;
+		return mem.byte_slice(aligned_mem, size), nil;
 	}
 	}
 
 
 	aligned_free :: proc(p: rawptr) {
 	aligned_free :: proc(p: rawptr) {
@@ -69,9 +69,9 @@ _heap_allocator_proc :: proc(allocator_data: rawptr, mode: runtime.Allocator_Mod
 		}
 		}
 	}
 	}
 
 
-	aligned_resize :: proc(p: rawptr, old_size: int, new_size: int, new_alignment: int) -> rawptr {
+	aligned_resize :: proc(p: rawptr, old_size: int, new_size: int, new_alignment: int) -> ([]byte, mem.Allocator_Error) {
 		if p == nil {
 		if p == nil {
-			return nil;
+			return nil, nil;
 		}
 		}
 		return aligned_alloc(new_size, new_alignment, p);
 		return aligned_alloc(new_size, new_alignment, p);
 	}
 	}
@@ -93,15 +93,15 @@ _heap_allocator_proc :: proc(allocator_data: rawptr, mode: runtime.Allocator_Mod
 		return aligned_resize(old_memory, old_size, size, alignment);
 		return aligned_resize(old_memory, old_size, size, alignment);
 
 
 	case .Query_Features:
 	case .Query_Features:
-		set := (^runtime.Allocator_Mode_Set)(old_memory);
+		set := (^mem.Allocator_Mode_Set)(old_memory);
 		if set != nil {
 		if set != nil {
 			set^ = {.Alloc, .Free, .Resize, .Query_Features};
 			set^ = {.Alloc, .Free, .Resize, .Query_Features};
 		}
 		}
-		return set;
+		return nil, nil;
 
 
 	case .Query_Info:
 	case .Query_Info:
-		return nil;
+		return nil, nil;
 	}
 	}
 
 
-	return nil;
+	return nil, nil;
 }
 }