| author | |
| committer | |
| log | 4dd3f429724768d575e297a82d633b4016467e72 |
| tree | 82699bfe5a52e55a7083244fefa804a4b54e0418 |
| parent | 57b8614a5a287d0a312b1cade463ec5485f0518f |
| parent | 431eeb5e20d20584688235078c9f5d730e59a5b9 |
| signature |
Windows definitions6 files changed, 510 insertions(+), 0 deletions(-)
lib/std/os/bits/windows.zig+14| ... | @@ -226,3 +226,17 @@ pub const AF_TCNMESSAGE = 30; | ... | @@ -226,3 +226,17 @@ pub const AF_TCNMESSAGE = 30; |
| 226 | pub const AF_ICLFXBM = 31; | 226 | pub const AF_ICLFXBM = 31; |
| 227 | pub const AF_BTH = 32; | 227 | pub const AF_BTH = 32; |
| 228 | pub const AF_MAX = 33; | 228 | pub const AF_MAX = 33; |
| 229 | |||
| 230 | pub const SOCK_STREAM = 1; | ||
| 231 | pub const SOCK_DGRAM = 2; | ||
| 232 | pub const SOCK_RAW = 3; | ||
| 233 | pub const SOCK_RDM = 4; | ||
| 234 | pub const SOCK_SEQPACKET = 5; | ||
| 235 | |||
| 236 | pub const IPPROTO_ICMP = 1; | ||
| 237 | pub const IPPROTO_IGMP = 2; | ||
| 238 | pub const BTHPROTO_RFCOMM = 3; | ||
| 239 | pub const IPPROTO_TCP = 6; | ||
| 240 | pub const IPPROTO_UDP = 17; | ||
| 241 | pub const IPPROTO_ICMPV6 = 58; | ||
| 242 | pub const IPPROTO_RM = 113; |
lib/std/os/windows.zig+109| ... | @@ -16,6 +16,7 @@ pub const kernel32 = @import("windows/kernel32.zig"); | ... | @@ -16,6 +16,7 @@ pub const kernel32 = @import("windows/kernel32.zig"); |
| 16 | pub const ntdll = @import("windows/ntdll.zig"); | 16 | pub const ntdll = @import("windows/ntdll.zig"); |
| 17 | pub const ole32 = @import("windows/ole32.zig"); | 17 | pub const ole32 = @import("windows/ole32.zig"); |
| 18 | pub const shell32 = @import("windows/shell32.zig"); | 18 | pub const shell32 = @import("windows/shell32.zig"); |
| 19 | pub const ws2_32 = @import("windows/ws2_32.zig"); | ||
| 19 | 20 | ||
| 20 | pub usingnamespace @import("windows/bits.zig"); | 21 | pub usingnamespace @import("windows/bits.zig"); |
| 21 | 22 | ||
| ... | @@ -96,6 +97,42 @@ pub fn CreatePipe(rd: *HANDLE, wr: *HANDLE, sattr: *const SECURITY_ATTRIBUTES) C | ... | @@ -96,6 +97,42 @@ pub fn CreatePipe(rd: *HANDLE, wr: *HANDLE, sattr: *const SECURITY_ATTRIBUTES) C |
| 96 | } | 97 | } |
| 97 | } | 98 | } |
| 98 | 99 | ||
| 100 | pub fn DeviceIoControl( | ||
| 101 | h: HANDLE, | ||
| 102 | ioControlCode: DWORD, | ||
| 103 | in: ?[]const u8, | ||
| 104 | out: ?[]u8, | ||
| 105 | overlapped: ?*OVERLAPPED, | ||
| 106 | ) !DWORD { | ||
| 107 | var bytes: DWORD = undefined; | ||
| 108 | if (kernel32.DeviceIoControl( | ||
| 109 | h, | ||
| 110 | ioControlCode, | ||
| 111 | if (in) |i| i.ptr else null, | ||
| 112 | if (in) |i| @intCast(u32, i.len) else 0, | ||
| 113 | if (out) |o| o.ptr else null, | ||
| 114 | if (out) |o| @intCast(u32, o.len) else 0, | ||
| 115 | &bytes, | ||
| 116 | overlapped, | ||
| 117 | ) == 0) { | ||
| 118 | switch (kernel32.GetLastError()) { | ||
| 119 | else => |err| return unexpectedError(err), | ||
| 120 | } | ||
| 121 | } | ||
| 122 | return bytes; | ||
| 123 | } | ||
| 124 | |||
| 125 | pub fn GetOverlappedResult(h: HANDLE, overlapped: *OVERLAPPED, wait: bool) !DWORD { | ||
| 126 | var bytes: DWORD = undefined; | ||
| 127 | if (kernel32.GetOverlappedResult(h, overlapped, &bytes, wait) == 0) { | ||
| 128 | switch (kernel32.GetLastError()) { | ||
| 129 | ERROR_IO_INCOMPLETE => if (!wait) return error.WouldBlock else unreachable, | ||
| 130 | else => |err| return unexpectedError(err), | ||
| 131 | } | ||
| 132 | } | ||
| 133 | return bytes; | ||
| 134 | } | ||
| 135 | |||
| 99 | pub const SetHandleInformationError = error{Unexpected}; | 136 | pub const SetHandleInformationError = error{Unexpected}; |
| 100 | 137 | ||
| 101 | pub fn SetHandleInformation(h: HANDLE, mask: DWORD, flags: DWORD) SetHandleInformationError!void { | 138 | pub fn SetHandleInformation(h: HANDLE, mask: DWORD, flags: DWORD) SetHandleInformationError!void { |
| ... | @@ -571,6 +608,74 @@ pub fn GetFileAttributesW(lpFileName: [*]const u16) GetFileAttributesError!DWORD | ... | @@ -571,6 +608,74 @@ pub fn GetFileAttributesW(lpFileName: [*]const u16) GetFileAttributesError!DWORD |
| 571 | return rc; | 608 | return rc; |
| 572 | } | 609 | } |
| 573 | 610 | ||
| 611 | pub fn WSAStartup(majorVersion: u8, minorVersion: u8) !ws2_32.WSADATA { | ||
| 612 | var wsadata: ws2_32.WSADATA = undefined; | ||
| 613 | return switch (ws2_32.WSAStartup((@as(WORD, minorVersion) << 8) | majorVersion, &wsadata)) { | ||
| 614 | 0 => wsadata, | ||
| 615 | else => |err| unexpectedWSAError(err), | ||
| 616 | }; | ||
| 617 | } | ||
| 618 | |||
| 619 | pub fn WSACleanup() !void { | ||
| 620 | return switch (ws2_32.WSACleanup()) { | ||
| 621 | 0 => {}, | ||
| 622 | ws2_32.SOCKET_ERROR => switch (ws2_32.WSAGetLastError()) { | ||
| 623 | else => |err| return unexpectedWSAError(err), | ||
| 624 | }, | ||
| 625 | else => unreachable, | ||
| 626 | }; | ||
| 627 | } | ||
| 628 | |||
| 629 | pub fn WSASocketW( | ||
| 630 | af: i32, | ||
| 631 | socket_type: i32, | ||
| 632 | protocol: i32, | ||
| 633 | protocolInfo: ?*ws2_32.WSAPROTOCOL_INFOW, | ||
| 634 | g: ws2_32.GROUP, | ||
| 635 | dwFlags: DWORD, | ||
| 636 | ) !ws2_32.SOCKET { | ||
| 637 | const rc = ws2_32.WSASocketW(af, socket_type, protocol, protocolInfo, g, dwFlags); | ||
| 638 | if (rc == ws2_32.INVALID_SOCKET) { | ||
| 639 | switch (ws2_32.WSAGetLastError()) { | ||
| 640 | ws2_32.WSAEAFNOSUPPORT => return error.AddressFamilyNotSupported, | ||
| 641 | ws2_32.WSAEMFILE => return error.ProcessFdQuotaExceeded, | ||
| 642 | ws2_32.WSAENOBUFS => return error.SystemResources, | ||
| 643 | ws2_32.WSAEPROTONOSUPPORT => return error.ProtocolNotSupported, | ||
| 644 | else => |err| return unexpectedWSAError(err), | ||
| 645 | } | ||
| 646 | } | ||
| 647 | return rc; | ||
| 648 | } | ||
| 649 | |||
| 650 | pub fn WSAIoctl( | ||
| 651 | s: ws2_32.SOCKET, | ||
| 652 | dwIoControlCode: DWORD, | ||
| 653 | inBuffer: ?[]const u8, | ||
| 654 | outBuffer: []u8, | ||
| 655 | overlapped: ?*ws2_32.WSAOVERLAPPED, | ||
| 656 | completionRoutine: ?*ws2_32.WSAOVERLAPPED_COMPLETION_ROUTINE, | ||
| 657 | ) !DWORD { | ||
| 658 | var bytes: DWORD = undefined; | ||
| 659 | switch (ws2_32.WSAIoctl( | ||
| 660 | s, | ||
| 661 | dwIoControlCode, | ||
| 662 | if (inBuffer) |i| i.ptr else null, | ||
| 663 | if (inBuffer) |i| @intCast(DWORD, i.len) else 0, | ||
| 664 | outBuffer.ptr, | ||
| 665 | @intCast(DWORD, outBuffer.len), | ||
| 666 | &bytes, | ||
| 667 | overlapped, | ||
| 668 | completionRoutine, | ||
| 669 | )) { | ||
| 670 | 0 => {}, | ||
| 671 | ws2_32.SOCKET_ERROR => switch (ws2_32.WSAGetLastError()) { | ||
| 672 | else => |err| return unexpectedWSAError(err), | ||
| 673 | }, | ||
| 674 | else => unreachable, | ||
| 675 | } | ||
| 676 | return bytes; | ||
| 677 | } | ||
| 678 | |||
| 574 | const GetModuleFileNameError = error{Unexpected}; | 679 | const GetModuleFileNameError = error{Unexpected}; |
| 575 | 680 | ||
| 576 | pub fn GetModuleFileNameW(hModule: ?HMODULE, buf_ptr: [*]u16, buf_len: DWORD) GetModuleFileNameError![]u16 { | 681 | pub fn GetModuleFileNameW(hModule: ?HMODULE, buf_ptr: [*]u16, buf_len: DWORD) GetModuleFileNameError![]u16 { |
| ... | @@ -868,6 +973,10 @@ pub fn unexpectedError(err: DWORD) std.os.UnexpectedError { | ... | @@ -868,6 +973,10 @@ pub fn unexpectedError(err: DWORD) std.os.UnexpectedError { |
| 868 | return error.Unexpected; | 973 | return error.Unexpected; |
| 869 | } | 974 | } |
| 870 | 975 | ||
| 976 | pub fn unexpectedWSAError(err: c_int) std.os.UnexpectedError { | ||
| 977 | return unexpectedError(@intCast(DWORD, err)); | ||
| 978 | } | ||
| 979 | |||
| 871 | /// Call this when you made a windows NtDll call | 980 | /// Call this when you made a windows NtDll call |
| 872 | /// and you get an unexpected status. | 981 | /// and you get an unexpected status. |
| 873 | pub fn unexpectedStatus(status: NTSTATUS) std.os.UnexpectedError { | 982 | pub fn unexpectedStatus(status: NTSTATUS) std.os.UnexpectedError { |
lib/std/os/windows/bits.zig+107| ... | @@ -67,6 +67,113 @@ pub const va_list = *@OpaqueType(); | ... | @@ -67,6 +67,113 @@ pub const va_list = *@OpaqueType(); |
| 67 | pub const TRUE = 1; | 67 | pub const TRUE = 1; |
| 68 | pub const FALSE = 0; | 68 | pub const FALSE = 0; |
| 69 | 69 | ||
| 70 | pub const DEVICE_TYPE = ULONG; | ||
| 71 | pub const FILE_DEVICE_BEEP: DEVICE_TYPE = 0x0001; | ||
| 72 | pub const FILE_DEVICE_CD_ROM: DEVICE_TYPE = 0x0002; | ||
| 73 | pub const FILE_DEVICE_CD_ROM_FILE_SYSTEM: DEVICE_TYPE = 0x0003; | ||
| 74 | pub const FILE_DEVICE_CONTROLLER: DEVICE_TYPE = 0x0004; | ||
| 75 | pub const FILE_DEVICE_DATALINK: DEVICE_TYPE = 0x0005; | ||
| 76 | pub const FILE_DEVICE_DFS: DEVICE_TYPE = 0x0006; | ||
| 77 | pub const FILE_DEVICE_DISK: DEVICE_TYPE = 0x0007; | ||
| 78 | pub const FILE_DEVICE_DISK_FILE_SYSTEM: DEVICE_TYPE = 0x0008; | ||
| 79 | pub const FILE_DEVICE_FILE_SYSTEM: DEVICE_TYPE = 0x0009; | ||
| 80 | pub const FILE_DEVICE_INPORT_PORT: DEVICE_TYPE = 0x000a; | ||
| 81 | pub const FILE_DEVICE_KEYBOARD: DEVICE_TYPE = 0x000b; | ||
| 82 | pub const FILE_DEVICE_MAILSLOT: DEVICE_TYPE = 0x000c; | ||
| 83 | pub const FILE_DEVICE_MIDI_IN: DEVICE_TYPE = 0x000d; | ||
| 84 | pub const FILE_DEVICE_MIDI_OUT: DEVICE_TYPE = 0x000e; | ||
| 85 | pub const FILE_DEVICE_MOUSE: DEVICE_TYPE = 0x000f; | ||
| 86 | pub const FILE_DEVICE_MULTI_UNC_PROVIDER: DEVICE_TYPE = 0x0010; | ||
| 87 | pub const FILE_DEVICE_NAMED_PIPE: DEVICE_TYPE = 0x0011; | ||
| 88 | pub const FILE_DEVICE_NETWORK: DEVICE_TYPE = 0x0012; | ||
| 89 | pub const FILE_DEVICE_NETWORK_BROWSER: DEVICE_TYPE = 0x0013; | ||
| 90 | pub const FILE_DEVICE_NETWORK_FILE_SYSTEM: DEVICE_TYPE = 0x0014; | ||
| 91 | pub const FILE_DEVICE_NULL: DEVICE_TYPE = 0x0015; | ||
| 92 | pub const FILE_DEVICE_PARALLEL_PORT: DEVICE_TYPE = 0x0016; | ||
| 93 | pub const FILE_DEVICE_PHYSICAL_NETCARD: DEVICE_TYPE = 0x0017; | ||
| 94 | pub const FILE_DEVICE_PRINTER: DEVICE_TYPE = 0x0018; | ||
| 95 | pub const FILE_DEVICE_SCANNER: DEVICE_TYPE = 0x0019; | ||
| 96 | pub const FILE_DEVICE_SERIAL_MOUSE_PORT: DEVICE_TYPE = 0x001a; | ||
| 97 | pub const FILE_DEVICE_SERIAL_PORT: DEVICE_TYPE = 0x001b; | ||
| 98 | pub const FILE_DEVICE_SCREEN: DEVICE_TYPE = 0x001c; | ||
| 99 | pub const FILE_DEVICE_SOUND: DEVICE_TYPE = 0x001d; | ||
| 100 | pub const FILE_DEVICE_STREAMS: DEVICE_TYPE = 0x001e; | ||
| 101 | pub const FILE_DEVICE_TAPE: DEVICE_TYPE = 0x001f; | ||
| 102 | pub const FILE_DEVICE_TAPE_FILE_SYSTEM: DEVICE_TYPE = 0x0020; | ||
| 103 | pub const FILE_DEVICE_TRANSPORT: DEVICE_TYPE = 0x0021; | ||
| 104 | pub const FILE_DEVICE_UNKNOWN: DEVICE_TYPE = 0x0022; | ||
| 105 | pub const FILE_DEVICE_VIDEO: DEVICE_TYPE = 0x0023; | ||
| 106 | pub const FILE_DEVICE_VIRTUAL_DISK: DEVICE_TYPE = 0x0024; | ||
| 107 | pub const FILE_DEVICE_WAVE_IN: DEVICE_TYPE = 0x0025; | ||
| 108 | pub const FILE_DEVICE_WAVE_OUT: DEVICE_TYPE = 0x0026; | ||
| 109 | pub const FILE_DEVICE_8042_PORT: DEVICE_TYPE = 0x0027; | ||
| 110 | pub const FILE_DEVICE_NETWORK_REDIRECTOR: DEVICE_TYPE = 0x0028; | ||
| 111 | pub const FILE_DEVICE_BATTERY: DEVICE_TYPE = 0x0029; | ||
| 112 | pub const FILE_DEVICE_BUS_EXTENDER: DEVICE_TYPE = 0x002a; | ||
| 113 | pub const FILE_DEVICE_MODEM: DEVICE_TYPE = 0x002b; | ||
| 114 | pub const FILE_DEVICE_VDM: DEVICE_TYPE = 0x002c; | ||
| 115 | pub const FILE_DEVICE_MASS_STORAGE: DEVICE_TYPE = 0x002d; | ||
| 116 | pub const FILE_DEVICE_SMB: DEVICE_TYPE = 0x002e; | ||
| 117 | pub const FILE_DEVICE_KS: DEVICE_TYPE = 0x002f; | ||
| 118 | pub const FILE_DEVICE_CHANGER: DEVICE_TYPE = 0x0030; | ||
| 119 | pub const FILE_DEVICE_SMARTCARD: DEVICE_TYPE = 0x0031; | ||
| 120 | pub const FILE_DEVICE_ACPI: DEVICE_TYPE = 0x0032; | ||
| 121 | pub const FILE_DEVICE_DVD: DEVICE_TYPE = 0x0033; | ||
| 122 | pub const FILE_DEVICE_FULLSCREEN_VIDEO: DEVICE_TYPE = 0x0034; | ||
| 123 | pub const FILE_DEVICE_DFS_FILE_SYSTEM: DEVICE_TYPE = 0x0035; | ||
| 124 | pub const FILE_DEVICE_DFS_VOLUME: DEVICE_TYPE = 0x0036; | ||
| 125 | pub const FILE_DEVICE_SERENUM: DEVICE_TYPE = 0x0037; | ||
| 126 | pub const FILE_DEVICE_TERMSRV: DEVICE_TYPE = 0x0038; | ||
| 127 | pub const FILE_DEVICE_KSEC: DEVICE_TYPE = 0x0039; | ||
| 128 | pub const FILE_DEVICE_FIPS: DEVICE_TYPE = 0x003a; | ||
| 129 | pub const FILE_DEVICE_INFINIBAND: DEVICE_TYPE = 0x003b; | ||
| 130 | // TODO: missing values? | ||
| 131 | pub const FILE_DEVICE_VMBUS: DEVICE_TYPE = 0x003e; | ||
| 132 | pub const FILE_DEVICE_CRYPT_PROVIDER: DEVICE_TYPE = 0x003f; | ||
| 133 | pub const FILE_DEVICE_WPD: DEVICE_TYPE = 0x0040; | ||
| 134 | pub const FILE_DEVICE_BLUETOOTH: DEVICE_TYPE = 0x0041; | ||
| 135 | pub const FILE_DEVICE_MT_COMPOSITE: DEVICE_TYPE = 0x0042; | ||
| 136 | pub const FILE_DEVICE_MT_TRANSPORT: DEVICE_TYPE = 0x0043; | ||
| 137 | pub const FILE_DEVICE_BIOMETRIC: DEVICE_TYPE = 0x0044; | ||
| 138 | pub const FILE_DEVICE_PMI: DEVICE_TYPE = 0x0045; | ||
| 139 | pub const FILE_DEVICE_EHSTOR: DEVICE_TYPE = 0x0046; | ||
| 140 | pub const FILE_DEVICE_DEVAPI: DEVICE_TYPE = 0x0047; | ||
| 141 | pub const FILE_DEVICE_GPIO: DEVICE_TYPE = 0x0048; | ||
| 142 | pub const FILE_DEVICE_USBEX: DEVICE_TYPE = 0x0049; | ||
| 143 | pub const FILE_DEVICE_CONSOLE: DEVICE_TYPE = 0x0050; | ||
| 144 | pub const FILE_DEVICE_NFP: DEVICE_TYPE = 0x0051; | ||
| 145 | pub const FILE_DEVICE_SYSENV: DEVICE_TYPE = 0x0052; | ||
| 146 | pub const FILE_DEVICE_VIRTUAL_BLOCK: DEVICE_TYPE = 0x0053; | ||
| 147 | pub const FILE_DEVICE_POINT_OF_SERVICE: DEVICE_TYPE = 0x0054; | ||
| 148 | pub const FILE_DEVICE_STORAGE_REPLICATION: DEVICE_TYPE = 0x0055; | ||
| 149 | pub const FILE_DEVICE_TRUST_ENV: DEVICE_TYPE = 0x0056; | ||
| 150 | pub const FILE_DEVICE_UCM: DEVICE_TYPE = 0x0057; | ||
| 151 | pub const FILE_DEVICE_UCMTCPCI: DEVICE_TYPE = 0x0058; | ||
| 152 | pub const FILE_DEVICE_PERSISTENT_MEMORY: DEVICE_TYPE = 0x0059; | ||
| 153 | pub const FILE_DEVICE_NVDIMM: DEVICE_TYPE = 0x005a; | ||
| 154 | pub const FILE_DEVICE_HOLOGRAPHIC: DEVICE_TYPE = 0x005b; | ||
| 155 | pub const FILE_DEVICE_SDFXHCI: DEVICE_TYPE = 0x005c; | ||
| 156 | |||
| 157 | /// https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/buffer-descriptions-for-i-o-control-codes | ||
| 158 | pub const TransferType = enum(u2) { | ||
| 159 | METHOD_BUFFERED = 0, | ||
| 160 | METHOD_IN_DIRECT = 1, | ||
| 161 | METHOD_OUT_DIRECT = 2, | ||
| 162 | METHOD_NEITHER = 3, | ||
| 163 | }; | ||
| 164 | |||
| 165 | pub const FILE_ANY_ACCESS = 0; | ||
| 166 | pub const FILE_READ_ACCESS = 1; | ||
| 167 | pub const FILE_WRITE_ACCESS = 2; | ||
| 168 | |||
| 169 | /// https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/defining-i-o-control-codes | ||
| 170 | pub fn CTL_CODE(deviceType: u16, function: u12, method: TransferType, access: u2) DWORD { | ||
| 171 | return (@as(DWORD, deviceType) << 16) | | ||
| 172 | (@as(DWORD, access) << 14) | | ||
| 173 | (@as(DWORD, function) << 2) | | ||
| 174 | @enumToInt(method); | ||
| 175 | } | ||
| 176 | |||
| 70 | pub const INVALID_HANDLE_VALUE = @intToPtr(HANDLE, maxInt(usize)); | 177 | pub const INVALID_HANDLE_VALUE = @intToPtr(HANDLE, maxInt(usize)); |
| 71 | 178 | ||
| 72 | pub const INVALID_FILE_ATTRIBUTES = @as(DWORD, maxInt(DWORD)); | 179 | pub const INVALID_FILE_ATTRIBUTES = @as(DWORD, maxInt(DWORD)); |
lib/std/os/windows/kernel32.zig+11| ... | @@ -45,6 +45,17 @@ pub extern "kernel32" stdcallcc fn CreateIoCompletionPort(FileHandle: HANDLE, Ex | ... | @@ -45,6 +45,17 @@ pub extern "kernel32" stdcallcc fn CreateIoCompletionPort(FileHandle: HANDLE, Ex |
| 45 | 45 | ||
| 46 | pub extern "kernel32" stdcallcc fn CreateThread(lpThreadAttributes: ?LPSECURITY_ATTRIBUTES, dwStackSize: SIZE_T, lpStartAddress: LPTHREAD_START_ROUTINE, lpParameter: ?LPVOID, dwCreationFlags: DWORD, lpThreadId: ?LPDWORD) ?HANDLE; | 46 | pub extern "kernel32" stdcallcc fn CreateThread(lpThreadAttributes: ?LPSECURITY_ATTRIBUTES, dwStackSize: SIZE_T, lpStartAddress: LPTHREAD_START_ROUTINE, lpParameter: ?LPVOID, dwCreationFlags: DWORD, lpThreadId: ?LPDWORD) ?HANDLE; |
| 47 | 47 | ||
| 48 | pub extern "kernel32" stdcallcc fn DeviceIoControl( | ||
| 49 | h: HANDLE, | ||
| 50 | dwIoControlCode: DWORD, | ||
| 51 | lpInBuffer: ?*const c_void, | ||
| 52 | nInBufferSize: DWORD, | ||
| 53 | lpOutBuffer: ?LPVOID, | ||
| 54 | nOutBufferSize: DWORD, | ||
| 55 | lpBytesReturned: LPDWORD, | ||
| 56 | lpOverlapped: ?*OVERLAPPED, | ||
| 57 | ) BOOL; | ||
| 58 | |||
| 48 | pub extern "kernel32" stdcallcc fn DeleteFileW(lpFileName: [*]const u16) BOOL; | 59 | pub extern "kernel32" stdcallcc fn DeleteFileW(lpFileName: [*]const u16) BOOL; |
| 49 | 60 | ||
| 50 | pub extern "kernel32" stdcallcc fn DuplicateHandle(hSourceProcessHandle: HANDLE, hSourceHandle: HANDLE, hTargetProcessHandle: HANDLE, lpTargetHandle: *HANDLE, dwDesiredAccess: DWORD, bInheritHandle: BOOL, dwOptions: DWORD) BOOL; | 61 | pub extern "kernel32" stdcallcc fn DuplicateHandle(hSourceProcessHandle: HANDLE, hSourceHandle: HANDLE, hTargetProcessHandle: HANDLE, lpTargetHandle: *HANDLE, dwDesiredAccess: DWORD, bInheritHandle: BOOL, dwOptions: DWORD) BOOL; |
lib/std/os/windows/ntdll.zig+12| ... | @@ -21,6 +21,18 @@ pub extern "NtDll" stdcallcc fn NtCreateFile( | ... | @@ -21,6 +21,18 @@ pub extern "NtDll" stdcallcc fn NtCreateFile( |
| 21 | EaBuffer: ?*c_void, | 21 | EaBuffer: ?*c_void, |
| 22 | EaLength: ULONG, | 22 | EaLength: ULONG, |
| 23 | ) NTSTATUS; | 23 | ) NTSTATUS; |
| 24 | pub extern "NtDll" stdcallcc fn NtDeviceIoControlFile( | ||
| 25 | FileHandle: HANDLE, | ||
| 26 | Event: ?HANDLE, | ||
| 27 | ApcRoutine: ?*IO_APC_ROUTINE, | ||
| 28 | ApcContext: usize, | ||
| 29 | IoStatusBlock: *IO_STATUS_BLOCK, | ||
| 30 | IoControlCode: ULONG, | ||
| 31 | InputBuffer: ?*const c_void, | ||
| 32 | InputBufferLength: ULONG, | ||
| 33 | OutputBuffer: ?PVOID, | ||
| 34 | OutputBufferLength: ULONG, | ||
| 35 | ) NTSTATUS; | ||
| 24 | pub extern "NtDll" stdcallcc fn NtClose(Handle: HANDLE) NTSTATUS; | 36 | pub extern "NtDll" stdcallcc fn NtClose(Handle: HANDLE) NTSTATUS; |
| 25 | pub extern "NtDll" stdcallcc fn RtlDosPathNameToNtPathName_U( | 37 | pub extern "NtDll" stdcallcc fn RtlDosPathNameToNtPathName_U( |
| 26 | DosPathName: [*]const u16, | 38 | DosPathName: [*]const u16, |
lib/std/os/windows/ws2_32.zig created+257| ... | @@ -0,0 +1,257 @@ | ||
| 1 | usingnamespace @import("bits.zig"); | ||
| 2 | |||
| 3 | pub const SOCKET = *@OpaqueType(); | ||
| 4 | pub const INVALID_SOCKET = @intToPtr(SOCKET, ~@as(usize, 0)); | ||
| 5 | pub const SOCKET_ERROR = -1; | ||
| 6 | |||
| 7 | pub const WSADESCRIPTION_LEN = 256; | ||
| 8 | pub const WSASYS_STATUS_LEN = 128; | ||
| 9 | |||
| 10 | pub const WSADATA = if (usize.bit_count == u64.bit_count) | ||
| 11 | extern struct { | ||
| 12 | wVersion: WORD, | ||
| 13 | wHighVersion: WORD, | ||
| 14 | iMaxSockets: u16, | ||
| 15 | iMaxUdpDg: u16, | ||
| 16 | lpVendorInfo: *u8, | ||
| 17 | szDescription: [WSADESCRIPTION_LEN + 1]u8, | ||
| 18 | szSystemStatus: [WSASYS_STATUS_LEN + 1]u8, | ||
| 19 | } | ||
| 20 | else | ||
| 21 | extern struct { | ||
| 22 | wVersion: WORD, | ||
| 23 | wHighVersion: WORD, | ||
| 24 | szDescription: [WSADESCRIPTION_LEN + 1]u8, | ||
| 25 | szSystemStatus: [WSASYS_STATUS_LEN + 1]u8, | ||
| 26 | iMaxSockets: u16, | ||
| 27 | iMaxUdpDg: u16, | ||
| 28 | lpVendorInfo: *u8, | ||
| 29 | }; | ||
| 30 | |||
| 31 | pub const MAX_PROTOCOL_CHAIN = 7; | ||
| 32 | |||
| 33 | pub const WSAPROTOCOLCHAIN = extern struct { | ||
| 34 | ChainLen: c_int, | ||
| 35 | ChainEntries: [MAX_PROTOCOL_CHAIN]DWORD, | ||
| 36 | }; | ||
| 37 | |||
| 38 | pub const WSAPROTOCOL_LEN = 255; | ||
| 39 | |||
| 40 | pub const WSAPROTOCOL_INFOA = extern struct { | ||
| 41 | dwServiceFlags1: DWORD, | ||
| 42 | dwServiceFlags2: DWORD, | ||
| 43 | dwServiceFlags3: DWORD, | ||
| 44 | dwServiceFlags4: DWORD, | ||
| 45 | dwProviderFlags: DWORD, | ||
| 46 | ProviderId: GUID, | ||
| 47 | dwCatalogEntryId: DWORD, | ||
| 48 | ProtocolChain: WSAPROTOCOLCHAIN, | ||
| 49 | iVersion: c_int, | ||
| 50 | iAddressFamily: c_int, | ||
| 51 | iMaxSockAddr: c_int, | ||
| 52 | iMinSockAddr: c_int, | ||
| 53 | iSocketType: c_int, | ||
| 54 | iProtocol: c_int, | ||
| 55 | iProtocolMaxOffset: c_int, | ||
| 56 | iNetworkByteOrder: c_int, | ||
| 57 | iSecurityScheme: c_int, | ||
| 58 | dwMessageSize: DWORD, | ||
| 59 | dwProviderReserved: DWORD, | ||
| 60 | szProtocol: [WSAPROTOCOL_LEN + 1]CHAR, | ||
| 61 | }; | ||
| 62 | |||
| 63 | pub const WSAPROTOCOL_INFOW = extern struct { | ||
| 64 | dwServiceFlags1: DWORD, | ||
| 65 | dwServiceFlags2: DWORD, | ||
| 66 | dwServiceFlags3: DWORD, | ||
| 67 | dwServiceFlags4: DWORD, | ||
| 68 | dwProviderFlags: DWORD, | ||
| 69 | ProviderId: GUID, | ||
| 70 | dwCatalogEntryId: DWORD, | ||
| 71 | ProtocolChain: WSAPROTOCOLCHAIN, | ||
| 72 | iVersion: c_int, | ||
| 73 | iAddressFamily: c_int, | ||
| 74 | iMaxSockAddr: c_int, | ||
| 75 | iMinSockAddr: c_int, | ||
| 76 | iSocketType: c_int, | ||
| 77 | iProtocol: c_int, | ||
| 78 | iProtocolMaxOffset: c_int, | ||
| 79 | iNetworkByteOrder: c_int, | ||
| 80 | iSecurityScheme: c_int, | ||
| 81 | dwMessageSize: DWORD, | ||
| 82 | dwProviderReserved: DWORD, | ||
| 83 | szProtocol: [WSAPROTOCOL_LEN + 1]WCHAR, | ||
| 84 | }; | ||
| 85 | |||
| 86 | pub const GROUP = u32; | ||
| 87 | |||
| 88 | pub const SG_UNCONSTRAINED_GROUP = 0x1; | ||
| 89 | pub const SG_CONSTRAINED_GROUP = 0x2; | ||
| 90 | |||
| 91 | pub const WSA_FLAG_OVERLAPPED = 0x01; | ||
| 92 | pub const WSA_FLAG_MULTIPOINT_C_ROOT = 0x02; | ||
| 93 | pub const WSA_FLAG_MULTIPOINT_C_LEAF = 0x04; | ||
| 94 | pub const WSA_FLAG_MULTIPOINT_D_ROOT = 0x08; | ||
| 95 | pub const WSA_FLAG_MULTIPOINT_D_LEAF = 0x10; | ||
| 96 | pub const WSA_FLAG_ACCESS_SYSTEM_SECURITY = 0x40; | ||
| 97 | pub const WSA_FLAG_NO_HANDLE_INHERIT = 0x80; | ||
| 98 | |||
| 99 | pub const WSAEVENT = HANDLE; | ||
| 100 | |||
| 101 | pub const WSAOVERLAPPED = extern struct { | ||
| 102 | Internal: DWORD, | ||
| 103 | InternalHigh: DWORD, | ||
| 104 | Offset: DWORD, | ||
| 105 | OffsetHigh: DWORD, | ||
| 106 | hEvent: ?WSAEVENT, | ||
| 107 | }; | ||
| 108 | |||
| 109 | pub const WSAOVERLAPPED_COMPLETION_ROUTINE = extern fn ( | ||
| 110 | dwError: DWORD, | ||
| 111 | cbTransferred: DWORD, | ||
| 112 | lpOverlapped: *WSAOVERLAPPED, | ||
| 113 | dwFlags: DWORD | ||
| 114 | ) void; | ||
| 115 | |||
| 116 | pub const WSA_INVALID_HANDLE = 6; | ||
| 117 | pub const WSA_NOT_ENOUGH_MEMORY = 8; | ||
| 118 | pub const WSA_INVALID_PARAMETER = 87; | ||
| 119 | pub const WSA_OPERATION_ABORTED = 995; | ||
| 120 | pub const WSA_IO_INCOMPLETE = 996; | ||
| 121 | pub const WSA_IO_PENDING = 997; | ||
| 122 | pub const WSAEINTR = 10004; | ||
| 123 | pub const WSAEBADF = 10009; | ||
| 124 | pub const WSAEACCES = 10013; | ||
| 125 | pub const WSAEFAULT = 10014; | ||
| 126 | pub const WSAEINVAL = 10022; | ||
| 127 | pub const WSAEMFILE = 10024; | ||
| 128 | pub const WSAEWOULDBLOCK = 10035; | ||
| 129 | pub const WSAEINPROGRESS = 10036; | ||
| 130 | pub const WSAEALREADY = 10037; | ||
| 131 | pub const WSAENOTSOCK = 10038; | ||
| 132 | pub const WSAEDESTADDRREQ = 10039; | ||
| 133 | pub const WSAEMSGSIZE = 10040; | ||
| 134 | pub const WSAEPROTOTYPE = 10041; | ||
| 135 | pub const WSAENOPROTOOPT = 10042; | ||
| 136 | pub const WSAEPROTONOSUPPORT = 10043; | ||
| 137 | pub const WSAESOCKTNOSUPPORT = 10044; | ||
| 138 | pub const WSAEOPNOTSUPP = 10045; | ||
| 139 | pub const WSAEPFNOSUPPORT = 10046; | ||
| 140 | pub const WSAEAFNOSUPPORT = 10047; | ||
| 141 | pub const WSAEADDRINUSE = 10048; | ||
| 142 | pub const WSAEADDRNOTAVAIL = 10049; | ||
| 143 | pub const WSAENETDOWN = 10050; | ||
| 144 | pub const WSAENETUNREACH = 10051; | ||
| 145 | pub const WSAENETRESET = 10052; | ||
| 146 | pub const WSAECONNABORTED = 10053; | ||
| 147 | pub const WSAECONNRESET = 10054; | ||
| 148 | pub const WSAENOBUFS = 10055; | ||
| 149 | pub const WSAEISCONN = 10056; | ||
| 150 | pub const WSAENOTCONN = 10057; | ||
| 151 | pub const WSAESHUTDOWN = 10058; | ||
| 152 | pub const WSAETOOMANYREFS = 10059; | ||
| 153 | pub const WSAETIMEDOUT = 10060; | ||
| 154 | pub const WSAECONNREFUSED = 10061; | ||
| 155 | pub const WSAELOOP = 10062; | ||
| 156 | pub const WSAENAMETOOLONG = 10063; | ||
| 157 | pub const WSAEHOSTDOWN = 10064; | ||
| 158 | pub const WSAEHOSTUNREACH = 10065; | ||
| 159 | pub const WSAENOTEMPTY = 10066; | ||
| 160 | pub const WSAEPROCLIM = 10067; | ||
| 161 | pub const WSAEUSERS = 10068; | ||
| 162 | pub const WSAEDQUOT = 10069; | ||
| 163 | pub const WSAESTALE = 10070; | ||
| 164 | pub const WSAEREMOTE = 10071; | ||
| 165 | pub const WSASYSNOTREADY = 10091; | ||
| 166 | pub const WSAVERNOTSUPPORTED = 10092; | ||
| 167 | pub const WSANOTINITIALISED = 10093; | ||
| 168 | pub const WSAEDISCON = 10101; | ||
| 169 | pub const WSAENOMORE = 10102; | ||
| 170 | pub const WSAECANCELLED = 10103; | ||
| 171 | pub const WSAEINVALIDPROCTABLE = 10104; | ||
| 172 | pub const WSAEINVALIDPROVIDER = 10105; | ||
| 173 | pub const WSAEPROVIDERFAILEDINIT = 10106; | ||
| 174 | pub const WSASYSCALLFAILURE = 10107; | ||
| 175 | pub const WSASERVICE_NOT_FOUND = 10108; | ||
| 176 | pub const WSATYPE_NOT_FOUND = 10109; | ||
| 177 | pub const WSA_E_NO_MORE = 10110; | ||
| 178 | pub const WSA_E_CANCELLED = 10111; | ||
| 179 | pub const WSAEREFUSED = 10112; | ||
| 180 | pub const WSAHOST_NOT_FOUND = 11001; | ||
| 181 | pub const WSATRY_AGAIN = 11002; | ||
| 182 | pub const WSANO_RECOVERY = 11003; | ||
| 183 | pub const WSANO_DATA = 11004; | ||
| 184 | pub const WSA_QOS_RECEIVERS = 11005; | ||
| 185 | pub const WSA_QOS_SENDERS = 11006; | ||
| 186 | pub const WSA_QOS_NO_SENDERS = 11007; | ||
| 187 | pub const WSA_QOS_NO_RECEIVERS = 11008; | ||
| 188 | pub const WSA_QOS_REQUEST_CONFIRMED = 11009; | ||
| 189 | pub const WSA_QOS_ADMISSION_FAILURE = 11010; | ||
| 190 | pub const WSA_QOS_POLICY_FAILURE = 11011; | ||
| 191 | pub const WSA_QOS_BAD_STYLE = 11012; | ||
| 192 | pub const WSA_QOS_BAD_OBJECT = 11013; | ||
| 193 | pub const WSA_QOS_TRAFFIC_CTRL_ERROR = 11014; | ||
| 194 | pub const WSA_QOS_GENERIC_ERROR = 11015; | ||
| 195 | pub const WSA_QOS_ESERVICETYPE = 11016; | ||
| 196 | pub const WSA_QOS_EFLOWSPEC = 11017; | ||
| 197 | pub const WSA_QOS_EPROVSPECBUF = 11018; | ||
| 198 | pub const WSA_QOS_EFILTERSTYLE = 11019; | ||
| 199 | pub const WSA_QOS_EFILTERTYPE = 11020; | ||
| 200 | pub const WSA_QOS_EFILTERCOUNT = 11021; | ||
| 201 | pub const WSA_QOS_EOBJLENGTH = 11022; | ||
| 202 | pub const WSA_QOS_EFLOWCOUNT = 11023; | ||
| 203 | pub const WSA_QOS_EUNKOWNPSOBJ = 11024; | ||
| 204 | pub const WSA_QOS_EPOLICYOBJ = 11025; | ||
| 205 | pub const WSA_QOS_EFLOWDESC = 11026; | ||
| 206 | pub const WSA_QOS_EPSFLOWSPEC = 11027; | ||
| 207 | pub const WSA_QOS_EPSFILTERSPEC = 11028; | ||
| 208 | pub const WSA_QOS_ESDMODEOBJ = 11029; | ||
| 209 | pub const WSA_QOS_ESHAPERATEOBJ = 11030; | ||
| 210 | pub const WSA_QOS_RESERVED_PETYPE = 11031; | ||
| 211 | |||
| 212 | |||
| 213 | /// no parameters | ||
| 214 | const IOC_VOID = 0x80000000; | ||
| 215 | /// copy out parameters | ||
| 216 | const IOC_OUT = 0x40000000; | ||
| 217 | /// copy in parameters | ||
| 218 | const IOC_IN = 0x80000000; | ||
| 219 | |||
| 220 | /// The IOCTL is a generic Windows Sockets 2 IOCTL code. New IOCTL codes defined for Windows Sockets 2 will have T == 1. | ||
| 221 | const IOC_WS2 = 0x08000000; | ||
| 222 | |||
| 223 | pub const SIO_BASE_HANDLE = IOC_OUT | IOC_WS2 | 34; | ||
| 224 | |||
| 225 | pub extern "ws2_32" stdcallcc fn WSAStartup( | ||
| 226 | wVersionRequired: WORD, | ||
| 227 | lpWSAData: *WSADATA, | ||
| 228 | ) c_int; | ||
| 229 | pub extern "ws2_32" stdcallcc fn WSACleanup() c_int; | ||
| 230 | pub extern "ws2_32" stdcallcc fn WSAGetLastError() c_int; | ||
| 231 | pub extern "ws2_32" stdcallcc fn WSASocketA( | ||
| 232 | af: c_int, | ||
| 233 | type: c_int, | ||
| 234 | protocol: c_int, | ||
| 235 | lpProtocolInfo: ?*WSAPROTOCOL_INFOA, | ||
| 236 | g: GROUP, | ||
| 237 | dwFlags: DWORD, | ||
| 238 | ) SOCKET; | ||
| 239 | pub extern "ws2_32" stdcallcc fn WSASocketW( | ||
| 240 | af: c_int, | ||
| 241 | type: c_int, | ||
| 242 | protocol: c_int, | ||
| 243 | lpProtocolInfo: ?*WSAPROTOCOL_INFOW, | ||
| 244 | g: GROUP, | ||
| 245 | dwFlags: DWORD, | ||
| 246 | ) SOCKET; | ||
| 247 | pub extern "ws2_32" stdcallcc fn WSAIoctl( | ||
| 248 | s: SOCKET, | ||
| 249 | dwIoControlCode: DWORD, | ||
| 250 | lpvInBuffer: ?*const c_void, | ||
| 251 | cbInBuffer: DWORD, | ||
| 252 | lpvOutBuffer: ?LPVOID, | ||
| 253 | cbOutBuffer: DWORD, | ||
| 254 | lpcbBytesReturned: LPDWORD, | ||
| 255 | lpOverlapped: ?*WSAOVERLAPPED, | ||
| 256 | lpCompletionRoutine: ?*WSAOVERLAPPED_COMPLETION_ROUTINE, | ||
| 257 | ) c_int; | ||