| author | |
| committer | |
| log | fd5a5db400995d80015448d19e92daaca71a7f72 |
| tree | 625235a0cd98cefd5958ca687ba0d956b6e54ce9 |
| parent | 9ae66b4c67a66c3dcf8ce6107eca7a4744edd66d |
2 files changed, 29 insertions(+), 1 deletions(-)
std/mem.zig+23-1| ... | ... | @@ -86,12 +86,34 @@ pub const IncrementingAllocator = struct { |
| 86 | 86 | .end_index = 0, |
| 87 | 87 | }; |
| 88 | 88 | }, |
| 89 | Os.windows => { | |
| 90 | const heap_handle = os.windows.GetProcessHeap(); | |
| 91 | const ptr = os.windows.HeapAlloc(heap_handle, 0, capacity); | |
| 92 | return IncrementingAllocator { | |
| 93 | .allocator = Allocator { | |
| 94 | .allocFn = alloc, | |
| 95 | .reallocFn = realloc, | |
| 96 | .freeFn = free, | |
| 97 | }, | |
| 98 | .bytes = @ptrCast(&u8, ptr)[0..capacity], | |
| 99 | .end_index = 0, | |
| 100 | }; | |
| 101 | }, | |
| 89 | 102 | else => @compileError("Unsupported OS"), |
| 90 | 103 | } |
| 91 | 104 | } |
| 92 | 105 | |
| 93 | 106 | fn deinit(self: &IncrementingAllocator) { |
| 94 | _ = os.posix.munmap(self.bytes.ptr, self.bytes.len); | |
| 107 | switch (builtin.os) { | |
| 108 | Os.linux, Os.darwin, Os.macosx, Os.ios => { | |
| 109 | _ = os.posix.munmap(self.bytes.ptr, self.bytes.len); | |
| 110 | }, | |
| 111 | Os.windows => { | |
| 112 | const heap_handle = os.windows.GetProcessHeap(); | |
| 113 | _ = os.windows.HeapFree(heap_handle, 0, @ptrCast(os.windows.LPVOID, self.bytes.ptr)); | |
| 114 | }, | |
| 115 | else => @compileError("Unsupported OS"), | |
| 116 | } | |
| 95 | 117 | } |
| 96 | 118 | |
| 97 | 119 | fn reset(self: &IncrementingAllocator) { |
std/os/windows/index.zig+6| ... | ... | @@ -39,6 +39,11 @@ pub extern "kernel32" stdcallcc fn WriteFile(in_hFile: HANDLE, in_lpBuffer: &con |
| 39 | 39 | |
| 40 | 40 | pub extern "kernel32" stdcallcc fn Sleep(dwMilliseconds: DWORD); |
| 41 | 41 | |
| 42 | pub extern "kernel32" stdcallcc fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T) -> LPVOID; | |
| 43 | ||
| 44 | pub extern "kernel32" stdcallcc fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID) -> BOOL; | |
| 45 | ||
| 46 | pub extern "kernel32" stdcallcc fn GetProcessHeap() -> HANDLE; | |
| 42 | 47 | |
| 43 | 48 | pub extern "user32" stdcallcc fn MessageBoxA(hWnd: ?HANDLE, lpText: ?LPCTSTR, lpCaption: ?LPCTSTR, uType: UINT) -> c_int; |
| 44 | 49 | |
| ... | ... | @@ -50,6 +55,7 @@ pub const LPWSTR = &WCHAR; |
| 50 | 55 | pub const LPSTR = &CHAR; |
| 51 | 56 | pub const CHAR = u8; |
| 52 | 57 | pub const PWSTR = &WCHAR; |
| 58 | pub const SIZE_T = usize; | |
| 53 | 59 | |
| 54 | 60 | pub const BOOL = bool; |
| 55 | 61 | pub const BYTE = u8; |