| author | |
| committer | |
| log | 17ecc77fc46727f3979abe904ec00b79f036270e |
| tree | de4aafb5064202ed8bf6b0836d3f696e3615b51d |
| parent | 9082b004b68b0cc0afe6e24b9277b900362c560d |
5 files changed, 3 insertions(+), 154 deletions(-)
lib/std/heap.zig+1-1| ... | @@ -46,7 +46,7 @@ pub var next_mmap_addr_hint: ?[*]align(page_size_min) u8 = null; | ... | @@ -46,7 +46,7 @@ pub var next_mmap_addr_hint: ?[*]align(page_size_min) u8 = null; |
| 46 | 46 | ||
| 47 | /// comptime-known minimum page size of the target. | 47 | /// comptime-known minimum page size of the target. |
| 48 | /// | 48 | /// |
| 49 | /// All pointers from `mmap` or `VirtualAlloc` are aligned to at least | 49 | /// All pointers from `mmap` or `NtAllocateVirtualMemory` are aligned to at least |
| 50 | /// `page_size_min`, but their actual alignment may be bigger. | 50 | /// `page_size_min`, but their actual alignment may be bigger. |
| 51 | /// | 51 | /// |
| 52 | /// This value can be overridden via `std.options.page_size_min`. | 52 | /// This value can be overridden via `std.options.page_size_min`. |
lib/std/os.zig-15| ... | @@ -56,21 +56,6 @@ pub var argv: [][*:0]u8 = if (builtin.link_libc) undefined else switch (native_o | ... | @@ -56,21 +56,6 @@ pub var argv: [][*:0]u8 = if (builtin.link_libc) undefined else switch (native_o |
| 56 | else => undefined, | 56 | else => undefined, |
| 57 | }; | 57 | }; |
| 58 | 58 | ||
| 59 | /// Call from Windows-specific code if you already have a WTF-16LE encoded, null terminated string. | ||
| 60 | /// Otherwise use `access`. | ||
| 61 | pub fn accessW(path: [*:0]const u16) windows.GetFileAttributesError!void { | ||
| 62 | const ret = try windows.GetFileAttributesW(path); | ||
| 63 | if (ret != windows.INVALID_FILE_ATTRIBUTES) { | ||
| 64 | return; | ||
| 65 | } | ||
| 66 | switch (windows.GetLastError()) { | ||
| 67 | .FILE_NOT_FOUND => return error.FileNotFound, | ||
| 68 | .PATH_NOT_FOUND => return error.FileNotFound, | ||
| 69 | .ACCESS_DENIED => return error.AccessDenied, | ||
| 70 | else => |err| return windows.unexpectedError(err), | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | pub fn isGetFdPathSupportedOnTarget(os: std.Target.Os) bool { | 59 | pub fn isGetFdPathSupportedOnTarget(os: std.Target.Os) bool { |
| 75 | return switch (os.tag) { | 60 | return switch (os.tag) { |
| 76 | .windows, | 61 | .windows, |
lib/std/os/windows.zig+1-81| ... | @@ -306,22 +306,6 @@ pub fn CreatePipe(rd: *HANDLE, wr: *HANDLE, sattr: *const SECURITY_ATTRIBUTES) C | ... | @@ -306,22 +306,6 @@ pub fn CreatePipe(rd: *HANDLE, wr: *HANDLE, sattr: *const SECURITY_ATTRIBUTES) C |
| 306 | wr.* = write; | 306 | wr.* = write; |
| 307 | } | 307 | } |
| 308 | 308 | ||
| 309 | pub fn CreateEventEx(attributes: ?*SECURITY_ATTRIBUTES, name: []const u8, flags: DWORD, desired_access: DWORD) !HANDLE { | ||
| 310 | const nameW = try sliceToPrefixedFileW(null, name); | ||
| 311 | return CreateEventExW(attributes, nameW.span().ptr, flags, desired_access); | ||
| 312 | } | ||
| 313 | |||
| 314 | pub fn CreateEventExW(attributes: ?*SECURITY_ATTRIBUTES, nameW: ?LPCWSTR, flags: DWORD, desired_access: DWORD) !HANDLE { | ||
| 315 | const handle = kernel32.CreateEventExW(attributes, nameW, flags, desired_access); | ||
| 316 | if (handle) |h| { | ||
| 317 | return h; | ||
| 318 | } else { | ||
| 319 | switch (GetLastError()) { | ||
| 320 | else => |err| return unexpectedError(err), | ||
| 321 | } | ||
| 322 | } | ||
| 323 | } | ||
| 324 | |||
| 325 | pub const DeviceIoControlError = error{ | 309 | pub const DeviceIoControlError = error{ |
| 326 | AccessDenied, | 310 | AccessDenied, |
| 327 | /// The volume does not contain a recognized file system. File system | 311 | /// The volume does not contain a recognized file system. File system |
| ... | @@ -598,10 +582,6 @@ pub fn CloseHandle(hObject: HANDLE) void { | ... | @@ -598,10 +582,6 @@ pub fn CloseHandle(hObject: HANDLE) void { |
| 598 | assert(ntdll.NtClose(hObject) == .SUCCESS); | 582 | assert(ntdll.NtClose(hObject) == .SUCCESS); |
| 599 | } | 583 | } |
| 600 | 584 | ||
| 601 | pub fn FindClose(hFindFile: HANDLE) void { | ||
| 602 | assert(kernel32.FindClose(hFindFile) != 0); | ||
| 603 | } | ||
| 604 | |||
| 605 | pub const ReadFileError = error{ | 585 | pub const ReadFileError = error{ |
| 606 | BrokenPipe, | 586 | BrokenPipe, |
| 607 | /// The specified network name is no longer available. | 587 | /// The specified network name is no longer available. |
| ... | @@ -1515,30 +1495,6 @@ pub fn GetFileSizeEx(hFile: HANDLE) GetFileSizeError!u64 { | ... | @@ -1515,30 +1495,6 @@ pub fn GetFileSizeEx(hFile: HANDLE) GetFileSizeError!u64 { |
| 1515 | return @as(u64, @bitCast(file_size)); | 1495 | return @as(u64, @bitCast(file_size)); |
| 1516 | } | 1496 | } |
| 1517 | 1497 | ||
| 1518 | pub const GetFileAttributesError = error{ | ||
| 1519 | FileNotFound, | ||
| 1520 | AccessDenied, | ||
| 1521 | Unexpected, | ||
| 1522 | }; | ||
| 1523 | |||
| 1524 | pub fn GetFileAttributes(filename: []const u8) (GetFileAttributesError || Wtf8ToPrefixedFileWError)!DWORD { | ||
| 1525 | const filename_w = try sliceToPrefixedFileW(null, filename); | ||
| 1526 | return GetFileAttributesW(filename_w.span().ptr); | ||
| 1527 | } | ||
| 1528 | |||
| 1529 | pub fn GetFileAttributesW(lpFileName: [*:0]const u16) GetFileAttributesError!DWORD { | ||
| 1530 | const rc = kernel32.GetFileAttributesW(lpFileName); | ||
| 1531 | if (rc == INVALID_FILE_ATTRIBUTES) { | ||
| 1532 | switch (GetLastError()) { | ||
| 1533 | .FILE_NOT_FOUND => return error.FileNotFound, | ||
| 1534 | .PATH_NOT_FOUND => return error.FileNotFound, | ||
| 1535 | .ACCESS_DENIED => return error.AccessDenied, | ||
| 1536 | else => |err| return unexpectedError(err), | ||
| 1537 | } | ||
| 1538 | } | ||
| 1539 | return rc; | ||
| 1540 | } | ||
| 1541 | |||
| 1542 | pub fn getpeername(s: ws2_32.SOCKET, name: *ws2_32.sockaddr, namelen: *ws2_32.socklen_t) i32 { | 1498 | pub fn getpeername(s: ws2_32.SOCKET, name: *ws2_32.sockaddr, namelen: *ws2_32.socklen_t) i32 { |
| 1543 | return ws2_32.getpeername(s, name, @as(*i32, @ptrCast(namelen))); | 1499 | return ws2_32.getpeername(s, name, @as(*i32, @ptrCast(namelen))); |
| 1544 | } | 1500 | } |
| ... | @@ -1657,6 +1613,7 @@ pub const NtFreeVirtualMemoryError = error{ | ... | @@ -1657,6 +1613,7 @@ pub const NtFreeVirtualMemoryError = error{ |
| 1657 | }; | 1613 | }; |
| 1658 | 1614 | ||
| 1659 | pub fn NtFreeVirtualMemory(hProcess: HANDLE, addr: ?*PVOID, size: *SIZE_T, free_type: ULONG) NtFreeVirtualMemoryError!void { | 1615 | pub fn NtFreeVirtualMemory(hProcess: HANDLE, addr: ?*PVOID, size: *SIZE_T, free_type: ULONG) NtFreeVirtualMemoryError!void { |
| 1616 | // TODO: If the return value is .INVALID_PAGE_PROTECTION, call RtlFlushSecureMemoryCache and try again. | ||
| 1660 | return switch (ntdll.NtFreeVirtualMemory(hProcess, addr, size, free_type)) { | 1617 | return switch (ntdll.NtFreeVirtualMemory(hProcess, addr, size, free_type)) { |
| 1661 | .SUCCESS => return, | 1618 | .SUCCESS => return, |
| 1662 | .ACCESS_DENIED => NtFreeVirtualMemoryError.AccessDenied, | 1619 | .ACCESS_DENIED => NtFreeVirtualMemoryError.AccessDenied, |
| ... | @@ -1665,20 +1622,6 @@ pub fn NtFreeVirtualMemory(hProcess: HANDLE, addr: ?*PVOID, size: *SIZE_T, free_ | ... | @@ -1665,20 +1622,6 @@ pub fn NtFreeVirtualMemory(hProcess: HANDLE, addr: ?*PVOID, size: *SIZE_T, free_ |
| 1665 | }; | 1622 | }; |
| 1666 | } | 1623 | } |
| 1667 | 1624 | ||
| 1668 | pub const VirtualAllocError = error{Unexpected}; | ||
| 1669 | |||
| 1670 | pub fn VirtualAlloc(addr: ?LPVOID, size: usize, alloc_type: DWORD, flProtect: DWORD) VirtualAllocError!LPVOID { | ||
| 1671 | return kernel32.VirtualAlloc(addr, size, alloc_type, flProtect) orelse { | ||
| 1672 | switch (GetLastError()) { | ||
| 1673 | else => |err| return unexpectedError(err), | ||
| 1674 | } | ||
| 1675 | }; | ||
| 1676 | } | ||
| 1677 | |||
| 1678 | pub fn VirtualFree(lpAddress: ?LPVOID, dwSize: usize, dwFreeType: DWORD) void { | ||
| 1679 | assert(kernel32.VirtualFree(lpAddress, dwSize, dwFreeType) != 0); | ||
| 1680 | } | ||
| 1681 | |||
| 1682 | pub const VirtualProtectError = error{ | 1625 | pub const VirtualProtectError = error{ |
| 1683 | InvalidAddress, | 1626 | InvalidAddress, |
| 1684 | Unexpected, | 1627 | Unexpected, |
| ... | @@ -1713,19 +1656,6 @@ pub fn VirtualProtectEx(handle: HANDLE, addr: ?LPVOID, size: SIZE_T, new_prot: D | ... | @@ -1713,19 +1656,6 @@ pub fn VirtualProtectEx(handle: HANDLE, addr: ?LPVOID, size: SIZE_T, new_prot: D |
| 1713 | } | 1656 | } |
| 1714 | } | 1657 | } |
| 1715 | 1658 | ||
| 1716 | pub const VirtualQueryError = error{Unexpected}; | ||
| 1717 | |||
| 1718 | pub fn VirtualQuery(lpAddress: ?LPVOID, lpBuffer: PMEMORY_BASIC_INFORMATION, dwLength: SIZE_T) VirtualQueryError!SIZE_T { | ||
| 1719 | const rc = kernel32.VirtualQuery(lpAddress, lpBuffer, dwLength); | ||
| 1720 | if (rc == 0) { | ||
| 1721 | switch (GetLastError()) { | ||
| 1722 | else => |err| return unexpectedError(err), | ||
| 1723 | } | ||
| 1724 | } | ||
| 1725 | |||
| 1726 | return rc; | ||
| 1727 | } | ||
| 1728 | |||
| 1729 | pub const SetConsoleTextAttributeError = error{Unexpected}; | 1659 | pub const SetConsoleTextAttributeError = error{Unexpected}; |
| 1730 | 1660 | ||
| 1731 | pub fn SetConsoleTextAttribute(hConsoleOutput: HANDLE, wAttributes: WORD) SetConsoleTextAttributeError!void { | 1661 | pub fn SetConsoleTextAttribute(hConsoleOutput: HANDLE, wAttributes: WORD) SetConsoleTextAttributeError!void { |
| ... | @@ -2628,16 +2558,6 @@ test ntToWin32Namespace { | ... | @@ -2628,16 +2558,6 @@ test ntToWin32Namespace { |
| 2628 | try std.testing.expectError(error.NameTooLong, ntToWin32Namespace(L("\\??\\C:\\test"), &too_small_buf)); | 2558 | try std.testing.expectError(error.NameTooLong, ntToWin32Namespace(L("\\??\\C:\\test"), &too_small_buf)); |
| 2629 | } | 2559 | } |
| 2630 | 2560 | ||
| 2631 | fn getFullPathNameW(path: [*:0]const u16, out: []u16) !usize { | ||
| 2632 | const result = kernel32.GetFullPathNameW(path, @as(u32, @intCast(out.len)), out.ptr, null); | ||
| 2633 | if (result == 0) { | ||
| 2634 | switch (GetLastError()) { | ||
| 2635 | else => |err| return unexpectedError(err), | ||
| 2636 | } | ||
| 2637 | } | ||
| 2638 | return result; | ||
| 2639 | } | ||
| 2640 | |||
| 2641 | inline fn MAKELANGID(p: c_ushort, s: c_ushort) LANGID { | 2561 | inline fn MAKELANGID(p: c_ushort, s: c_ushort) LANGID { |
| 2642 | return (s << 10) | p; | 2562 | return (s << 10) | p; |
| 2643 | } | 2563 | } |
lib/std/os/windows/kernel32.zig-56| ... | @@ -86,23 +86,6 @@ pub extern "kernel32" fn CreateNamedPipeW( | ... | @@ -86,23 +86,6 @@ pub extern "kernel32" fn CreateNamedPipeW( |
| 86 | lpSecurityAttributes: ?*const SECURITY_ATTRIBUTES, | 86 | lpSecurityAttributes: ?*const SECURITY_ATTRIBUTES, |
| 87 | ) callconv(.winapi) HANDLE; | 87 | ) callconv(.winapi) HANDLE; |
| 88 | 88 | ||
| 89 | pub extern "kernel32" fn FindFirstFileW( | ||
| 90 | lpFileName: LPCWSTR, | ||
| 91 | lpFindFileData: *WIN32_FIND_DATAW, | ||
| 92 | ) callconv(.winapi) HANDLE; | ||
| 93 | |||
| 94 | pub extern "kernel32" fn FindClose( | ||
| 95 | hFindFile: HANDLE, | ||
| 96 | ) callconv(.winapi) BOOL; | ||
| 97 | |||
| 98 | // TODO: Wrapper around RtlGetFullPathName_UEx | ||
| 99 | pub extern "kernel32" fn GetFullPathNameW( | ||
| 100 | lpFileName: LPCWSTR, | ||
| 101 | nBufferLength: DWORD, | ||
| 102 | lpBuffer: LPWSTR, | ||
| 103 | lpFilePart: ?*?LPWSTR, | ||
| 104 | ) callconv(.winapi) DWORD; | ||
| 105 | |||
| 106 | // TODO: Matches `STD_*_HANDLE` to peb().ProcessParameters.Standard* | 89 | // TODO: Matches `STD_*_HANDLE` to peb().ProcessParameters.Standard* |
| 107 | pub extern "kernel32" fn GetStdHandle( | 90 | pub extern "kernel32" fn GetStdHandle( |
| 108 | nStdHandle: DWORD, | 91 | nStdHandle: DWORD, |
| ... | @@ -162,11 +145,6 @@ pub extern "kernel32" fn GetCurrentDirectoryW( | ... | @@ -162,11 +145,6 @@ pub extern "kernel32" fn GetCurrentDirectoryW( |
| 162 | lpBuffer: ?[*]WCHAR, | 145 | lpBuffer: ?[*]WCHAR, |
| 163 | ) callconv(.winapi) DWORD; | 146 | ) callconv(.winapi) DWORD; |
| 164 | 147 | ||
| 165 | // TODO: RtlDosPathNameToNtPathNameU_WithStatus + NtQueryAttributesFile. | ||
| 166 | pub extern "kernel32" fn GetFileAttributesW( | ||
| 167 | lpFileName: LPCWSTR, | ||
| 168 | ) callconv(.winapi) DWORD; | ||
| 169 | |||
| 170 | pub extern "kernel32" fn ReadFile( | 148 | pub extern "kernel32" fn ReadFile( |
| 171 | hFile: HANDLE, | 149 | hFile: HANDLE, |
| 172 | lpBuffer: LPVOID, | 150 | lpBuffer: LPVOID, |
| ... | @@ -182,14 +160,6 @@ pub extern "kernel32" fn GetSystemDirectoryW( | ... | @@ -182,14 +160,6 @@ pub extern "kernel32" fn GetSystemDirectoryW( |
| 182 | 160 | ||
| 183 | // I/O - Kernel Objects | 161 | // I/O - Kernel Objects |
| 184 | 162 | ||
| 185 | // TODO: Wrapper around NtCreateEvent. | ||
| 186 | pub extern "kernel32" fn CreateEventExW( | ||
| 187 | lpEventAttributes: ?*SECURITY_ATTRIBUTES, | ||
| 188 | lpName: ?LPCWSTR, | ||
| 189 | dwFlags: DWORD, | ||
| 190 | dwDesiredAccess: DWORD, | ||
| 191 | ) callconv(.winapi) ?HANDLE; | ||
| 192 | |||
| 193 | // TODO: Wrapper around GetStdHandle + NtDuplicateObject. | 163 | // TODO: Wrapper around GetStdHandle + NtDuplicateObject. |
| 194 | pub extern "kernel32" fn DuplicateHandle( | 164 | pub extern "kernel32" fn DuplicateHandle( |
| 195 | hSourceProcessHandle: HANDLE, | 165 | hSourceProcessHandle: HANDLE, |
| ... | @@ -318,9 +288,6 @@ pub extern "kernel32" fn GetExitCodeProcess( | ... | @@ -318,9 +288,6 @@ pub extern "kernel32" fn GetExitCodeProcess( |
| 318 | lpExitCode: *DWORD, | 288 | lpExitCode: *DWORD, |
| 319 | ) callconv(.winapi) BOOL; | 289 | ) callconv(.winapi) BOOL; |
| 320 | 290 | ||
| 321 | // TODO: Already a wrapper for this, see `windows.GetCurrentProcess`. | ||
| 322 | pub extern "kernel32" fn GetCurrentProcess() callconv(.winapi) HANDLE; | ||
| 323 | |||
| 324 | // TODO: Wrapper around RtlSetEnvironmentVar. | 291 | // TODO: Wrapper around RtlSetEnvironmentVar. |
| 325 | pub extern "kernel32" fn SetEnvironmentVariableW( | 292 | pub extern "kernel32" fn SetEnvironmentVariableW( |
| 326 | lpName: LPCWSTR, | 293 | lpName: LPCWSTR, |
| ... | @@ -465,29 +432,6 @@ pub extern "kernel32" fn HeapValidate( | ... | @@ -465,29 +432,6 @@ pub extern "kernel32" fn HeapValidate( |
| 465 | lpMem: ?*const anyopaque, | 432 | lpMem: ?*const anyopaque, |
| 466 | ) callconv(.winapi) BOOL; | 433 | ) callconv(.winapi) BOOL; |
| 467 | 434 | ||
| 468 | // TODO: Wrapper around NtAllocateVirtualMemory. | ||
| 469 | pub extern "kernel32" fn VirtualAlloc( | ||
| 470 | lpAddress: ?LPVOID, | ||
| 471 | dwSize: SIZE_T, | ||
| 472 | flAllocationType: DWORD, | ||
| 473 | flProtect: DWORD, | ||
| 474 | ) callconv(.winapi) ?LPVOID; | ||
| 475 | |||
| 476 | // TODO: Wrapper around NtFreeVirtualMemory. | ||
| 477 | // If the return value is .INVALID_PAGE_PROTECTION, calls RtlFlushSecureMemoryCache and try again. | ||
| 478 | pub extern "kernel32" fn VirtualFree( | ||
| 479 | lpAddress: ?LPVOID, | ||
| 480 | dwSize: SIZE_T, | ||
| 481 | dwFreeType: DWORD, | ||
| 482 | ) callconv(.winapi) BOOL; | ||
| 483 | |||
| 484 | // TODO: Wrapper around NtQueryVirtualMemory. | ||
| 485 | pub extern "kernel32" fn VirtualQuery( | ||
| 486 | lpAddress: ?LPVOID, | ||
| 487 | lpBuffer: PMEMORY_BASIC_INFORMATION, | ||
| 488 | dwLength: SIZE_T, | ||
| 489 | ) callconv(.winapi) SIZE_T; | ||
| 490 | |||
| 491 | // TODO: Getter for peb.ProcessHeap | 435 | // TODO: Getter for peb.ProcessHeap |
| 492 | pub extern "kernel32" fn GetProcessHeap() callconv(.winapi) ?HANDLE; | 436 | pub extern "kernel32" fn GetProcessHeap() callconv(.winapi) ?HANDLE; |
| 493 | 437 |
lib/std/posix.zig+1-1| ... | @@ -4409,7 +4409,7 @@ pub fn mmap( | ... | @@ -4409,7 +4409,7 @@ pub fn mmap( |
| 4409 | /// Note that while POSIX allows unmapping a region in the middle of an existing mapping, | 4409 | /// Note that while POSIX allows unmapping a region in the middle of an existing mapping, |
| 4410 | /// Zig's munmap function does not, for two reasons: | 4410 | /// Zig's munmap function does not, for two reasons: |
| 4411 | /// * It violates the Zig principle that resource deallocation must succeed. | 4411 | /// * It violates the Zig principle that resource deallocation must succeed. |
| 4412 | /// * The Windows function, VirtualFree, has this restriction. | 4412 | /// * The Windows function, NtFreeVirtualMemory, has this restriction. |
| 4413 | pub fn munmap(memory: []align(page_size_min) const u8) void { | 4413 | pub fn munmap(memory: []align(page_size_min) const u8) void { |
| 4414 | switch (errno(system.munmap(memory.ptr, memory.len))) { | 4414 | switch (errno(system.munmap(memory.ptr, memory.len))) { |
| 4415 | .SUCCESS => return, | 4415 | .SUCCESS => return, |