zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 349349fa01f77fe3bf2b57dc821f889e2e869004 (tree)
parent 216badef0bd90c6353bf32bd927e2c6d36b3ebf6
Author: Jakub Konka <kubkon@jakubkonka.com>
Date:   Thu, 30 Mar 2023 20:54:46 +0200

std: simplify VirtualProtectEx and fix ntdll signature

Diffstat:
Mlib/std/os/windows.zig | 7++++---
Mlib/std/os/windows/ntdll.zig | 2+-
2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig @@ -1514,7 +1514,8 @@ pub fn VirtualProtect(lpAddress: ?LPVOID, dwSize: SIZE_T, flNewProtect: DWORD, l } } -pub fn VirtualProtectEx(handle: HANDLE, addr: ?LPVOID, size: usize, new_prot: DWORD, old_prot: ?*DWORD) VirtualProtectError!void { +pub fn VirtualProtectEx(handle: HANDLE, addr: ?LPVOID, size: SIZE_T, new_prot: DWORD) VirtualProtectError!DWORD { + var old_prot: DWORD = undefined; var out_addr = addr; var out_size = size; switch (ntdll.NtProtectVirtualMemory( @@ -1522,9 +1523,9 @@ pub fn VirtualProtectEx(handle: HANDLE, addr: ?LPVOID, size: usize, new_prot: DW &out_addr, &out_size, new_prot, - old_prot, + &old_prot, )) { - .SUCCESS => {}, + .SUCCESS => return old_prot, .INVALID_ADDRESS => return error.InvalidAddress, // TODO: map errors else => |rc| return std.os.windows.unexpectedStatus(rc), diff --git a/lib/std/os/windows/ntdll.zig b/lib/std/os/windows/ntdll.zig @@ -283,5 +283,5 @@ pub extern "ntdll" fn NtProtectVirtualMemory( BaseAddress: *?PVOID, NumberOfBytesToProtect: *SIZE_T, NewAccessProtection: ULONG, - OldAccessProtection: ?*ULONG, + OldAccessProtection: *ULONG, ) callconv(WINAPI) NTSTATUS;