From f7da31b1f43f5f707c9de841577e491ef115bb94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Mon, 28 Oct 2024 22:47:25 +0100 Subject: [PATCH 01/11] std.builtin: Some minor fixes to CallingConvention doc comments. --- lib/std/builtin.zig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index d7f8876b24..02948d6602 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -293,12 +293,12 @@ pub const CallingConvention = union(enum(u8)) { arm_aapcs16_vfp: CommonOptions, arm_interrupt: ArmInterruptOptions, - // Calling conventions for the `mips64` architecture. + // Calling conventions for the `mips64` and `mips64el` architectures. mips64_n64: CommonOptions, mips64_n32: CommonOptions, mips64_interrupt: MipsInterruptOptions, - // Calling conventions for the `mips` architecture. + // Calling conventions for the `mips` and `mipsel` architectures. mips_o32: CommonOptions, mips_interrupt: MipsInterruptOptions, @@ -329,7 +329,7 @@ pub const CallingConvention = union(enum(u8)) { powerpc_aix: CommonOptions, powerpc_aix_altivec: CommonOptions, - /// The standard `wasm32`/`wasm64` calling convention, as specified in the WebAssembly Tool Conventions. + /// The standard `wasm32` and `wasm64` calling convention, as specified in the WebAssembly Tool Conventions. wasm_watc: CommonOptions, /// The standard `arc` calling convention. @@ -396,7 +396,7 @@ pub const CallingConvention = union(enum(u8)) { amdgcn_kernel, amdgcn_cs: CommonOptions, - // Calling conventions for the `nvptx` architecture. + // Calling conventions for the `nvptx` and `nvptx64` architectures. nvptx_device, nvptx_kernel, From 20cdfe9fb6e5f54623e170b59781001dcc7e1d75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Mon, 28 Oct 2024 20:24:02 +0100 Subject: [PATCH 02/11] std.Target: Pick arm_aapcs16_vfp for arm-watchos-* in cCallingConvention(). This is a legacy target, but we should still get it right. --- lib/std/Target.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/std/Target.zig b/lib/std/Target.zig index 4610d11c01..eef52c889f 100644 --- a/lib/std/Target.zig +++ b/lib/std/Target.zig @@ -3295,6 +3295,7 @@ pub fn cCallingConvention(target: Target) ?std.builtin.CallingConvention { }, .arm, .armeb, .thumb, .thumbeb => switch (target.os.tag) { .netbsd => .{ .arm_apcs = .{} }, + .watchos => .{ .arm_aapcs16_vfp = .{} }, else => switch (target.abi.floatAbi()) { .soft => .{ .arm_aapcs = .{} }, .hard => .{ .arm_aapcs_vfp = .{} }, From baf60426d48adbd938406f07bbbd0dfdf012943b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Mon, 28 Oct 2024 23:42:47 +0100 Subject: [PATCH 03/11] std.Target: Rename amdgpu module to amdgcn. This was an inconsistency left over from c825b567b26c475e058e074e5d22af006854fab6. --- CMakeLists.txt | 2 +- lib/compiler_rt/atomics.zig | 2 +- lib/std/Target.zig | 11 +++++------ lib/std/Target/{amdgpu.zig => amdgcn.zig} | 0 tools/update_clang_options.zig | 2 +- tools/update_cpu_features.zig | 2 +- 6 files changed, 9 insertions(+), 10 deletions(-) rename lib/std/Target/{amdgpu.zig => amdgcn.zig} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index be92fb9f9c..ca20a702bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -376,7 +376,7 @@ set(ZIG_STAGE2_SOURCES lib/std/Target.zig lib/std/Target/Query.zig lib/std/Target/aarch64.zig - lib/std/Target/amdgpu.zig + lib/std/Target/amdgcn.zig lib/std/Target/arm.zig lib/std/Target/avr.zig lib/std/Target/bpf.zig diff --git a/lib/compiler_rt/atomics.zig b/lib/compiler_rt/atomics.zig index db1e9b4b70..2cec398732 100644 --- a/lib/compiler_rt/atomics.zig +++ b/lib/compiler_rt/atomics.zig @@ -42,7 +42,7 @@ const largest_atomic_size = switch (arch) { // Objects smaller than this threshold are implemented in terms of compare-exchange // of a larger value. const smallest_atomic_fetch_exch_size = switch (arch) { - // On AMDGPU, there are no instructions for atomic operations other than load and store + // On AMDGCN, there are no instructions for atomic operations other than load and store // (as of LLVM 15), and so these need to be implemented in terms of atomic CAS. .amdgcn => @sizeOf(u32), else => @sizeOf(u8), diff --git a/lib/std/Target.zig b/lib/std/Target.zig index eef52c889f..9e194c72ce 100644 --- a/lib/std/Target.zig +++ b/lib/std/Target.zig @@ -719,7 +719,7 @@ pub const Os = struct { pub const aarch64 = @import("Target/aarch64.zig"); pub const arc = @import("Target/arc.zig"); -pub const amdgpu = @import("Target/amdgpu.zig"); +pub const amdgcn = @import("Target/amdgcn.zig"); pub const arm = @import("Target/arm.zig"); pub const avr = @import("Target/avr.zig"); pub const bpf = @import("Target/bpf.zig"); @@ -1591,7 +1591,6 @@ pub const Cpu = struct { .loongarch32, .loongarch64 => "loongarch", .mips, .mipsel, .mips64, .mips64el => "mips", .powerpc, .powerpcle, .powerpc64, .powerpc64le => "powerpc", - .amdgcn => "amdgpu", .riscv32, .riscv64 => "riscv", .sparc, .sparc64 => "sparc", .s390x => "s390x", @@ -1620,7 +1619,7 @@ pub const Cpu = struct { .mips, .mipsel, .mips64, .mips64el => &mips.all_features, .msp430 => &msp430.all_features, .powerpc, .powerpcle, .powerpc64, .powerpc64le => &powerpc.all_features, - .amdgcn => &amdgpu.all_features, + .amdgcn => &amdgcn.all_features, .riscv32, .riscv64 => &riscv.all_features, .sparc, .sparc64 => &sparc.all_features, .spirv, .spirv32, .spirv64 => &spirv.all_features, @@ -1652,7 +1651,7 @@ pub const Cpu = struct { .mips, .mipsel, .mips64, .mips64el => comptime allCpusFromDecls(mips.cpu), .msp430 => comptime allCpusFromDecls(msp430.cpu), .powerpc, .powerpcle, .powerpc64, .powerpc64le => comptime allCpusFromDecls(powerpc.cpu), - .amdgcn => comptime allCpusFromDecls(amdgpu.cpu), + .amdgcn => comptime allCpusFromDecls(amdgcn.cpu), .riscv32, .riscv64 => comptime allCpusFromDecls(riscv.cpu), .sparc, .sparc64 => comptime allCpusFromDecls(sparc.cpu), .spirv, .spirv32, .spirv64 => comptime allCpusFromDecls(spirv.cpu), @@ -1890,7 +1889,7 @@ pub const Cpu = struct { }; }; return switch (arch) { - .amdgcn => &amdgpu.cpu.gfx600, + .amdgcn => &amdgcn.cpu.gfx600, .arc => &arc.cpu.generic, .arm, .armeb, .thumb, .thumbeb => &arm.cpu.generic, .aarch64, .aarch64_be => &aarch64.cpu.generic, @@ -1939,7 +1938,7 @@ pub const Cpu = struct { /// `Os.Tag.freestanding`. pub fn baseline(arch: Arch, os: Os) *const Model { return switch (arch) { - .amdgcn => &amdgpu.cpu.gfx906, + .amdgcn => &amdgcn.cpu.gfx906, .arm, .armeb, .thumb, .thumbeb => &arm.cpu.baseline, .aarch64 => switch (os.tag) { .bridgeos, .driverkit, .macos => &aarch64.cpu.apple_m1, diff --git a/lib/std/Target/amdgpu.zig b/lib/std/Target/amdgcn.zig similarity index 100% rename from lib/std/Target/amdgpu.zig rename to lib/std/Target/amdgcn.zig diff --git a/tools/update_clang_options.zig b/tools/update_clang_options.zig index 3d32e4c7e1..637c9a5eaf 100644 --- a/tools/update_clang_options.zig +++ b/tools/update_clang_options.zig @@ -576,7 +576,7 @@ fn knownOption(name: []const u8) ?[]const u8 { const cpu_targets = struct { pub const aarch64 = std.Target.aarch64; - pub const amdgpu = std.Target.amdgpu; + pub const amdgcn = std.Target.amdgcn; pub const arc = std.Target.arc; pub const arm = std.Target.arm; pub const avr = std.Target.avr; diff --git a/tools/update_cpu_features.zig b/tools/update_cpu_features.zig index 2390a00575..07d66213ff 100644 --- a/tools/update_cpu_features.zig +++ b/tools/update_cpu_features.zig @@ -390,7 +390,7 @@ const llvm_targets = [_]LlvmTarget{ }, }, .{ - .zig_name = "amdgpu", + .zig_name = "amdgcn", .llvm_name = "AMDGPU", .td_name = "AMDGPU.td", .feature_overrides = &.{ From 8a2d960627dc5362da2aa4093f58665adb6b9b4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Mon, 28 Oct 2024 22:15:44 +0100 Subject: [PATCH 04/11] start: Fix a calling convention check to use eql(). Also modernize some callconv uses. Closes #21813. --- lib/std/start.zig | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/std/start.zig b/lib/std/start.zig index c5664cbf0f..bb62d1a282 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -29,7 +29,7 @@ comptime { if (simplified_logic) { if (builtin.output_mode == .Exe) { if ((builtin.link_libc or builtin.object_format == .c) and @hasDecl(root, "main")) { - if (@typeInfo(@TypeOf(root.main)).@"fn".calling_convention != .C) { + if (!@typeInfo(@TypeOf(root.main)).@"fn".calling_convention.eql(.c)) { @export(&main2, .{ .name = "main" }); } } else if (builtin.os.tag == .windows) { @@ -96,7 +96,7 @@ comptime { // Simplified start code for stage2 until it supports more language features /// -fn main2() callconv(.C) c_int { +fn main2() callconv(.c) c_int { root.main(); return 0; } @@ -110,11 +110,11 @@ fn callMain2() noreturn { exit2(0); } -fn spirvMain2() callconv(.Kernel) void { +fn spirvMain2() callconv(.kernel) void { root.main(); } -fn wWinMainCRTStartup2() callconv(.C) noreturn { +fn wWinMainCRTStartup2() callconv(.c) noreturn { root.main(); exit2(0); } @@ -172,7 +172,7 @@ fn _DllMainCRTStartup( hinstDLL: std.os.windows.HINSTANCE, fdwReason: std.os.windows.DWORD, lpReserved: std.os.windows.LPVOID, -) callconv(std.os.windows.WINAPI) std.os.windows.BOOL { +) callconv(.winapi) std.os.windows.BOOL { if (!builtin.single_threaded and !builtin.link_libc) { _ = @import("os/windows/tls.zig"); } @@ -184,13 +184,13 @@ fn _DllMainCRTStartup( return std.os.windows.TRUE; } -fn wasm_freestanding_start() callconv(.C) void { +fn wasm_freestanding_start() callconv(.c) void { // This is marked inline because for some reason LLVM in // release mode fails to inline it, and we want fewer call frames in stack traces. _ = @call(.always_inline, callMain, .{}); } -fn wasi_start() callconv(.C) void { +fn wasi_start() callconv(.c) void { // The function call is marked inline because for some reason LLVM in // release mode fails to inline it, and we want fewer call frames in stack traces. switch (builtin.wasi_exec_model) { @@ -199,7 +199,7 @@ fn wasi_start() callconv(.C) void { } } -fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) callconv(.C) usize { +fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) callconv(.c) usize { uefi.handle = handle; uefi.system_table = system_table; @@ -221,7 +221,7 @@ fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) callconv } } -fn _start() callconv(.Naked) noreturn { +fn _start() callconv(.naked) noreturn { // TODO set Top of Stack on non x86_64-plan9 if (native_os == .plan9 and native_arch == .x86_64) { // from /sys/src/libc/amd64/main9.s @@ -447,7 +447,7 @@ fn wWinMainCRTStartup() callconv(.withStackAlign(.winapi, 1)) noreturn { std.os.windows.ntdll.RtlExitUserProcess(@as(std.os.windows.UINT, @bitCast(result))); } -fn posixCallMainAndExit(argc_argv_ptr: [*]usize) callconv(.C) noreturn { +fn posixCallMainAndExit(argc_argv_ptr: [*]usize) callconv(.c) noreturn { // We're not ready to panic until thread local storage is initialized. @setRuntimeSafety(false); // Code coverage instrumentation might try to use thread local variables. @@ -514,11 +514,11 @@ fn posixCallMainAndExit(argc_argv_ptr: [*]usize) callconv(.C) noreturn { // to ask for more stack space. expandStackSize(phdrs); - const opt_init_array_start = @extern([*]*const fn () callconv(.C) void, .{ + const opt_init_array_start = @extern([*]*const fn () callconv(.c) void, .{ .name = "__init_array_start", .linkage = .weak, }); - const opt_init_array_end = @extern([*]*const fn () callconv(.C) void, .{ + const opt_init_array_end = @extern([*]*const fn () callconv(.c) void, .{ .name = "__init_array_end", .linkage = .weak, }); @@ -577,7 +577,7 @@ inline fn callMainWithArgs(argc: usize, argv: [*][*:0]u8, envp: [][*:0]u8) u8 { return callMain(); } -fn main(c_argc: c_int, c_argv: [*][*:0]c_char, c_envp: [*:null]?[*:0]c_char) callconv(.C) c_int { +fn main(c_argc: c_int, c_argv: [*][*:0]c_char, c_envp: [*:null]?[*:0]c_char) callconv(.c) c_int { var env_count: usize = 0; while (c_envp[env_count] != null) : (env_count += 1) {} const envp = @as([*][*:0]u8, @ptrCast(c_envp))[0..env_count]; @@ -592,7 +592,7 @@ fn main(c_argc: c_int, c_argv: [*][*:0]c_char, c_envp: [*:null]?[*:0]c_char) cal return callMainWithArgs(@as(usize, @intCast(c_argc)), @as([*][*:0]u8, @ptrCast(c_argv)), envp); } -fn mainWithoutEnv(c_argc: c_int, c_argv: [*][*:0]c_char) callconv(.C) c_int { +fn mainWithoutEnv(c_argc: c_int, c_argv: [*][*:0]c_char) callconv(.c) c_int { std.os.argv = @as([*][*:0]u8, @ptrCast(c_argv))[0..@as(usize, @intCast(c_argc))]; return callMain(); } @@ -702,4 +702,4 @@ fn maybeIgnoreSigpipe() void { } } -fn noopSigHandler(_: i32) callconv(.C) void {} +fn noopSigHandler(_: i32) callconv(.c) void {} From 82e82b6267f314e76b1030310032f2c0ff5caa93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Fri, 1 Nov 2024 01:08:05 +0100 Subject: [PATCH 05/11] start: Fix callconv for the wWinMainCRTStartup symbol. This just uses the C calling convention in the vcruntime sources. --- lib/std/start.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/std/start.zig b/lib/std/start.zig index bb62d1a282..02884b2c2a 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -426,7 +426,7 @@ fn _start() callconv(.naked) noreturn { ); } -fn WinStartup() callconv(.withStackAlign(.winapi, 1)) noreturn { +fn WinStartup() callconv(.withStackAlign(.c, 1)) noreturn { if (!builtin.single_threaded and !builtin.link_libc) { _ = @import("os/windows/tls.zig"); } @@ -436,7 +436,7 @@ fn WinStartup() callconv(.withStackAlign(.winapi, 1)) noreturn { std.os.windows.ntdll.RtlExitUserProcess(callMain()); } -fn wWinMainCRTStartup() callconv(.withStackAlign(.winapi, 1)) noreturn { +fn wWinMainCRTStartup() callconv(.withStackAlign(.c, 1)) noreturn { if (!builtin.single_threaded and !builtin.link_libc) { _ = @import("os/windows/tls.zig"); } From 5a6cc552e362fccfd29570a2473573748f86c424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Fri, 1 Nov 2024 01:06:00 +0100 Subject: [PATCH 06/11] std.os.windows: Fix some incorrect callconv specifiers. Closes #21869. --- lib/std/Thread.zig | 6 +++--- lib/std/os/windows.zig | 28 ++++++++++++++-------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig index 0244eb6d41..aa21a8a0ea 100644 --- a/lib/std/Thread.zig +++ b/lib/std/Thread.zig @@ -589,7 +589,7 @@ const WindowsThreadImpl = struct { fn_args: Args, thread: ThreadCompletion, - fn entryFn(raw_ptr: windows.PVOID) callconv(.C) windows.DWORD { + fn entryFn(raw_ptr: windows.PVOID) callconv(.winapi) windows.DWORD { const self: *@This() = @ptrCast(@alignCast(raw_ptr)); defer switch (self.thread.completion.swap(.completed, .seq_cst)) { .running => {}, @@ -749,7 +749,7 @@ const PosixThreadImpl = struct { const allocator = std.heap.c_allocator; const Instance = struct { - fn entryFn(raw_arg: ?*anyopaque) callconv(.C) ?*anyopaque { + fn entryFn(raw_arg: ?*anyopaque) callconv(.c) ?*anyopaque { const args_ptr: *Args = @ptrCast(@alignCast(raw_arg)); defer allocator.destroy(args_ptr); return callFn(f, args_ptr.*); @@ -1363,7 +1363,7 @@ const LinuxThreadImpl = struct { fn_args: Args, thread: ThreadCompletion, - fn entryFn(raw_arg: usize) callconv(.C) u8 { + fn entryFn(raw_arg: usize) callconv(.c) u8 { const self = @as(*@This(), @ptrFromInt(raw_arg)); defer switch (self.thread.completion.swap(.completed, .seq_cst)) { .running => {}, diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index dbd6df46b7..6903bbf9a8 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -2101,8 +2101,8 @@ pub fn UnlockFile( /// This is a workaround for the C backend until zig has the ability to put /// C code in inline assembly. -extern fn zig_x86_windows_teb() callconv(.C) *anyopaque; -extern fn zig_x86_64_windows_teb() callconv(.C) *anyopaque; +extern fn zig_x86_windows_teb() callconv(.c) *anyopaque; +extern fn zig_x86_64_windows_teb() callconv(.c) *anyopaque; pub fn teb() *TEB { return switch (native_arch) { @@ -3567,7 +3567,7 @@ pub const MEM_RESERVE_PLACEHOLDERS = 0x2; pub const MEM_DECOMMIT = 0x4000; pub const MEM_RELEASE = 0x8000; -pub const PTHREAD_START_ROUTINE = *const fn (LPVOID) callconv(.C) DWORD; +pub const PTHREAD_START_ROUTINE = *const fn (LPVOID) callconv(.winapi) DWORD; pub const LPTHREAD_START_ROUTINE = PTHREAD_START_ROUTINE; pub const WIN32_FIND_DATAW = extern struct { @@ -3745,7 +3745,7 @@ pub const IMAGE_TLS_DIRECTORY = extern struct { pub const IMAGE_TLS_DIRECTORY64 = IMAGE_TLS_DIRECTORY; pub const IMAGE_TLS_DIRECTORY32 = IMAGE_TLS_DIRECTORY; -pub const PIMAGE_TLS_CALLBACK = ?*const fn (PVOID, DWORD, PVOID) callconv(.C) void; +pub const PIMAGE_TLS_CALLBACK = ?*const fn (PVOID, DWORD, PVOID) callconv(.winapi) void; pub const PROV_RSA_FULL = 1; @@ -3843,7 +3843,7 @@ pub const RTL_QUERY_REGISTRY_ROUTINE = ?*const fn ( ULONG, ?*anyopaque, ?*anyopaque, -) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; /// Path is a full path pub const RTL_REGISTRY_ABSOLUTE = 0; @@ -3940,7 +3940,7 @@ pub const FILE_ACTION_MODIFIED = 0x00000003; pub const FILE_ACTION_RENAMED_OLD_NAME = 0x00000004; pub const FILE_ACTION_RENAMED_NEW_NAME = 0x00000005; -pub const LPOVERLAPPED_COMPLETION_ROUTINE = ?*const fn (DWORD, DWORD, *OVERLAPPED) callconv(.C) void; +pub const LPOVERLAPPED_COMPLETION_ROUTINE = ?*const fn (DWORD, DWORD, *OVERLAPPED) callconv(.winapi) void; pub const FileNotifyChangeFilter = packed struct(DWORD) { file_name: bool = false, @@ -4003,7 +4003,7 @@ pub const RTL_CRITICAL_SECTION = extern struct { pub const CRITICAL_SECTION = RTL_CRITICAL_SECTION; pub const INIT_ONCE = RTL_RUN_ONCE; pub const INIT_ONCE_STATIC_INIT = RTL_RUN_ONCE_INIT; -pub const INIT_ONCE_FN = *const fn (InitOnce: *INIT_ONCE, Parameter: ?*anyopaque, Context: ?*anyopaque) callconv(.C) BOOL; +pub const INIT_ONCE_FN = *const fn (InitOnce: *INIT_ONCE, Parameter: ?*anyopaque, Context: ?*anyopaque) callconv(.winapi) BOOL; pub const RTL_RUN_ONCE = extern struct { Ptr: ?*anyopaque, @@ -4467,7 +4467,7 @@ pub const EXCEPTION_POINTERS = extern struct { ContextRecord: *CONTEXT, }; -pub const VECTORED_EXCEPTION_HANDLER = *const fn (ExceptionInfo: *EXCEPTION_POINTERS) callconv(WINAPI) c_long; +pub const VECTORED_EXCEPTION_HANDLER = *const fn (ExceptionInfo: *EXCEPTION_POINTERS) callconv(.winapi) c_long; pub const EXCEPTION_DISPOSITION = i32; pub const EXCEPTION_ROUTINE = *const fn ( @@ -4475,7 +4475,7 @@ pub const EXCEPTION_ROUTINE = *const fn ( EstablisherFrame: PVOID, ContextRecord: *(Self.CONTEXT), DispatcherContext: PVOID, -) callconv(WINAPI) EXCEPTION_DISPOSITION; +) callconv(.winapi) EXCEPTION_DISPOSITION; pub const UNWIND_HISTORY_TABLE_SIZE = 12; pub const UNWIND_HISTORY_TABLE_ENTRY = extern struct { @@ -4851,7 +4851,7 @@ pub const RTL_DRIVE_LETTER_CURDIR = extern struct { DosPath: UNICODE_STRING, }; -pub const PPS_POST_PROCESS_INIT_ROUTINE = ?*const fn () callconv(.C) void; +pub const PPS_POST_PROCESS_INIT_ROUTINE = ?*const fn () callconv(.winapi) void; pub const FILE_DIRECTORY_INFORMATION = extern struct { NextEntryOffset: ULONG, @@ -4905,7 +4905,7 @@ pub fn FileInformationIterator(comptime FileInformationType: type) type { }; } -pub const IO_APC_ROUTINE = *const fn (PVOID, *IO_STATUS_BLOCK, ULONG) callconv(.C) void; +pub const IO_APC_ROUTINE = *const fn (PVOID, *IO_STATUS_BLOCK, ULONG) callconv(.winapi) void; pub const CURDIR = extern struct { DosPath: UNICODE_STRING, @@ -5009,8 +5009,8 @@ pub const ENUM_PAGE_FILE_INFORMATION = extern struct { PeakUsage: SIZE_T, }; -pub const PENUM_PAGE_FILE_CALLBACKW = ?*const fn (?LPVOID, *ENUM_PAGE_FILE_INFORMATION, LPCWSTR) callconv(.C) BOOL; -pub const PENUM_PAGE_FILE_CALLBACKA = ?*const fn (?LPVOID, *ENUM_PAGE_FILE_INFORMATION, LPCSTR) callconv(.C) BOOL; +pub const PENUM_PAGE_FILE_CALLBACKW = ?*const fn (?LPVOID, *ENUM_PAGE_FILE_INFORMATION, LPCWSTR) callconv(.winapi) BOOL; +pub const PENUM_PAGE_FILE_CALLBACKA = ?*const fn (?LPVOID, *ENUM_PAGE_FILE_INFORMATION, LPCSTR) callconv(.winapi) BOOL; pub const PSAPI_WS_WATCH_INFORMATION_EX = extern struct { BasicInfo: PSAPI_WS_WATCH_INFORMATION, @@ -5122,7 +5122,7 @@ pub const CTRL_CLOSE_EVENT: DWORD = 2; pub const CTRL_LOGOFF_EVENT: DWORD = 5; pub const CTRL_SHUTDOWN_EVENT: DWORD = 6; -pub const HANDLER_ROUTINE = *const fn (dwCtrlType: DWORD) callconv(WINAPI) BOOL; +pub const HANDLER_ROUTINE = *const fn (dwCtrlType: DWORD) callconv(.winapi) BOOL; /// Processor feature enumeration. pub const PF = enum(DWORD) { From be8a527eb2ac2f0527e33ce9e34c3bccdfee76c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Fri, 1 Nov 2024 01:06:45 +0100 Subject: [PATCH 07/11] std.os.windows: Deprecate WINAPI in favor of CallingConvention.winapi. --- lib/std/debug.zig | 2 +- lib/std/os/windows.zig | 1 + lib/std/os/windows/advapi32.zig | 13 +- lib/std/os/windows/crypt32.zig | 7 +- lib/std/os/windows/kernel32.zig | 191 ++++++++++++++-------------- lib/std/os/windows/ntdll.zig | 93 +++++++------- lib/std/os/windows/test.zig | 2 +- lib/std/os/windows/ws2_32.zig | 213 ++++++++++++++++---------------- src/crash_report.zig | 2 +- 9 files changed, 260 insertions(+), 264 deletions(-) diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 8527677ebb..5b18f37b6a 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -1344,7 +1344,7 @@ fn dumpSegfaultInfoPosix(sig: i32, code: i32, addr: usize, ctx_ptr: ?*anyopaque) } } -fn handleSegfaultWindows(info: *windows.EXCEPTION_POINTERS) callconv(windows.WINAPI) c_long { +fn handleSegfaultWindows(info: *windows.EXCEPTION_POINTERS) callconv(.winapi) c_long { switch (info.ExceptionRecord.ExceptionCode) { windows.EXCEPTION_DATATYPE_MISALIGNMENT => handleSegfaultWindowsExtra(info, 0, "Unaligned Memory Access"), windows.EXCEPTION_ACCESS_VIOLATION => handleSegfaultWindowsExtra(info, 1, null), diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index 6903bbf9a8..010bbcd005 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -2824,6 +2824,7 @@ pub const STD_OUTPUT_HANDLE = maxInt(DWORD) - 11 + 1; /// The standard error device. Initially, this is the active console screen buffer, CONOUT$. pub const STD_ERROR_HANDLE = maxInt(DWORD) - 12 + 1; +/// Deprecated; use `std.builtin.CallingConvention.winapi` instead. pub const WINAPI: std.builtin.CallingConvention = .winapi; pub const BOOL = c_int; diff --git a/lib/std/os/windows/advapi32.zig b/lib/std/os/windows/advapi32.zig index 3419fdc95c..bf438e2776 100644 --- a/lib/std/os/windows/advapi32.zig +++ b/lib/std/os/windows/advapi32.zig @@ -8,7 +8,6 @@ const LPCWSTR = windows.LPCWSTR; const LSTATUS = windows.LSTATUS; const REGSAM = windows.REGSAM; const ULONG = windows.ULONG; -const WINAPI = windows.WINAPI; pub extern "advapi32" fn RegOpenKeyExW( hKey: HKEY, @@ -16,7 +15,7 @@ pub extern "advapi32" fn RegOpenKeyExW( ulOptions: DWORD, samDesired: REGSAM, phkResult: *HKEY, -) callconv(WINAPI) LSTATUS; +) callconv(.winapi) LSTATUS; pub extern "advapi32" fn RegQueryValueExW( hKey: HKEY, @@ -25,13 +24,13 @@ pub extern "advapi32" fn RegQueryValueExW( lpType: ?*DWORD, lpData: ?*BYTE, lpcbData: ?*DWORD, -) callconv(WINAPI) LSTATUS; +) callconv(.winapi) LSTATUS; -pub extern "advapi32" fn RegCloseKey(hKey: HKEY) callconv(WINAPI) LSTATUS; +pub extern "advapi32" fn RegCloseKey(hKey: HKEY) callconv(.winapi) LSTATUS; // RtlGenRandom is known as SystemFunction036 under advapi32 // http://msdn.microsoft.com/en-us/library/windows/desktop/aa387694.aspx */ -pub extern "advapi32" fn SystemFunction036(output: [*]u8, length: ULONG) callconv(WINAPI) BOOL; +pub extern "advapi32" fn SystemFunction036(output: [*]u8, length: ULONG) callconv(.winapi) BOOL; pub const RtlGenRandom = SystemFunction036; pub const RRF = struct { @@ -62,7 +61,7 @@ pub extern "advapi32" fn RegGetValueW( pdwType: ?*DWORD, pvData: ?*anyopaque, pcbData: ?*DWORD, -) callconv(WINAPI) LSTATUS; +) callconv(.winapi) LSTATUS; pub extern "advapi32" fn RegLoadAppKeyW( lpFile: LPCWSTR, @@ -70,4 +69,4 @@ pub extern "advapi32" fn RegLoadAppKeyW( samDesired: REGSAM, dwOptions: DWORD, reserved: DWORD, -) callconv(WINAPI) LSTATUS; +) callconv(.winapi) LSTATUS; diff --git a/lib/std/os/windows/crypt32.zig b/lib/std/os/windows/crypt32.zig index 9500d4b261..37d8110405 100644 --- a/lib/std/os/windows/crypt32.zig +++ b/lib/std/os/windows/crypt32.zig @@ -4,7 +4,6 @@ const BOOL = windows.BOOL; const DWORD = windows.DWORD; const BYTE = windows.BYTE; const LPCWSTR = windows.LPCWSTR; -const WINAPI = windows.WINAPI; pub const CERT_INFO = *opaque {}; pub const HCERTSTORE = *opaque {}; @@ -19,14 +18,14 @@ pub const CERT_CONTEXT = extern struct { pub extern "crypt32" fn CertOpenSystemStoreW( _: ?*const anyopaque, szSubsystemProtocol: LPCWSTR, -) callconv(WINAPI) ?HCERTSTORE; +) callconv(.winapi) ?HCERTSTORE; pub extern "crypt32" fn CertCloseStore( hCertStore: HCERTSTORE, dwFlags: DWORD, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; pub extern "crypt32" fn CertEnumCertificatesInStore( hCertStore: HCERTSTORE, pPrevCertContext: ?*CERT_CONTEXT, -) callconv(WINAPI) ?*CERT_CONTEXT; +) callconv(.winapi) ?*CERT_CONTEXT; diff --git a/lib/std/os/windows/kernel32.zig b/lib/std/os/windows/kernel32.zig index b8ae72af55..f2da7957a8 100644 --- a/lib/std/os/windows/kernel32.zig +++ b/lib/std/os/windows/kernel32.zig @@ -41,7 +41,6 @@ const VECTORED_EXCEPTION_HANDLER = windows.VECTORED_EXCEPTION_HANDLER; const WCHAR = windows.WCHAR; const WIN32_FIND_DATAW = windows.WIN32_FIND_DATAW; const Win32Error = windows.Win32Error; -const WINAPI = windows.WINAPI; const WORD = windows.WORD; // I/O - Filesystem @@ -55,18 +54,18 @@ pub extern "kernel32" fn ReadDirectoryChangesW( lpBytesReturned: ?*windows.DWORD, lpOverlapped: ?*windows.OVERLAPPED, lpCompletionRoutine: windows.LPOVERLAPPED_COMPLETION_ROUTINE, -) callconv(windows.WINAPI) windows.BOOL; +) callconv(.winapi) windows.BOOL; // TODO: Wrapper around NtCancelIoFile. pub extern "kernel32" fn CancelIo( hFile: HANDLE, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; // TODO: Wrapper around NtCancelIoFileEx. pub extern "kernel32" fn CancelIoEx( hFile: HANDLE, lpOverlapped: ?*OVERLAPPED, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; pub extern "kernel32" fn CreateFileW( lpFileName: LPCWSTR, @@ -76,7 +75,7 @@ pub extern "kernel32" fn CreateFileW( dwCreationDisposition: DWORD, dwFlagsAndAttributes: DWORD, hTemplateFile: ?HANDLE, -) callconv(WINAPI) HANDLE; +) callconv(.winapi) HANDLE; // TODO A bunch of logic around NtCreateNamedPipe pub extern "kernel32" fn CreateNamedPipeW( @@ -88,16 +87,16 @@ pub extern "kernel32" fn CreateNamedPipeW( nInBufferSize: DWORD, nDefaultTimeOut: DWORD, lpSecurityAttributes: ?*const SECURITY_ATTRIBUTES, -) callconv(WINAPI) HANDLE; +) callconv(.winapi) HANDLE; pub extern "kernel32" fn FindFirstFileW( lpFileName: LPCWSTR, lpFindFileData: *WIN32_FIND_DATAW, -) callconv(WINAPI) HANDLE; +) callconv(.winapi) HANDLE; pub extern "kernel32" fn FindClose( hFindFile: HANDLE, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; // TODO: Wrapper around RtlGetFullPathName_UEx pub extern "kernel32" fn GetFullPathNameW( @@ -105,18 +104,18 @@ pub extern "kernel32" fn GetFullPathNameW( nBufferLength: DWORD, lpBuffer: LPWSTR, lpFilePart: ?*?LPWSTR, -) callconv(WINAPI) DWORD; +) callconv(.winapi) DWORD; // TODO: Matches `STD_*_HANDLE` to peb().ProcessParameters.Standard* pub extern "kernel32" fn GetStdHandle( nStdHandle: DWORD, -) callconv(WINAPI) ?HANDLE; +) callconv(.winapi) ?HANDLE; pub extern "kernel32" fn MoveFileExW( lpExistingFileName: LPCWSTR, lpNewFileName: LPCWSTR, dwFlags: DWORD, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; // TODO: Wrapper around NtSetInformationFile + `FILE_POSITION_INFORMATION`. // `FILE_STANDARD_INFORMATION` is also used if dwMoveMethod is `FILE_END` @@ -125,7 +124,7 @@ pub extern "kernel32" fn SetFilePointerEx( liDistanceToMove: LARGE_INTEGER, lpNewFilePointer: ?*LARGE_INTEGER, dwMoveMethod: DWORD, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; // TODO: Wrapper around NtSetInformationFile + `FILE_BASIC_INFORMATION` pub extern "kernel32" fn SetFileTime( @@ -133,7 +132,7 @@ pub extern "kernel32" fn SetFileTime( lpCreationTime: ?*const FILETIME, lpLastAccessTime: ?*const FILETIME, lpLastWriteTime: ?*const FILETIME, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; pub extern "kernel32" fn WriteFile( in_hFile: HANDLE, @@ -141,35 +140,35 @@ pub extern "kernel32" fn WriteFile( in_nNumberOfBytesToWrite: DWORD, out_lpNumberOfBytesWritten: ?*DWORD, in_out_lpOverlapped: ?*OVERLAPPED, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; // TODO: wrapper for NtQueryInformationFile + `FILE_STANDARD_INFORMATION` pub extern "kernel32" fn GetFileSizeEx( hFile: HANDLE, lpFileSize: *LARGE_INTEGER, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; // TODO: Wrapper around GetStdHandle + NtFlushBuffersFile. pub extern "kernel32" fn FlushFileBuffers( hFile: HANDLE, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; // TODO: Wrapper around NtSetInformationFile + `FILE_IO_COMPLETION_NOTIFICATION_INFORMATION`. pub extern "kernel32" fn SetFileCompletionNotificationModes( FileHandle: HANDLE, Flags: UCHAR, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; // TODO: `RtlGetCurrentDirectory_U(nBufferLength * 2, lpBuffer)` pub extern "kernel32" fn GetCurrentDirectoryW( nBufferLength: DWORD, lpBuffer: ?[*]WCHAR, -) callconv(WINAPI) DWORD; +) callconv(.winapi) DWORD; // TODO: RtlDosPathNameToNtPathNameU_WithStatus + NtQueryAttributesFile. pub extern "kernel32" fn GetFileAttributesW( lpFileName: LPCWSTR, -) callconv(WINAPI) DWORD; +) callconv(.winapi) DWORD; pub extern "kernel32" fn ReadFile( hFile: HANDLE, @@ -177,12 +176,12 @@ pub extern "kernel32" fn ReadFile( nNumberOfBytesToRead: DWORD, lpNumberOfBytesRead: ?*DWORD, lpOverlapped: ?*OVERLAPPED, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; pub extern "kernel32" fn GetSystemDirectoryW( lpBuffer: LPWSTR, uSize: UINT, -) callconv(WINAPI) UINT; +) callconv(.winapi) UINT; // I/O - Kernel Objects @@ -192,7 +191,7 @@ pub extern "kernel32" fn CreateEventExW( lpName: ?LPCWSTR, dwFlags: DWORD, dwDesiredAccess: DWORD, -) callconv(WINAPI) ?HANDLE; +) callconv(.winapi) ?HANDLE; // TODO: Wrapper around GetStdHandle + NtDuplicateObject. pub extern "kernel32" fn DuplicateHandle( @@ -203,14 +202,14 @@ pub extern "kernel32" fn DuplicateHandle( dwDesiredAccess: DWORD, bInheritHandle: BOOL, dwOptions: DWORD, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; // TODO: Wrapper around GetStdHandle + NtQueryObject + NtSetInformationObject with .ObjectHandleFlagInformation. pub extern "kernel32" fn SetHandleInformation( hObject: HANDLE, dwMask: DWORD, dwFlags: DWORD, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; // TODO: Wrapper around NtRemoveIoCompletion. pub extern "kernel32" fn GetQueuedCompletionStatus( @@ -219,7 +218,7 @@ pub extern "kernel32" fn GetQueuedCompletionStatus( lpCompletionKey: *ULONG_PTR, lpOverlapped: *?*OVERLAPPED, dwMilliseconds: DWORD, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; // TODO: Wrapper around NtRemoveIoCompletionEx. pub extern "kernel32" fn GetQueuedCompletionStatusEx( @@ -229,7 +228,7 @@ pub extern "kernel32" fn GetQueuedCompletionStatusEx( ulNumEntriesRemoved: *ULONG, dwMilliseconds: DWORD, fAlertable: BOOL, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; // TODO: Wrapper around NtSetIoCompletion with `IoStatus = .SUCCESS`. pub extern "kernel32" fn PostQueuedCompletionStatus( @@ -237,7 +236,7 @@ pub extern "kernel32" fn PostQueuedCompletionStatus( dwNumberOfBytesTransferred: DWORD, dwCompletionKey: ULONG_PTR, lpOverlapped: ?*OVERLAPPED, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; // TODO: // GetOverlappedResultEx with bAlertable=false, which calls: GetStdHandle + WaitForSingleObjectEx. @@ -247,7 +246,7 @@ pub extern "kernel32" fn GetOverlappedResult( lpOverlapped: *OVERLAPPED, lpNumberOfBytesTransferred: *DWORD, bWait: BOOL, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; // TODO: Wrapper around NtCreateIoCompletion + NtSetInformationFile with FILE_COMPLETION_INFORMATION. // This would be better splitting into two functions. @@ -256,30 +255,30 @@ pub extern "kernel32" fn CreateIoCompletionPort( ExistingCompletionPort: ?HANDLE, CompletionKey: ULONG_PTR, NumberOfConcurrentThreads: DWORD, -) callconv(WINAPI) ?HANDLE; +) callconv(.winapi) ?HANDLE; // TODO: Forwarder to NtAddVectoredExceptionHandler. pub extern "kernel32" fn AddVectoredExceptionHandler( First: ULONG, Handler: ?VECTORED_EXCEPTION_HANDLER, -) callconv(WINAPI) ?LPVOID; +) callconv(.winapi) ?LPVOID; // TODO: Forwarder to NtRemoveVectoredExceptionHandler. pub extern "kernel32" fn RemoveVectoredExceptionHandler( Handle: HANDLE, -) callconv(WINAPI) ULONG; +) callconv(.winapi) ULONG; // TODO: Wrapper around RtlReportSilentProcessExit + NtTerminateProcess. pub extern "kernel32" fn TerminateProcess( hProcess: HANDLE, uExitCode: UINT, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; // TODO: WaitForSingleObjectEx with bAlertable=false. pub extern "kernel32" fn WaitForSingleObject( hHandle: HANDLE, dwMilliseconds: DWORD, -) callconv(WINAPI) DWORD; +) callconv(.winapi) DWORD; // TODO: Wrapper for GetStdHandle + NtWaitForSingleObject. // Sets up an activation context before calling NtWaitForSingleObject. @@ -287,7 +286,7 @@ pub extern "kernel32" fn WaitForSingleObjectEx( hHandle: HANDLE, dwMilliseconds: DWORD, bAlertable: BOOL, -) callconv(WINAPI) DWORD; +) callconv(.winapi) DWORD; // TODO: WaitForMultipleObjectsEx with alertable=false pub extern "kernel32" fn WaitForMultipleObjects( @@ -295,7 +294,7 @@ pub extern "kernel32" fn WaitForMultipleObjects( lpHandle: [*]const HANDLE, bWaitAll: BOOL, dwMilliseconds: DWORD, -) callconv(WINAPI) DWORD; +) callconv(.winapi) DWORD; // TODO: Wrapper around NtWaitForMultipleObjects. pub extern "kernel32" fn WaitForMultipleObjectsEx( @@ -304,7 +303,7 @@ pub extern "kernel32" fn WaitForMultipleObjectsEx( bWaitAll: BOOL, dwMilliseconds: DWORD, bAlertable: BOOL, -) callconv(WINAPI) DWORD; +) callconv(.winapi) DWORD; // Process Management @@ -319,57 +318,57 @@ pub extern "kernel32" fn CreateProcessW( lpCurrentDirectory: ?LPCWSTR, lpStartupInfo: *STARTUPINFOW, lpProcessInformation: *PROCESS_INFORMATION, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; // TODO: Fowarder to RtlExitUserProcess. pub extern "kernel32" fn ExitProcess( exit_code: UINT, -) callconv(WINAPI) noreturn; +) callconv(.winapi) noreturn; // TODO: SleepEx with bAlertable=false. pub extern "kernel32" fn Sleep( dwMilliseconds: DWORD, -) callconv(WINAPI) void; +) callconv(.winapi) void; // TODO: Wrapper around NtQueryInformationProcess with `PROCESS_BASIC_INFORMATION`. pub extern "kernel32" fn GetExitCodeProcess( hProcess: HANDLE, lpExitCode: *DWORD, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; // TODO: Already a wrapper for this, see `windows.GetCurrentProcess`. -pub extern "kernel32" fn GetCurrentProcess() callconv(WINAPI) HANDLE; +pub extern "kernel32" fn GetCurrentProcess() callconv(.winapi) HANDLE; // TODO: memcpy peb().ProcessParameters.Environment, mem.span(0). Requires locking the PEB. -pub extern "kernel32" fn GetEnvironmentStringsW() callconv(WINAPI) ?LPWSTR; +pub extern "kernel32" fn GetEnvironmentStringsW() callconv(.winapi) ?LPWSTR; // TODO: RtlFreeHeap on the output of GetEnvironmentStringsW. pub extern "kernel32" fn FreeEnvironmentStringsW( penv: LPWSTR, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; // TODO: Wrapper around RtlQueryEnvironmentVariable. pub extern "kernel32" fn GetEnvironmentVariableW( lpName: ?LPCWSTR, lpBuffer: ?[*]WCHAR, nSize: DWORD, -) callconv(WINAPI) DWORD; +) callconv(.winapi) DWORD; // TODO: Wrapper around RtlSetEnvironmentVar. pub extern "kernel32" fn SetEnvironmentVariableW( lpName: LPCWSTR, lpValue: ?LPCWSTR, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; pub extern "kernel32" fn CreateToolhelp32Snapshot( dwFlags: DWORD, th32ProcessID: DWORD, -) callconv(WINAPI) HANDLE; +) callconv(.winapi) HANDLE; // Threading // TODO: Already a wrapper for this, see `windows.GetCurrentThreadId`. -pub extern "kernel32" fn GetCurrentThreadId() callconv(WINAPI) DWORD; +pub extern "kernel32" fn GetCurrentThreadId() callconv(.winapi) DWORD; // TODO: CreateRemoteThread with hProcess=NtCurrentProcess(). pub extern "kernel32" fn CreateThread( @@ -379,64 +378,64 @@ pub extern "kernel32" fn CreateThread( lpParameter: ?LPVOID, dwCreationFlags: DWORD, lpThreadId: ?*DWORD, -) callconv(WINAPI) ?HANDLE; +) callconv(.winapi) ?HANDLE; // TODO: Wrapper around RtlDelayExecution. -pub extern "kernel32" fn SwitchToThread() callconv(WINAPI) BOOL; +pub extern "kernel32" fn SwitchToThread() callconv(.winapi) BOOL; // Locks, critical sections, initializers // TODO: Forwarder to RtlInitializeCriticalSection pub extern "kernel32" fn InitializeCriticalSection( lpCriticalSection: *CRITICAL_SECTION, -) callconv(WINAPI) void; +) callconv(.winapi) void; // TODO: Forwarder to RtlEnterCriticalSection pub extern "kernel32" fn EnterCriticalSection( lpCriticalSection: *CRITICAL_SECTION, -) callconv(WINAPI) void; +) callconv(.winapi) void; // TODO: Forwarder to RtlLeaveCriticalSection pub extern "kernel32" fn LeaveCriticalSection( lpCriticalSection: *CRITICAL_SECTION, -) callconv(WINAPI) void; +) callconv(.winapi) void; // TODO: Forwarder to RtlDeleteCriticalSection pub extern "kernel32" fn DeleteCriticalSection( lpCriticalSection: *CRITICAL_SECTION, -) callconv(WINAPI) void; +) callconv(.winapi) void; // TODO: Forwarder to RtlTryAcquireSRWLockExclusive pub extern "kernel32" fn TryAcquireSRWLockExclusive( SRWLock: *SRWLOCK, -) callconv(WINAPI) BOOLEAN; +) callconv(.winapi) BOOLEAN; // TODO: Forwarder to RtlAcquireSRWLockExclusive pub extern "kernel32" fn AcquireSRWLockExclusive( SRWLock: *SRWLOCK, -) callconv(WINAPI) void; +) callconv(.winapi) void; // TODO: Forwarder to RtlReleaseSRWLockExclusive pub extern "kernel32" fn ReleaseSRWLockExclusive( SRWLock: *SRWLOCK, -) callconv(WINAPI) void; +) callconv(.winapi) void; pub extern "kernel32" fn InitOnceExecuteOnce( InitOnce: *INIT_ONCE, InitFn: INIT_ONCE_FN, Parameter: ?*anyopaque, Context: ?*anyopaque, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; // TODO: Forwarder to RtlWakeConditionVariable pub extern "kernel32" fn WakeConditionVariable( ConditionVariable: *CONDITION_VARIABLE, -) callconv(WINAPI) void; +) callconv(.winapi) void; // TODO: Forwarder to RtlWakeAllConditionVariable pub extern "kernel32" fn WakeAllConditionVariable( ConditionVariable: *CONDITION_VARIABLE, -) callconv(WINAPI) void; +) callconv(.winapi) void; // TODO: // - dwMilliseconds -> LARGE_INTEGER. @@ -447,40 +446,40 @@ pub extern "kernel32" fn SleepConditionVariableSRW( SRWLock: *SRWLOCK, dwMilliseconds: DWORD, Flags: ULONG, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; // Console management pub extern "kernel32" fn GetConsoleMode( hConsoleHandle: HANDLE, lpMode: *DWORD, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; pub extern "kernel32" fn SetConsoleMode( hConsoleHandle: HANDLE, dwMode: DWORD, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; pub extern "kernel32" fn GetConsoleScreenBufferInfo( hConsoleOutput: HANDLE, lpConsoleScreenBufferInfo: *CONSOLE_SCREEN_BUFFER_INFO, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; pub extern "kernel32" fn SetConsoleTextAttribute( hConsoleOutput: HANDLE, wAttributes: WORD, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; pub extern "kernel32" fn SetConsoleCtrlHandler( HandlerRoutine: ?HANDLER_ROUTINE, Add: BOOL, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; pub extern "kernel32" fn SetConsoleOutputCP( wCodePageID: UINT, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; -pub extern "kernel32" fn GetConsoleOutputCP() callconv(WINAPI) UINT; +pub extern "kernel32" fn GetConsoleOutputCP() callconv(.winapi) UINT; pub extern "kernel32" fn FillConsoleOutputAttribute( hConsoleOutput: HANDLE, @@ -488,7 +487,7 @@ pub extern "kernel32" fn FillConsoleOutputAttribute( nLength: DWORD, dwWriteCoord: COORD, lpNumberOfAttrsWritten: *DWORD, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; pub extern "kernel32" fn FillConsoleOutputCharacterW( hConsoleOutput: HANDLE, @@ -496,12 +495,12 @@ pub extern "kernel32" fn FillConsoleOutputCharacterW( nLength: DWORD, dwWriteCoord: COORD, lpNumberOfCharsWritten: *DWORD, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; pub extern "kernel32" fn SetConsoleCursorPosition( hConsoleOutput: HANDLE, dwCursorPosition: COORD, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; pub extern "kernel32" fn WriteConsoleW( hConsoleOutput: HANDLE, @@ -509,7 +508,7 @@ pub extern "kernel32" fn WriteConsoleW( nNumberOfCharsToWrite: DWORD, lpNumberOfCharsWritten: ?*DWORD, lpReserved: ?LPVOID, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; pub extern "kernel32" fn ReadConsoleOutputCharacterW( hConsoleOutput: HANDLE, @@ -517,7 +516,7 @@ pub extern "kernel32" fn ReadConsoleOutputCharacterW( nLength: DWORD, dwReadCoord: COORD, lpNumberOfCharsRead: *DWORD, -) callconv(windows.WINAPI) BOOL; +) callconv(.winapi) BOOL; // Memory Mapping/Allocation @@ -526,12 +525,12 @@ pub extern "kernel32" fn HeapCreate( flOptions: DWORD, dwInitialSize: SIZE_T, dwMaximumSize: SIZE_T, -) callconv(WINAPI) ?HANDLE; +) callconv(.winapi) ?HANDLE; // TODO: Wrapper around RtlDestroyHeap (BOOLEAN -> BOOL). pub extern "kernel32" fn HeapDestroy( hHeap: HANDLE, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; // TODO: Forwarder to RtlReAllocateHeap. pub extern "kernel32" fn HeapReAlloc( @@ -539,28 +538,28 @@ pub extern "kernel32" fn HeapReAlloc( dwFlags: DWORD, lpMem: *anyopaque, dwBytes: SIZE_T, -) callconv(WINAPI) ?*anyopaque; +) callconv(.winapi) ?*anyopaque; // TODO: Fowrarder to RtlAllocateHeap. pub extern "kernel32" fn HeapAlloc( hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T, -) callconv(WINAPI) ?*anyopaque; +) callconv(.winapi) ?*anyopaque; // TODO: Fowrarder to RtlFreeHeap. pub extern "kernel32" fn HeapFree( hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; // TODO: Wrapper around RtlValidateHeap (BOOLEAN -> BOOL) pub extern "kernel32" fn HeapValidate( hHeap: HANDLE, dwFlags: DWORD, lpMem: ?*const anyopaque, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; // TODO: Wrapper around NtAllocateVirtualMemory. pub extern "kernel32" fn VirtualAlloc( @@ -568,7 +567,7 @@ pub extern "kernel32" fn VirtualAlloc( dwSize: SIZE_T, flAllocationType: DWORD, flProtect: DWORD, -) callconv(WINAPI) ?LPVOID; +) callconv(.winapi) ?LPVOID; // TODO: Wrapper around NtFreeVirtualMemory. // If the return value is .INVALID_PAGE_PROTECTION, calls RtlFlushSecureMemoryCache and try again. @@ -576,21 +575,21 @@ pub extern "kernel32" fn VirtualFree( lpAddress: ?LPVOID, dwSize: SIZE_T, dwFreeType: DWORD, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; // TODO: Wrapper around NtQueryVirtualMemory. pub extern "kernel32" fn VirtualQuery( lpAddress: ?LPVOID, lpBuffer: PMEMORY_BASIC_INFORMATION, dwLength: SIZE_T, -) callconv(WINAPI) SIZE_T; +) callconv(.winapi) SIZE_T; pub extern "kernel32" fn LocalFree( hMem: HLOCAL, -) callconv(WINAPI) ?HLOCAL; +) callconv(.winapi) ?HLOCAL; // TODO: Getter for peb.ProcessHeap -pub extern "kernel32" fn GetProcessHeap() callconv(WINAPI) ?HANDLE; +pub extern "kernel32" fn GetProcessHeap() callconv(.winapi) ?HANDLE; // Code Libraries/Modules @@ -599,49 +598,49 @@ pub extern "kernel32" fn GetModuleFileNameW( hModule: ?HMODULE, lpFilename: [*]WCHAR, nSize: DWORD, -) callconv(WINAPI) DWORD; +) callconv(.winapi) DWORD; extern "kernel32" fn K32GetModuleFileNameExW( hProcess: HANDLE, hModule: ?HMODULE, lpFilename: LPWSTR, nSize: DWORD, -) callconv(WINAPI) DWORD; +) callconv(.winapi) DWORD; pub const GetModuleFileNameExW = K32GetModuleFileNameExW; // TODO: Wrapper around ntdll.LdrGetDllHandle, which is a wrapper around LdrGetDllHandleEx pub extern "kernel32" fn GetModuleHandleW( lpModuleName: ?LPCWSTR, -) callconv(WINAPI) ?HMODULE; +) callconv(.winapi) ?HMODULE; pub extern "kernel32" fn Module32First( hSnapshot: HANDLE, lpme: *MODULEENTRY32, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; pub extern "kernel32" fn Module32Next( hSnapshot: HANDLE, lpme: *MODULEENTRY32, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; pub extern "kernel32" fn LoadLibraryW( lpLibFileName: LPCWSTR, -) callconv(WINAPI) ?HMODULE; +) callconv(.winapi) ?HMODULE; pub extern "kernel32" fn LoadLibraryExW( lpLibFileName: LPCWSTR, hFile: ?HANDLE, dwFlags: DWORD, -) callconv(WINAPI) ?HMODULE; +) callconv(.winapi) ?HMODULE; pub extern "kernel32" fn GetProcAddress( hModule: HMODULE, lpProcName: LPCSTR, -) callconv(WINAPI) ?FARPROC; +) callconv(.winapi) ?FARPROC; pub extern "kernel32" fn FreeLibrary( hModule: HMODULE, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; // Error Management @@ -653,15 +652,15 @@ pub extern "kernel32" fn FormatMessageW( lpBuffer: LPWSTR, nSize: DWORD, Arguments: ?*va_list, -) callconv(WINAPI) DWORD; +) callconv(.winapi) DWORD; // TODO: Getter for teb().LastErrorValue. -pub extern "kernel32" fn GetLastError() callconv(WINAPI) Win32Error; +pub extern "kernel32" fn GetLastError() callconv(.winapi) Win32Error; // TODO: Wrapper around RtlSetLastWin32Error. pub extern "kernel32" fn SetLastError( dwErrCode: Win32Error, -) callconv(WINAPI) void; +) callconv(.winapi) void; // Everything Else @@ -670,4 +669,4 @@ pub extern "kernel32" fn SetLastError( // Much better to use NtQuerySystemTime or NtQuerySystemTimePrecise for guaranteed 0.1ns precision. pub extern "kernel32" fn GetSystemTimeAsFileTime( lpSystemTimeAsFileTime: *FILETIME, -) callconv(WINAPI) void; +) callconv(.winapi) void; diff --git a/lib/std/os/windows/ntdll.zig b/lib/std/os/windows/ntdll.zig index 4683b1e887..b4c33a2e2d 100644 --- a/lib/std/os/windows/ntdll.zig +++ b/lib/std/os/windows/ntdll.zig @@ -5,7 +5,6 @@ const BOOL = windows.BOOL; const DWORD = windows.DWORD; const DWORD64 = windows.DWORD64; const ULONG = windows.ULONG; -const WINAPI = windows.WINAPI; const NTSTATUS = windows.NTSTATUS; const WORD = windows.WORD; const HANDLE = windows.HANDLE; @@ -44,7 +43,7 @@ pub extern "ntdll" fn NtQueryInformationProcess( ProcessInformation: *anyopaque, ProcessInformationLength: ULONG, ReturnLength: ?*ULONG, -) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; pub extern "ntdll" fn NtQueryInformationThread( ThreadHandle: HANDLE, @@ -52,37 +51,37 @@ pub extern "ntdll" fn NtQueryInformationThread( ThreadInformation: *anyopaque, ThreadInformationLength: ULONG, ReturnLength: ?*ULONG, -) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; pub extern "ntdll" fn NtQuerySystemInformation( SystemInformationClass: SYSTEM_INFORMATION_CLASS, SystemInformation: PVOID, SystemInformationLength: ULONG, ReturnLength: ?*ULONG, -) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; pub extern "ntdll" fn NtSetInformationThread( ThreadHandle: HANDLE, ThreadInformationClass: THREADINFOCLASS, ThreadInformation: *const anyopaque, ThreadInformationLength: ULONG, -) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; pub extern "ntdll" fn RtlGetVersion( lpVersionInformation: *RTL_OSVERSIONINFOW, -) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; pub extern "ntdll" fn RtlCaptureStackBackTrace( FramesToSkip: DWORD, FramesToCapture: DWORD, BackTrace: **anyopaque, BackTraceHash: ?*DWORD, -) callconv(WINAPI) WORD; -pub extern "ntdll" fn RtlCaptureContext(ContextRecord: *CONTEXT) callconv(WINAPI) void; +) callconv(.winapi) WORD; +pub extern "ntdll" fn RtlCaptureContext(ContextRecord: *CONTEXT) callconv(.winapi) void; pub extern "ntdll" fn RtlLookupFunctionEntry( ControlPc: DWORD64, ImageBase: *DWORD64, HistoryTable: *UNWIND_HISTORY_TABLE, -) callconv(WINAPI) ?*RUNTIME_FUNCTION; +) callconv(.winapi) ?*RUNTIME_FUNCTION; pub extern "ntdll" fn RtlVirtualUnwind( HandlerType: DWORD, ImageBase: DWORD64, @@ -92,33 +91,33 @@ pub extern "ntdll" fn RtlVirtualUnwind( HandlerData: *?PVOID, EstablisherFrame: *DWORD64, ContextPointers: ?*KNONVOLATILE_CONTEXT_POINTERS, -) callconv(WINAPI) *EXCEPTION_ROUTINE; +) callconv(.winapi) *EXCEPTION_ROUTINE; pub extern "ntdll" fn NtQueryInformationFile( FileHandle: HANDLE, IoStatusBlock: *IO_STATUS_BLOCK, FileInformation: *anyopaque, Length: ULONG, FileInformationClass: FILE_INFORMATION_CLASS, -) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; pub extern "ntdll" fn NtSetInformationFile( FileHandle: HANDLE, IoStatusBlock: *IO_STATUS_BLOCK, FileInformation: PVOID, Length: ULONG, FileInformationClass: FILE_INFORMATION_CLASS, -) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; pub extern "ntdll" fn NtQueryAttributesFile( ObjectAttributes: *OBJECT_ATTRIBUTES, FileAttributes: *FILE_BASIC_INFORMATION, -) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; -pub extern "ntdll" fn RtlQueryPerformanceCounter(PerformanceCounter: *LARGE_INTEGER) callconv(WINAPI) BOOL; -pub extern "ntdll" fn RtlQueryPerformanceFrequency(PerformanceFrequency: *LARGE_INTEGER) callconv(WINAPI) BOOL; +pub extern "ntdll" fn RtlQueryPerformanceCounter(PerformanceCounter: *LARGE_INTEGER) callconv(.winapi) BOOL; +pub extern "ntdll" fn RtlQueryPerformanceFrequency(PerformanceFrequency: *LARGE_INTEGER) callconv(.winapi) BOOL; pub extern "ntdll" fn NtQueryPerformanceCounter( PerformanceCounter: *LARGE_INTEGER, PerformanceFrequency: ?*LARGE_INTEGER, -) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; pub extern "ntdll" fn NtCreateFile( FileHandle: *HANDLE, @@ -132,7 +131,7 @@ pub extern "ntdll" fn NtCreateFile( CreateOptions: ULONG, EaBuffer: ?*anyopaque, EaLength: ULONG, -) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; pub extern "ntdll" fn NtCreateSection( SectionHandle: *HANDLE, DesiredAccess: ACCESS_MASK, @@ -141,7 +140,7 @@ pub extern "ntdll" fn NtCreateSection( SectionPageProtection: ULONG, AllocationAttributes: ULONG, FileHandle: ?HANDLE, -) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; pub extern "ntdll" fn NtMapViewOfSection( SectionHandle: HANDLE, ProcessHandle: HANDLE, @@ -153,11 +152,11 @@ pub extern "ntdll" fn NtMapViewOfSection( InheritDispostion: SECTION_INHERIT, AllocationType: ULONG, Win32Protect: ULONG, -) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; pub extern "ntdll" fn NtUnmapViewOfSection( ProcessHandle: HANDLE, BaseAddress: PVOID, -) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; pub extern "ntdll" fn NtDeviceIoControlFile( FileHandle: HANDLE, Event: ?HANDLE, @@ -169,7 +168,7 @@ pub extern "ntdll" fn NtDeviceIoControlFile( InputBufferLength: ULONG, OutputBuffer: ?PVOID, OutputBufferLength: ULONG, -) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; pub extern "ntdll" fn NtFsControlFile( FileHandle: HANDLE, Event: ?HANDLE, @@ -181,15 +180,15 @@ pub extern "ntdll" fn NtFsControlFile( InputBufferLength: ULONG, OutputBuffer: ?PVOID, OutputBufferLength: ULONG, -) callconv(WINAPI) NTSTATUS; -pub extern "ntdll" fn NtClose(Handle: HANDLE) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; +pub extern "ntdll" fn NtClose(Handle: HANDLE) callconv(.winapi) NTSTATUS; pub extern "ntdll" fn RtlDosPathNameToNtPathName_U( DosPathName: [*:0]const u16, NtPathName: *UNICODE_STRING, NtFileNamePart: ?*?[*:0]const u16, DirectoryInfo: ?*CURDIR, -) callconv(WINAPI) BOOL; -pub extern "ntdll" fn RtlFreeUnicodeString(UnicodeString: *UNICODE_STRING) callconv(WINAPI) void; +) callconv(.winapi) BOOL; +pub extern "ntdll" fn RtlFreeUnicodeString(UnicodeString: *UNICODE_STRING) callconv(.winapi) void; /// Returns the number of bytes written to `Buffer`. /// If the returned count is larger than `BufferByteLength`, the buffer was too small. @@ -199,7 +198,7 @@ pub extern "ntdll" fn RtlGetFullPathName_U( BufferByteLength: ULONG, Buffer: [*]u16, ShortName: ?*[*:0]const u16, -) callconv(windows.WINAPI) windows.ULONG; +) callconv(.winapi) windows.ULONG; pub extern "ntdll" fn NtQueryDirectoryFile( FileHandle: HANDLE, @@ -213,30 +212,30 @@ pub extern "ntdll" fn NtQueryDirectoryFile( ReturnSingleEntry: BOOLEAN, FileName: ?*UNICODE_STRING, RestartScan: BOOLEAN, -) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; pub extern "ntdll" fn NtCreateKeyedEvent( KeyedEventHandle: *HANDLE, DesiredAccess: ACCESS_MASK, ObjectAttributes: ?PVOID, Flags: ULONG, -) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; pub extern "ntdll" fn NtReleaseKeyedEvent( EventHandle: ?HANDLE, Key: ?*const anyopaque, Alertable: BOOLEAN, Timeout: ?*const LARGE_INTEGER, -) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; pub extern "ntdll" fn NtWaitForKeyedEvent( EventHandle: ?HANDLE, Key: ?*const anyopaque, Alertable: BOOLEAN, Timeout: ?*const LARGE_INTEGER, -) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; -pub extern "ntdll" fn RtlSetCurrentDirectory_U(PathName: *UNICODE_STRING) callconv(WINAPI) NTSTATUS; +pub extern "ntdll" fn RtlSetCurrentDirectory_U(PathName: *UNICODE_STRING) callconv(.winapi) NTSTATUS; pub extern "ntdll" fn NtQueryObject( Handle: HANDLE, @@ -244,7 +243,7 @@ pub extern "ntdll" fn NtQueryObject( ObjectInformation: PVOID, ObjectInformationLength: ULONG, ReturnLength: ?*ULONG, -) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; pub extern "ntdll" fn NtQueryVolumeInformationFile( FileHandle: HANDLE, @@ -252,32 +251,32 @@ pub extern "ntdll" fn NtQueryVolumeInformationFile( FsInformation: *anyopaque, Length: ULONG, FsInformationClass: FS_INFORMATION_CLASS, -) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; pub extern "ntdll" fn RtlWakeAddressAll( Address: ?*const anyopaque, -) callconv(WINAPI) void; +) callconv(.winapi) void; pub extern "ntdll" fn RtlWakeAddressSingle( Address: ?*const anyopaque, -) callconv(WINAPI) void; +) callconv(.winapi) void; pub extern "ntdll" fn RtlWaitOnAddress( Address: ?*const anyopaque, CompareAddress: ?*const anyopaque, AddressSize: SIZE_T, Timeout: ?*const LARGE_INTEGER, -) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; pub extern "ntdll" fn RtlEqualUnicodeString( String1: *const UNICODE_STRING, String2: *const UNICODE_STRING, CaseInSensitive: BOOLEAN, -) callconv(WINAPI) BOOLEAN; +) callconv(.winapi) BOOLEAN; pub extern "ntdll" fn RtlUpcaseUnicodeChar( SourceCharacter: u16, -) callconv(WINAPI) u16; +) callconv(.winapi) u16; pub extern "ntdll" fn NtLockFile( FileHandle: HANDLE, @@ -290,7 +289,7 @@ pub extern "ntdll" fn NtLockFile( Key: ?*ULONG, FailImmediately: BOOLEAN, ExclusiveLock: BOOLEAN, -) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; pub extern "ntdll" fn NtUnlockFile( FileHandle: HANDLE, @@ -298,13 +297,13 @@ pub extern "ntdll" fn NtUnlockFile( ByteOffset: *const LARGE_INTEGER, Length: *const LARGE_INTEGER, Key: ?*ULONG, -) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; pub extern "ntdll" fn NtOpenKey( KeyHandle: *HANDLE, DesiredAccess: ACCESS_MASK, ObjectAttributes: OBJECT_ATTRIBUTES, -) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; pub extern "ntdll" fn RtlQueryRegistryValues( RelativeTo: ULONG, @@ -312,7 +311,7 @@ pub extern "ntdll" fn RtlQueryRegistryValues( QueryTable: [*]RTL_QUERY_REGISTRY_TABLE, Context: ?*anyopaque, Environment: ?*anyopaque, -) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; pub extern "ntdll" fn NtReadVirtualMemory( ProcessHandle: HANDLE, @@ -320,7 +319,7 @@ pub extern "ntdll" fn NtReadVirtualMemory( Buffer: LPVOID, NumberOfBytesToRead: SIZE_T, NumberOfBytesRead: ?*SIZE_T, -) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; pub extern "ntdll" fn NtWriteVirtualMemory( ProcessHandle: HANDLE, @@ -328,7 +327,7 @@ pub extern "ntdll" fn NtWriteVirtualMemory( Buffer: LPCVOID, NumberOfBytesToWrite: SIZE_T, NumberOfBytesWritten: ?*SIZE_T, -) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; pub extern "ntdll" fn NtProtectVirtualMemory( ProcessHandle: HANDLE, @@ -336,11 +335,11 @@ pub extern "ntdll" fn NtProtectVirtualMemory( NumberOfBytesToProtect: *SIZE_T, NewAccessProtection: ULONG, OldAccessProtection: *ULONG, -) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; pub extern "ntdll" fn RtlExitUserProcess( ExitStatus: u32, -) callconv(WINAPI) noreturn; +) callconv(.winapi) noreturn; pub extern "ntdll" fn NtCreateNamedPipeFile( FileHandle: *HANDLE, @@ -357,4 +356,4 @@ pub extern "ntdll" fn NtCreateNamedPipeFile( InboundQuota: ULONG, OutboundQuota: ULONG, DefaultTimeout: *LARGE_INTEGER, -) callconv(WINAPI) NTSTATUS; +) callconv(.winapi) NTSTATUS; diff --git a/lib/std/os/windows/test.zig b/lib/std/os/windows/test.zig index acaa7d1218..b4cecefbd7 100644 --- a/lib/std/os/windows/test.zig +++ b/lib/std/os/windows/test.zig @@ -250,7 +250,7 @@ test "loadWinsockExtensionFunction" { SendBufLen: windows.DWORD, BytesSent: *windows.DWORD, Overlapped: *windows.OVERLAPPED, - ) callconv(windows.WINAPI) windows.BOOL; + ) callconv(.winapi) windows.BOOL; _ = windows.loadWinsockExtensionFunction( LPFN_CONNECTEX, diff --git a/lib/std/os/windows/ws2_32.zig b/lib/std/os/windows/ws2_32.zig index f3a1fdca84..e8375dc2c1 100644 --- a/lib/std/os/windows/ws2_32.zig +++ b/lib/std/os/windows/ws2_32.zig @@ -2,7 +2,6 @@ const std = @import("../../std.zig"); const assert = std.debug.assert; const windows = std.os.windows; -const WINAPI = windows.WINAPI; const OVERLAPPED = windows.OVERLAPPED; const WORD = windows.WORD; const DWORD = windows.DWORD; @@ -958,14 +957,14 @@ pub const LPCONDITIONPROC = *const fn ( lpCalleeData: *WSABUF, g: *u32, dwCallbackData: usize, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub const LPWSAOVERLAPPED_COMPLETION_ROUTINE = *const fn ( dwError: u32, cbTransferred: u32, lpOverlapped: *OVERLAPPED, dwFlags: u32, -) callconv(WINAPI) void; +) callconv(.winapi) void; pub const FLOWSPEC = extern struct { TokenRate: u32, @@ -1196,7 +1195,7 @@ pub const LPFN_TRANSMITFILE = *const fn ( lpOverlapped: ?*OVERLAPPED, lpTransmitBuffers: ?*TRANSMIT_FILE_BUFFERS, dwReserved: u32, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; pub const LPFN_ACCEPTEX = *const fn ( sListenSocket: SOCKET, @@ -1207,7 +1206,7 @@ pub const LPFN_ACCEPTEX = *const fn ( dwRemoteAddressLength: u32, lpdwBytesReceived: *u32, lpOverlapped: *OVERLAPPED, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; pub const LPFN_GETACCEPTEXSOCKADDRS = *const fn ( lpOutputBuffer: *anyopaque, @@ -1218,7 +1217,7 @@ pub const LPFN_GETACCEPTEXSOCKADDRS = *const fn ( LocalSockaddrLength: *i32, RemoteSockaddr: **sockaddr, RemoteSockaddrLength: *i32, -) callconv(WINAPI) void; +) callconv(.winapi) void; pub const LPFN_WSASENDMSG = *const fn ( s: SOCKET, @@ -1227,7 +1226,7 @@ pub const LPFN_WSASENDMSG = *const fn ( lpNumberOfBytesSent: ?*u32, lpOverlapped: ?*OVERLAPPED, lpCompletionRoutine: ?LPWSAOVERLAPPED_COMPLETION_ROUTINE, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub const LPFN_WSARECVMSG = *const fn ( s: SOCKET, @@ -1235,12 +1234,12 @@ pub const LPFN_WSARECVMSG = *const fn ( lpdwNumberOfBytesRecv: ?*u32, lpOverlapped: ?*OVERLAPPED, lpCompletionRoutine: ?LPWSAOVERLAPPED_COMPLETION_ROUTINE, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub const LPSERVICE_CALLBACK_PROC = *const fn ( lParam: LPARAM, hAsyncTaskHandle: HANDLE, -) callconv(WINAPI) void; +) callconv(.winapi) void; pub const SERVICE_ASYNC_INFO = extern struct { lpServiceCallbackProc: LPSERVICE_CALLBACK_PROC, @@ -1252,7 +1251,7 @@ pub const LPLOOKUPSERVICE_COMPLETION_ROUTINE = *const fn ( dwError: u32, dwBytes: u32, lpOverlapped: *OVERLAPPED, -) callconv(WINAPI) void; +) callconv(.winapi) void; pub const fd_set = extern struct { fd_count: u32, @@ -1725,41 +1724,41 @@ pub extern "ws2_32" fn accept( s: SOCKET, addr: ?*sockaddr, addrlen: ?*i32, -) callconv(WINAPI) SOCKET; +) callconv(.winapi) SOCKET; pub extern "ws2_32" fn bind( s: SOCKET, name: *const sockaddr, namelen: i32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn closesocket( s: SOCKET, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn connect( s: SOCKET, name: *const sockaddr, namelen: i32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn ioctlsocket( s: SOCKET, cmd: i32, argp: *u32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn getpeername( s: SOCKET, name: *sockaddr, namelen: *i32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn getsockname( s: SOCKET, name: *sockaddr, namelen: *i32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn getsockopt( s: SOCKET, @@ -1767,39 +1766,39 @@ pub extern "ws2_32" fn getsockopt( optname: i32, optval: [*]u8, optlen: *i32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn htonl( hostlong: u32, -) callconv(WINAPI) u32; +) callconv(.winapi) u32; pub extern "ws2_32" fn htons( hostshort: u16, -) callconv(WINAPI) u16; +) callconv(.winapi) u16; pub extern "ws2_32" fn inet_addr( cp: ?[*]const u8, -) callconv(WINAPI) u32; +) callconv(.winapi) u32; pub extern "ws2_32" fn listen( s: SOCKET, backlog: i32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn ntohl( netlong: u32, -) callconv(WINAPI) u32; +) callconv(.winapi) u32; pub extern "ws2_32" fn ntohs( netshort: u16, -) callconv(WINAPI) u16; +) callconv(.winapi) u16; pub extern "ws2_32" fn recv( s: SOCKET, buf: [*]u8, len: i32, flags: i32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn recvfrom( s: SOCKET, @@ -1808,7 +1807,7 @@ pub extern "ws2_32" fn recvfrom( flags: i32, from: ?*sockaddr, fromlen: ?*i32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn select( nfds: i32, @@ -1816,14 +1815,14 @@ pub extern "ws2_32" fn select( writefds: ?*fd_set, exceptfds: ?*fd_set, timeout: ?*const timeval, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn send( s: SOCKET, buf: [*]const u8, len: i32, flags: u32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn sendto( s: SOCKET, @@ -1832,7 +1831,7 @@ pub extern "ws2_32" fn sendto( flags: i32, to: *const sockaddr, tolen: i32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn setsockopt( s: SOCKET, @@ -1840,37 +1839,37 @@ pub extern "ws2_32" fn setsockopt( optname: i32, optval: ?[*]const u8, optlen: i32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn shutdown( s: SOCKET, how: i32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn socket( af: i32, @"type": i32, protocol: i32, -) callconv(WINAPI) SOCKET; +) callconv(.winapi) SOCKET; pub extern "ws2_32" fn WSAStartup( wVersionRequired: WORD, lpWSAData: *WSADATA, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; -pub extern "ws2_32" fn WSACleanup() callconv(WINAPI) i32; +pub extern "ws2_32" fn WSACleanup() callconv(.winapi) i32; -pub extern "ws2_32" fn WSASetLastError(iError: i32) callconv(WINAPI) void; +pub extern "ws2_32" fn WSASetLastError(iError: i32) callconv(.winapi) void; -pub extern "ws2_32" fn WSAGetLastError() callconv(WINAPI) WinsockError; +pub extern "ws2_32" fn WSAGetLastError() callconv(.winapi) WinsockError; -pub extern "ws2_32" fn WSAIsBlocking() callconv(WINAPI) BOOL; +pub extern "ws2_32" fn WSAIsBlocking() callconv(.winapi) BOOL; -pub extern "ws2_32" fn WSAUnhookBlockingHook() callconv(WINAPI) i32; +pub extern "ws2_32" fn WSAUnhookBlockingHook() callconv(.winapi) i32; -pub extern "ws2_32" fn WSASetBlockingHook(lpBlockFunc: FARPROC) callconv(WINAPI) FARPROC; +pub extern "ws2_32" fn WSASetBlockingHook(lpBlockFunc: FARPROC) callconv(.winapi) FARPROC; -pub extern "ws2_32" fn WSACancelBlockingCall() callconv(WINAPI) i32; +pub extern "ws2_32" fn WSACancelBlockingCall() callconv(.winapi) i32; pub extern "ws2_32" fn WSAAsyncGetServByName( hWnd: HWND, @@ -1879,7 +1878,7 @@ pub extern "ws2_32" fn WSAAsyncGetServByName( proto: ?[*:0]const u8, buf: [*]u8, buflen: i32, -) callconv(WINAPI) HANDLE; +) callconv(.winapi) HANDLE; pub extern "ws2_32" fn WSAAsyncGetServByPort( hWnd: HWND, @@ -1888,7 +1887,7 @@ pub extern "ws2_32" fn WSAAsyncGetServByPort( proto: ?[*:0]const u8, buf: [*]u8, buflen: i32, -) callconv(WINAPI) HANDLE; +) callconv(.winapi) HANDLE; pub extern "ws2_32" fn WSAAsyncGetProtoByName( hWnd: HWND, @@ -1896,7 +1895,7 @@ pub extern "ws2_32" fn WSAAsyncGetProtoByName( name: [*:0]const u8, buf: [*]u8, buflen: i32, -) callconv(WINAPI) HANDLE; +) callconv(.winapi) HANDLE; pub extern "ws2_32" fn WSAAsyncGetProtoByNumber( hWnd: HWND, @@ -1904,16 +1903,16 @@ pub extern "ws2_32" fn WSAAsyncGetProtoByNumber( number: i32, buf: [*]u8, buflen: i32, -) callconv(WINAPI) HANDLE; +) callconv(.winapi) HANDLE; -pub extern "ws2_32" fn WSACancelAsyncRequest(hAsyncTaskHandle: HANDLE) callconv(WINAPI) i32; +pub extern "ws2_32" fn WSACancelAsyncRequest(hAsyncTaskHandle: HANDLE) callconv(.winapi) i32; pub extern "ws2_32" fn WSAAsyncSelect( s: SOCKET, hWnd: HWND, wMsg: u32, lEvent: i32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn WSAAccept( s: SOCKET, @@ -1921,9 +1920,9 @@ pub extern "ws2_32" fn WSAAccept( addrlen: ?*i32, lpfnCondition: ?LPCONDITIONPROC, dwCallbackData: usize, -) callconv(WINAPI) SOCKET; +) callconv(.winapi) SOCKET; -pub extern "ws2_32" fn WSACloseEvent(hEvent: HANDLE) callconv(WINAPI) BOOL; +pub extern "ws2_32" fn WSACloseEvent(hEvent: HANDLE) callconv(.winapi) BOOL; pub extern "ws2_32" fn WSAConnect( s: SOCKET, @@ -1933,7 +1932,7 @@ pub extern "ws2_32" fn WSAConnect( lpCalleeData: ?*WSABUF, lpSQOS: ?*QOS, lpGQOS: ?*QOS, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn WSAConnectByNameW( s: SOCKET, @@ -1945,7 +1944,7 @@ pub extern "ws2_32" fn WSAConnectByNameW( RemoteAddress: ?*sockaddr, timeout: ?*const timeval, Reserved: *OVERLAPPED, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; pub extern "ws2_32" fn WSAConnectByNameA( s: SOCKET, @@ -1957,7 +1956,7 @@ pub extern "ws2_32" fn WSAConnectByNameA( RemoteAddress: ?*sockaddr, timeout: ?*const timeval, Reserved: *OVERLAPPED, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; pub extern "ws2_32" fn WSAConnectByList( s: SOCKET, @@ -1968,45 +1967,45 @@ pub extern "ws2_32" fn WSAConnectByList( RemoteAddress: ?*sockaddr, timeout: ?*const timeval, Reserved: *OVERLAPPED, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; -pub extern "ws2_32" fn WSACreateEvent() callconv(WINAPI) HANDLE; +pub extern "ws2_32" fn WSACreateEvent() callconv(.winapi) HANDLE; pub extern "ws2_32" fn WSADuplicateSocketA( s: SOCKET, dwProcessId: u32, lpProtocolInfo: *WSAPROTOCOL_INFOA, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn WSADuplicateSocketW( s: SOCKET, dwProcessId: u32, lpProtocolInfo: *WSAPROTOCOL_INFOW, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn WSAEnumNetworkEvents( s: SOCKET, hEventObject: HANDLE, lpNetworkEvents: *WSANETWORKEVENTS, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn WSAEnumProtocolsA( lpiProtocols: ?*i32, lpProtocolBuffer: ?*WSAPROTOCOL_INFOA, lpdwBufferLength: *u32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn WSAEnumProtocolsW( lpiProtocols: ?*i32, lpProtocolBuffer: ?*WSAPROTOCOL_INFOW, lpdwBufferLength: *u32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn WSAEventSelect( s: SOCKET, hEventObject: HANDLE, lNetworkEvents: i32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn WSAGetOverlappedResult( s: SOCKET, @@ -2014,25 +2013,25 @@ pub extern "ws2_32" fn WSAGetOverlappedResult( lpcbTransfer: *u32, fWait: BOOL, lpdwFlags: *u32, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; pub extern "ws2_32" fn WSAGetQOSByName( s: SOCKET, lpQOSName: *WSABUF, lpQOS: *QOS, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; pub extern "ws2_32" fn WSAHtonl( s: SOCKET, hostlong: u32, lpnetlong: *u32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn WSAHtons( s: SOCKET, hostshort: u16, lpnetshort: *u16, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn WSAIoctl( s: SOCKET, @@ -2044,7 +2043,7 @@ pub extern "ws2_32" fn WSAIoctl( lpcbBytesReturned: *u32, lpOverlapped: ?*OVERLAPPED, lpCompletionRoutine: ?LPWSAOVERLAPPED_COMPLETION_ROUTINE, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn WSAJoinLeaf( s: SOCKET, @@ -2055,19 +2054,19 @@ pub extern "ws2_32" fn WSAJoinLeaf( lpSQOS: ?*QOS, lpGQOS: ?*QOS, dwFlags: u32, -) callconv(WINAPI) SOCKET; +) callconv(.winapi) SOCKET; pub extern "ws2_32" fn WSANtohl( s: SOCKET, netlong: u32, lphostlong: *u32, -) callconv(WINAPI) u32; +) callconv(.winapi) u32; pub extern "ws2_32" fn WSANtohs( s: SOCKET, netshort: u16, lphostshort: *u16, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn WSARecv( s: SOCKET, @@ -2077,12 +2076,12 @@ pub extern "ws2_32" fn WSARecv( lpFlags: *u32, lpOverlapped: ?*OVERLAPPED, lpCompletionRoutine: ?LPWSAOVERLAPPED_COMPLETION_ROUTINE, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn WSARecvDisconnect( s: SOCKET, lpInboundDisconnectData: ?*WSABUF, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn WSARecvFrom( s: SOCKET, @@ -2094,9 +2093,9 @@ pub extern "ws2_32" fn WSARecvFrom( lpFromlen: ?*i32, lpOverlapped: ?*OVERLAPPED, lpCompletionRoutine: ?LPWSAOVERLAPPED_COMPLETION_ROUTINE, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; -pub extern "ws2_32" fn WSAResetEvent(hEvent: HANDLE) callconv(WINAPI) i32; +pub extern "ws2_32" fn WSAResetEvent(hEvent: HANDLE) callconv(.winapi) i32; pub extern "ws2_32" fn WSASend( s: SOCKET, @@ -2106,7 +2105,7 @@ pub extern "ws2_32" fn WSASend( dwFlags: u32, lpOverlapped: ?*OVERLAPPED, lpCompletionRoutine: ?LPWSAOVERLAPPED_COMPLETION_ROUTINE, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn WSASendMsg( s: SOCKET, @@ -2115,7 +2114,7 @@ pub extern "ws2_32" fn WSASendMsg( lpNumberOfBytesSent: ?*u32, lpOverlapped: ?*OVERLAPPED, lpCompletionRoutine: ?LPWSAOVERLAPPED_COMPLETION_ROUTINE, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn WSARecvMsg( s: SOCKET, @@ -2123,12 +2122,12 @@ pub extern "ws2_32" fn WSARecvMsg( lpdwNumberOfBytesRecv: ?*u32, lpOverlapped: ?*OVERLAPPED, lpCompletionRoutine: ?LPWSAOVERLAPPED_COMPLETION_ROUTINE, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn WSASendDisconnect( s: SOCKET, lpOutboundDisconnectData: ?*WSABUF, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn WSASendTo( s: SOCKET, @@ -2140,11 +2139,11 @@ pub extern "ws2_32" fn WSASendTo( iToLen: i32, lpOverlapped: ?*OVERLAPPED, lpCompletionRounte: ?LPWSAOVERLAPPED_COMPLETION_ROUTINE, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn WSASetEvent( hEvent: HANDLE, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; pub extern "ws2_32" fn WSASocketA( af: i32, @@ -2153,7 +2152,7 @@ pub extern "ws2_32" fn WSASocketA( lpProtocolInfo: ?*WSAPROTOCOL_INFOA, g: u32, dwFlags: u32, -) callconv(WINAPI) SOCKET; +) callconv(.winapi) SOCKET; pub extern "ws2_32" fn WSASocketW( af: i32, @@ -2162,7 +2161,7 @@ pub extern "ws2_32" fn WSASocketW( lpProtocolInfo: ?*WSAPROTOCOL_INFOW, g: u32, dwFlags: u32, -) callconv(WINAPI) SOCKET; +) callconv(.winapi) SOCKET; pub extern "ws2_32" fn WSAWaitForMultipleEvents( cEvents: u32, @@ -2170,7 +2169,7 @@ pub extern "ws2_32" fn WSAWaitForMultipleEvents( fWaitAll: BOOL, dwTimeout: u32, fAlertable: BOOL, -) callconv(WINAPI) u32; +) callconv(.winapi) u32; pub extern "ws2_32" fn WSAAddressToStringA( lpsaAddress: *sockaddr, @@ -2178,7 +2177,7 @@ pub extern "ws2_32" fn WSAAddressToStringA( lpProtocolInfo: ?*WSAPROTOCOL_INFOA, lpszAddressString: [*]u8, lpdwAddressStringLength: *u32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn WSAAddressToStringW( lpsaAddress: *sockaddr, @@ -2186,7 +2185,7 @@ pub extern "ws2_32" fn WSAAddressToStringW( lpProtocolInfo: ?*WSAPROTOCOL_INFOW, lpszAddressString: [*]u16, lpdwAddressStringLength: *u32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn WSAStringToAddressA( AddressString: [*:0]const u8, @@ -2194,7 +2193,7 @@ pub extern "ws2_32" fn WSAStringToAddressA( lpProtocolInfo: ?*WSAPROTOCOL_INFOA, lpAddress: *sockaddr, lpAddressLength: *i32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn WSAStringToAddressW( AddressString: [*:0]const u16, @@ -2202,26 +2201,26 @@ pub extern "ws2_32" fn WSAStringToAddressW( lpProtocolInfo: ?*WSAPROTOCOL_INFOW, lpAddrses: *sockaddr, lpAddressLength: *i32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn WSAProviderConfigChange( lpNotificationHandle: *HANDLE, lpOverlapped: ?*OVERLAPPED, lpCompletionRoutine: ?LPWSAOVERLAPPED_COMPLETION_ROUTINE, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn WSAPoll( fdArray: [*]WSAPOLLFD, fds: u32, timeout: i32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "mswsock" fn WSARecvEx( s: SOCKET, buf: [*]u8, len: i32, flags: *i32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "mswsock" fn TransmitFile( hSocket: SOCKET, @@ -2231,7 +2230,7 @@ pub extern "mswsock" fn TransmitFile( lpOverlapped: ?*OVERLAPPED, lpTransmitBuffers: ?*TRANSMIT_FILE_BUFFERS, dwReserved: u32, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; pub extern "mswsock" fn AcceptEx( sListenSocket: SOCKET, @@ -2242,7 +2241,7 @@ pub extern "mswsock" fn AcceptEx( dwRemoteAddressLength: u32, lpdwBytesReceived: *u32, lpOverlapped: *OVERLAPPED, -) callconv(WINAPI) BOOL; +) callconv(.winapi) BOOL; pub extern "mswsock" fn GetAcceptExSockaddrs( lpOutputBuffer: *anyopaque, @@ -2253,24 +2252,24 @@ pub extern "mswsock" fn GetAcceptExSockaddrs( LocalSockaddrLength: *i32, RemoteSockaddr: **sockaddr, RemoteSockaddrLength: *i32, -) callconv(WINAPI) void; +) callconv(.winapi) void; pub extern "ws2_32" fn WSAProviderCompleteAsyncCall( hAsyncCall: HANDLE, iRetCode: i32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "mswsock" fn EnumProtocolsA( lpiProtocols: ?*i32, lpProtocolBuffer: *anyopaque, lpdwBufferLength: *u32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "mswsock" fn EnumProtocolsW( lpiProtocols: ?*i32, lpProtocolBuffer: *anyopaque, lpdwBufferLength: *u32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "mswsock" fn GetAddressByNameA( dwNameSpace: u32, @@ -2282,7 +2281,7 @@ pub extern "mswsock" fn GetAddressByNameA( lpCsaddrBuffer: *anyopaque, lpAliasBuffer: ?[*:0]const u8, lpdwAliasBufferLength: *u32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "mswsock" fn GetAddressByNameW( dwNameSpace: u32, @@ -2295,36 +2294,36 @@ pub extern "mswsock" fn GetAddressByNameW( ldwBufferLEngth: *u32, lpAliasBuffer: ?[*:0]u16, lpdwAliasBufferLength: *u32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "mswsock" fn GetTypeByNameA( lpServiceName: [*:0]u8, lpServiceType: *GUID, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "mswsock" fn GetTypeByNameW( lpServiceName: [*:0]u16, lpServiceType: *GUID, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "mswsock" fn GetNameByTypeA( lpServiceType: *GUID, lpServiceName: [*:0]u8, dwNameLength: u32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "mswsock" fn GetNameByTypeW( lpServiceType: *GUID, lpServiceName: [*:0]u16, dwNameLength: u32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn getaddrinfo( pNodeName: ?[*:0]const u8, pServiceName: ?[*:0]const u8, pHints: ?*const addrinfoa, ppResult: *?*addrinfoa, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn GetAddrInfoExA( pName: ?[*:0]const u8, @@ -2336,23 +2335,23 @@ pub extern "ws2_32" fn GetAddrInfoExA( timeout: ?*timeval, lpOverlapped: ?*OVERLAPPED, lpCompletionRoutine: ?LPLOOKUPSERVICE_COMPLETION_ROUTINE, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn GetAddrInfoExCancel( lpHandle: *HANDLE, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn GetAddrInfoExOverlappedResult( lpOverlapped: *OVERLAPPED, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "ws2_32" fn freeaddrinfo( pAddrInfo: ?*addrinfoa, -) callconv(WINAPI) void; +) callconv(.winapi) void; pub extern "ws2_32" fn FreeAddrInfoEx( pAddrInfoEx: ?*addrinfoexA, -) callconv(WINAPI) void; +) callconv(.winapi) void; pub extern "ws2_32" fn getnameinfo( pSockaddr: *const sockaddr, @@ -2362,8 +2361,8 @@ pub extern "ws2_32" fn getnameinfo( pServiceBuffer: ?[*]u8, ServiceBufferName: u32, Flags: i32, -) callconv(WINAPI) i32; +) callconv(.winapi) i32; pub extern "iphlpapi" fn if_nametoindex( InterfaceName: [*:0]const u8, -) callconv(WINAPI) u32; +) callconv(.winapi) u32; diff --git a/src/crash_report.zig b/src/crash_report.zig index d9f8bac350..45410890a5 100644 --- a/src/crash_report.zig +++ b/src/crash_report.zig @@ -229,7 +229,7 @@ const WindowsSegfaultMessage = union(enum) { illegal_instruction: void, }; -fn handleSegfaultWindows(info: *windows.EXCEPTION_POINTERS) callconv(windows.WINAPI) c_long { +fn handleSegfaultWindows(info: *windows.EXCEPTION_POINTERS) callconv(.winapi) c_long { switch (info.ExceptionRecord.ExceptionCode) { windows.EXCEPTION_DATATYPE_MISALIGNMENT => handleSegfaultWindowsExtra(info, .{ .literal = "Unaligned Memory Access" }), windows.EXCEPTION_ACCESS_VIOLATION => handleSegfaultWindowsExtra(info, .segfault), From 3a5142af8dcafea7062588b9d217ae82735c0bac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Mon, 28 Oct 2024 20:24:41 +0100 Subject: [PATCH 08/11] compiler: Handle arm_aapcs16_vfp alongside arm_aapcs_vfp in some places. --- src/Zcu.zig | 6 +++++- src/codegen/c.zig | 2 +- src/codegen/llvm.zig | 16 +++++++++++----- src/link/Dwarf.zig | 5 +++-- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/Zcu.zig b/src/Zcu.zig index 88bc4750af..67c8f14729 100644 --- a/src/Zcu.zig +++ b/src/Zcu.zig @@ -3615,12 +3615,16 @@ pub fn callconvSupported(zcu: *Zcu, cc: std.builtin.CallingConvention) union(enu .aarch64_vfabi, .aarch64_vfabi_sve, .arm_aapcs, - .arm_aapcs_vfp, .riscv64_lp64_v, .riscv32_ilp32_v, .m68k_rtd, => |opts| opts.incoming_stack_alignment == null, + .arm_aapcs_vfp, + => |opts| opts.incoming_stack_alignment == null and target.os.tag != .watchos, + .arm_aapcs16_vfp, + => |opts| opts.incoming_stack_alignment == null and target.os.tag == .watchos, + .x86_sysv, .x86_win, .x86_stdcall, diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 4d55637f27..d7b2ca3d09 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -7623,7 +7623,7 @@ fn toCallingConvention(cc: std.builtin.CallingConvention, zcu: *Zcu) ?[]const u8 .aarch64_vfabi => "aarch64_vector_pcs", .aarch64_vfabi_sve => "aarch64_sve_pcs", .arm_aapcs => "pcs(\"aapcs\")", - .arm_aapcs_vfp => "pcs(\"aapcs-vfp\")", + .arm_aapcs_vfp, .arm_aapcs16_vfp => "pcs(\"aapcs-vfp\")", .riscv64_lp64_v, .riscv32_ilp32_v => "riscv_vector_cc", .m68k_rtd => "m68k_rtd", diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index fc7d26a815..217c14d9bb 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -11747,7 +11747,14 @@ fn toLlvmCallConvTag(cc_tag: std.builtin.CallingConvention.Tag, target: std.Targ .aarch64_vfabi_sve => .aarch64_sve_vector_pcs, .arm_apcs => .arm_apcscc, .arm_aapcs => .arm_aapcscc, - .arm_aapcs_vfp => .arm_aapcs_vfpcc, + .arm_aapcs_vfp => if (target.os.tag != .watchos) + .arm_aapcs_vfpcc + else + null, + .arm_aapcs16_vfp => if (target.os.tag == .watchos) + .arm_aapcs_vfpcc + else + null, .riscv64_lp64_v => .riscv_vectorcallcc, .riscv32_ilp32_v => .riscv_vectorcallcc, .avr_builtin => .avr_builtincc, @@ -11777,7 +11784,6 @@ fn toLlvmCallConvTag(cc_tag: std.builtin.CallingConvention.Tag, target: std.Targ .aarch64_aapcs, .aarch64_aapcs_darwin, .aarch64_aapcs_win, - .arm_aapcs16_vfp, .mips64_n64, .mips64_n32, .mips_o32, @@ -11957,7 +11963,7 @@ fn firstParamSRet(fn_info: InternPool.Key.FuncType, zcu: *Zcu, target: std.Targe .aarch64_aapcs_darwin, .aarch64_aapcs_win, => aarch64_c_abi.classifyType(return_type, zcu) == .memory, - .arm_aapcs, .arm_aapcs_vfp => switch (arm_c_abi.classifyType(return_type, zcu, .ret)) { + .arm_aapcs, .arm_aapcs_vfp, .arm_aapcs16_vfp => switch (arm_c_abi.classifyType(return_type, zcu, .ret)) { .memory, .i64_array => true, .i32_array => |size| size != 1, .byval => false, @@ -12007,7 +12013,7 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Bu .integer => return o.builder.intType(@intCast(return_type.bitSize(zcu))), .double_integer => return o.builder.arrayType(2, .i64), }, - .arm_aapcs, .arm_aapcs_vfp => switch (arm_c_abi.classifyType(return_type, zcu, .ret)) { + .arm_aapcs, .arm_aapcs_vfp, .arm_aapcs16_vfp => switch (arm_c_abi.classifyType(return_type, zcu, .ret)) { .memory, .i64_array => return .void, .i32_array => |len| return if (len == 1) .i32 else .void, .byval => return o.lowerType(return_type), @@ -12256,7 +12262,7 @@ const ParamTypeIterator = struct { .double_integer => return Lowering{ .i64_array = 2 }, } }, - .arm_aapcs, .arm_aapcs_vfp => { + .arm_aapcs, .arm_aapcs_vfp, .arm_aapcs16_vfp => { it.zig_index += 1; it.llvm_index += 1; switch (arm_c_abi.classifyType(ty, zcu, .arg)) { diff --git a/src/link/Dwarf.zig b/src/link/Dwarf.zig index 2babe2b090..b96124438b 100644 --- a/src/link/Dwarf.zig +++ b/src/link/Dwarf.zig @@ -3433,8 +3433,9 @@ fn updateType( .arm_apcs => .nocall, .arm_aapcs => .LLVM_AAPCS, - .arm_aapcs_vfp => .LLVM_AAPCS_VFP, - .arm_aapcs16_vfp => .nocall, + .arm_aapcs_vfp, + .arm_aapcs16_vfp, + => .LLVM_AAPCS_VFP, .riscv64_lp64_v, .riscv32_ilp32_v, From c217fd2b9ca06d51b8c67a7a556e61ae71a25dbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Mon, 28 Oct 2024 22:47:57 +0100 Subject: [PATCH 09/11] cbe: Support some more calling conventions. --- src/Zcu.zig | 19 +++++++++++++++++++ src/codegen/c.zig | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/Zcu.zig b/src/Zcu.zig index 67c8f14729..d03eb4cc9a 100644 --- a/src/Zcu.zig +++ b/src/Zcu.zig @@ -3607,17 +3607,21 @@ pub fn callconvSupported(zcu: *Zcu, cc: std.builtin.CallingConvention) union(enu .x86_64_vectorcall, .x86_64_regcall_v3_sysv, .x86_64_regcall_v4_win, + .x86_64_interrupt, .x86_fastcall, .x86_thiscall, .x86_vectorcall, .x86_regcall_v3, .x86_regcall_v4_win, + .x86_interrupt, .aarch64_vfabi, .aarch64_vfabi_sve, .arm_aapcs, + .csky_interrupt, .riscv64_lp64_v, .riscv32_ilp32_v, .m68k_rtd, + .m68k_interrupt, => |opts| opts.incoming_stack_alignment == null, .arm_aapcs_vfp, @@ -3625,11 +3629,26 @@ pub fn callconvSupported(zcu: *Zcu, cc: std.builtin.CallingConvention) union(enu .arm_aapcs16_vfp, => |opts| opts.incoming_stack_alignment == null and target.os.tag == .watchos, + .arm_interrupt, + => |opts| opts.incoming_stack_alignment == null, + + .mips_interrupt, + .mips64_interrupt, + => |opts| opts.incoming_stack_alignment == null, + + .riscv32_interrupt, + .riscv64_interrupt, + => |opts| opts.incoming_stack_alignment == null, + .x86_sysv, .x86_win, .x86_stdcall, => |opts| opts.incoming_stack_alignment == null and opts.register_params == 0, + .avr_interrupt, + .avr_signal, + => true, + .naked => true, else => false, diff --git a/src/codegen/c.zig b/src/codegen/c.zig index d7b2ca3d09..a56c1e7951 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -7622,11 +7622,44 @@ fn toCallingConvention(cc: std.builtin.CallingConvention, zcu: *Zcu) ?[]const u8 .aarch64_vfabi => "aarch64_vector_pcs", .aarch64_vfabi_sve => "aarch64_sve_pcs", + .arm_aapcs => "pcs(\"aapcs\")", .arm_aapcs_vfp, .arm_aapcs16_vfp => "pcs(\"aapcs-vfp\")", + + .arm_interrupt => |opts| switch (opts.type) { + .generic => "interrupt", + .irq => "interrupt(\"IRQ\")", + .fiq => "interrupt(\"FIQ\")", + .swi => "interrupt(\"SWI\")", + .abort => "interrupt(\"ABORT\")", + .undef => "interrupt(\"UNDEF\")", + }, + + .avr_signal => "signal", + + .mips_interrupt, + .mips64_interrupt, + => |opts| switch (opts.mode) { + inline else => |m| "interrupt(\"" ++ @tagName(m) ++ "\")", + }, + .riscv64_lp64_v, .riscv32_ilp32_v => "riscv_vector_cc", + + .riscv32_interrupt, + .riscv64_interrupt, + => |opts| switch (opts.mode) { + inline else => |m| "interrupt(\"" ++ @tagName(m) ++ "\")", + }, + .m68k_rtd => "m68k_rtd", + .avr_interrupt, + .csky_interrupt, + .m68k_interrupt, + .x86_interrupt, + .x86_64_interrupt, + => "interrupt", + else => unreachable, // `Zcu.callconvSupported` }; } From f508e227052bb13943bad16b324944ae72d8af4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Tue, 29 Oct 2024 01:20:18 +0100 Subject: [PATCH 10/11] link.Dwarf: Some minor corrections to calling conventions to ~match Clang. This can't be completely 1:1 due to the fact that we model CCs more precisely, but this is about as close as we can get. --- src/link/Dwarf.zig | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/link/Dwarf.zig b/src/link/Dwarf.zig index b96124438b..6653a8309a 100644 --- a/src/link/Dwarf.zig +++ b/src/link/Dwarf.zig @@ -3415,8 +3415,8 @@ fn updateType( .x86_64_regcall_v3_sysv => .LLVM_X86RegCall, .x86_64_regcall_v4_win => .LLVM_X86RegCall, .x86_64_vectorcall => .LLVM_vectorcall, - .x86_sysv => .nocall, - .x86_win => .nocall, + .x86_sysv => .normal, + .x86_win => .normal, .x86_stdcall => .BORLAND_stdcall, .x86_fastcall => .BORLAND_msfastcall, .x86_thiscall => .BORLAND_thiscall, @@ -3425,13 +3425,13 @@ fn updateType( .x86_regcall_v4_win => .LLVM_X86RegCall, .x86_vectorcall => .LLVM_vectorcall, - .aarch64_aapcs => .LLVM_AAPCS, - .aarch64_aapcs_darwin => .LLVM_AAPCS, - .aarch64_aapcs_win => .LLVM_AAPCS, + .aarch64_aapcs => .normal, + .aarch64_aapcs_darwin => .normal, + .aarch64_aapcs_win => .normal, .aarch64_vfabi => .LLVM_AAPCS, .aarch64_vfabi_sve => .LLVM_AAPCS, - .arm_apcs => .nocall, + .arm_apcs => .normal, .arm_aapcs => .LLVM_AAPCS, .arm_aapcs_vfp, .arm_aapcs16_vfp, @@ -3443,10 +3443,10 @@ fn updateType( .m68k_rtd => .LLVM_M68kRTD, - .amdgcn_kernel, + .amdgcn_kernel => .LLVM_OpenCLKernel, .nvptx_kernel, .spirv_kernel, - => .LLVM_OpenCLKernel, + => .nocall, .x86_64_interrupt, .x86_interrupt, From e4e3d7ab4140ae6f078d3ffd72fce4c0a5e6e59f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Mon, 28 Oct 2024 21:57:29 +0100 Subject: [PATCH 11/11] Sema: Disallow calling functions with certain special calling conventions. --- src/Sema.zig | 33 +++++++++++++++++-- ...function_with_naked_calling_convention.zig | 4 +-- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/Sema.zig b/src/Sema.zig index 46fe7f0a31..65805b6a67 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -7574,13 +7574,13 @@ fn analyzeCall( if (try sema.resolveValue(func)) |func_val| if (func_val.isUndef(zcu)) return sema.failWithUseOfUndef(block, call_src); - if (cc == .naked) { + if (!callConvIsCallable(cc)) { const maybe_func_inst = try sema.funcDeclSrcInst(func); const msg = msg: { const msg = try sema.errMsg( func_src, - "unable to call function with naked calling convention", - .{}, + "unable to call function with calling convention '{s}'", + .{@tagName(cc)}, ); errdefer msg.destroy(sema.gpa); @@ -9764,6 +9764,33 @@ fn checkCallConvSupportsVarArgs(sema: *Sema, block: *Block, src: LazySrcLoc, cc: } } +fn callConvIsCallable(cc: std.builtin.CallingConvention.Tag) bool { + return switch (cc) { + .naked, + + .arm_interrupt, + .avr_interrupt, + .avr_signal, + .csky_interrupt, + .m68k_interrupt, + .mips_interrupt, + .mips64_interrupt, + .riscv32_interrupt, + .riscv64_interrupt, + .x86_interrupt, + .x86_64_interrupt, + + .amdgcn_kernel, + .nvptx_kernel, + .spirv_kernel, + .spirv_fragment, + .spirv_vertex, + => false, + + else => true, + }; +} + fn checkMergeAllowed(sema: *Sema, block: *Block, src: LazySrcLoc, peer_ty: Type) !void { const pt = sema.pt; const zcu = pt.zcu; diff --git a/test/cases/compile_errors/calling_function_with_naked_calling_convention.zig b/test/cases/compile_errors/calling_function_with_naked_calling_convention.zig index 2bd0364d4f..ea4e42f15d 100644 --- a/test/cases/compile_errors/calling_function_with_naked_calling_convention.zig +++ b/test/cases/compile_errors/calling_function_with_naked_calling_convention.zig @@ -1,11 +1,11 @@ export fn entry() void { foo(); } -fn foo() callconv(.Naked) void {} +fn foo() callconv(.naked) void {} // error // backend=llvm // target=native // -// :2:5: error: unable to call function with naked calling convention +// :2:5: error: unable to call function with calling convention 'naked' // :4:1: note: function declared here