| author | |
| committer | |
| log | 41b7e40d75bdd415da0daef6fa6a71dc4686320f |
| tree | 192a10d212127c63c8c1bf8f71b7103545f0f2e3 |
| parent | d1e7be0bd190e1d93a6375b051a180f739990191 |
| parent | a68b27c252669f3a42b8f789359893ee82cd0aad |
| signature |
std.os: fix alignment of Sigaction.handler_fn9 files changed, 38 insertions(+), 15 deletions(-)
lib/std/c/darwin.zig+1-1| ... | @@ -918,7 +918,7 @@ pub const siginfo_t = extern struct { | ... | @@ -918,7 +918,7 @@ pub const siginfo_t = extern struct { |
| 918 | 918 | ||
| 919 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with function name. | 919 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with function name. |
| 920 | pub const Sigaction = extern struct { | 920 | pub const Sigaction = extern struct { |
| 921 | pub const handler_fn = std.meta.FnPtr(fn (c_int) callconv(.C) void); | 921 | pub const handler_fn = std.meta.FnPtr(fn (c_int) align(1) callconv(.C) void); |
| 922 | pub const sigaction_fn = std.meta.FnPtr(fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void); | 922 | pub const sigaction_fn = std.meta.FnPtr(fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void); |
| 923 | 923 | ||
| 924 | handler: extern union { | 924 | handler: extern union { |
lib/std/c/dragonfly.zig+1-1| ... | @@ -681,7 +681,7 @@ pub const empty_sigset = sigset_t{ .__bits = [_]c_uint{0} ** _SIG_WORDS }; | ... | @@ -681,7 +681,7 @@ pub const empty_sigset = sigset_t{ .__bits = [_]c_uint{0} ** _SIG_WORDS }; |
| 681 | pub const sig_atomic_t = c_int; | 681 | pub const sig_atomic_t = c_int; |
| 682 | 682 | ||
| 683 | pub const Sigaction = extern struct { | 683 | pub const Sigaction = extern struct { |
| 684 | pub const handler_fn = std.meta.FnPtr(fn (c_int) callconv(.C) void); | 684 | pub const handler_fn = std.meta.FnPtr(fn (c_int) align(1) callconv(.C) void); |
| 685 | pub const sigaction_fn = std.meta.FnPtr(fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void); | 685 | pub const sigaction_fn = std.meta.FnPtr(fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void); |
| 686 | 686 | ||
| 687 | /// signal handler | 687 | /// signal handler |
lib/std/c/freebsd.zig+1-1| ... | @@ -1197,7 +1197,7 @@ const NSIG = 32; | ... | @@ -1197,7 +1197,7 @@ const NSIG = 32; |
| 1197 | 1197 | ||
| 1198 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. | 1198 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. |
| 1199 | pub const Sigaction = extern struct { | 1199 | pub const Sigaction = extern struct { |
| 1200 | pub const handler_fn = std.meta.FnPtr(fn (c_int) callconv(.C) void); | 1200 | pub const handler_fn = std.meta.FnPtr(fn (c_int) align(1) callconv(.C) void); |
| 1201 | pub const sigaction_fn = std.meta.FnPtr(fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void); | 1201 | pub const sigaction_fn = std.meta.FnPtr(fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void); |
| 1202 | 1202 | ||
| 1203 | /// signal handler | 1203 | /// signal handler |
lib/std/c/haiku.zig+1-1| ... | @@ -742,7 +742,7 @@ const NSIG = 32; | ... | @@ -742,7 +742,7 @@ const NSIG = 32; |
| 742 | 742 | ||
| 743 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. | 743 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. |
| 744 | pub const Sigaction = extern struct { | 744 | pub const Sigaction = extern struct { |
| 745 | pub const handler_fn = std.meta.FnPtr(fn (i32) callconv(.C) void); | 745 | pub const handler_fn = std.meta.FnPtr(fn (i32) align(1) callconv(.C) void); |
| 746 | 746 | ||
| 747 | /// signal handler | 747 | /// signal handler |
| 748 | __sigaction_u: extern union { | 748 | __sigaction_u: extern union { |
lib/std/c/netbsd.zig+1-1| ... | @@ -971,7 +971,7 @@ pub const SIG = struct { | ... | @@ -971,7 +971,7 @@ pub const SIG = struct { |
| 971 | 971 | ||
| 972 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. | 972 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. |
| 973 | pub const Sigaction = extern struct { | 973 | pub const Sigaction = extern struct { |
| 974 | pub const handler_fn = std.meta.FnPtr(fn (c_int) callconv(.C) void); | 974 | pub const handler_fn = std.meta.FnPtr(fn (c_int) align(1) callconv(.C) void); |
| 975 | pub const sigaction_fn = std.meta.FnPtr(fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void); | 975 | pub const sigaction_fn = std.meta.FnPtr(fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void); |
| 976 | 976 | ||
| 977 | /// signal handler | 977 | /// signal handler |
lib/std/c/openbsd.zig+1-1| ... | @@ -1026,7 +1026,7 @@ pub const SIG = struct { | ... | @@ -1026,7 +1026,7 @@ pub const SIG = struct { |
| 1026 | 1026 | ||
| 1027 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. | 1027 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. |
| 1028 | pub const Sigaction = extern struct { | 1028 | pub const Sigaction = extern struct { |
| 1029 | pub const handler_fn = std.meta.FnPtr(fn (c_int) callconv(.C) void); | 1029 | pub const handler_fn = std.meta.FnPtr(fn (c_int) align(1) callconv(.C) void); |
| 1030 | pub const sigaction_fn = std.meta.FnPtr(fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void); | 1030 | pub const sigaction_fn = std.meta.FnPtr(fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void); |
| 1031 | 1031 | ||
| 1032 | /// signal handler | 1032 | /// signal handler |
lib/std/c/solaris.zig+1-1| ... | @@ -952,7 +952,7 @@ pub const SIG = struct { | ... | @@ -952,7 +952,7 @@ pub const SIG = struct { |
| 952 | 952 | ||
| 953 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. | 953 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. |
| 954 | pub const Sigaction = extern struct { | 954 | pub const Sigaction = extern struct { |
| 955 | pub const handler_fn = std.meta.FnPtr(fn (c_int) callconv(.C) void); | 955 | pub const handler_fn = std.meta.FnPtr(fn (c_int) align(1) callconv(.C) void); |
| 956 | pub const sigaction_fn = std.meta.FnPtr(fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void); | 956 | pub const sigaction_fn = std.meta.FnPtr(fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void); |
| 957 | 957 | ||
| 958 | /// signal options | 958 | /// signal options |
lib/std/os/linux.zig+2-2| ... | @@ -3130,7 +3130,7 @@ pub const all_mask: sigset_t = [_]u32{0xffffffff} ** @typeInfo(sigset_t).Array.l | ... | @@ -3130,7 +3130,7 @@ pub const all_mask: sigset_t = [_]u32{0xffffffff} ** @typeInfo(sigset_t).Array.l |
| 3130 | pub const app_mask: sigset_t = [2]u32{ 0xfffffffc, 0x7fffffff } ++ [_]u32{0xffffffff} ** 30; | 3130 | pub const app_mask: sigset_t = [2]u32{ 0xfffffffc, 0x7fffffff } ++ [_]u32{0xffffffff} ** 30; |
| 3131 | 3131 | ||
| 3132 | const k_sigaction_funcs = struct { | 3132 | const k_sigaction_funcs = struct { |
| 3133 | const handler = ?std.meta.FnPtr(fn (c_int) callconv(.C) void); | 3133 | const handler = ?std.meta.FnPtr(fn (c_int) align(1) callconv(.C) void); |
| 3134 | const restorer = std.meta.FnPtr(fn () callconv(.C) void); | 3134 | const restorer = std.meta.FnPtr(fn () callconv(.C) void); |
| 3135 | }; | 3135 | }; |
| 3136 | 3136 | ||
| ... | @@ -3157,7 +3157,7 @@ pub const k_sigaction = switch (native_arch) { | ... | @@ -3157,7 +3157,7 @@ pub const k_sigaction = switch (native_arch) { |
| 3157 | 3157 | ||
| 3158 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. | 3158 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. |
| 3159 | pub const Sigaction = extern struct { | 3159 | pub const Sigaction = extern struct { |
| 3160 | pub const handler_fn = std.meta.FnPtr(fn (c_int) callconv(.C) void); | 3160 | pub const handler_fn = std.meta.FnPtr(fn (c_int) align(1) callconv(.C) void); |
| 3161 | pub const sigaction_fn = std.meta.FnPtr(fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void); | 3161 | pub const sigaction_fn = std.meta.FnPtr(fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void); |
| 3162 | 3162 | ||
| 3163 | handler: extern union { | 3163 | handler: extern union { |
lib/std/os/test.zig+29-6| ... | @@ -739,8 +739,6 @@ test "shutdown socket" { | ... | @@ -739,8 +739,6 @@ test "shutdown socket" { |
| 739 | os.closeSocket(sock); | 739 | os.closeSocket(sock); |
| 740 | } | 740 | } |
| 741 | 741 | ||
| 742 | var signal_test_failed = true; | ||
| 743 | |||
| 744 | test "sigaction" { | 742 | test "sigaction" { |
| 745 | if (native_os == .wasi or native_os == .windows) | 743 | if (native_os == .wasi or native_os == .windows) |
| 746 | return error.SkipZigTest; | 744 | return error.SkipZigTest; |
| ... | @@ -750,17 +748,19 @@ test "sigaction" { | ... | @@ -750,17 +748,19 @@ test "sigaction" { |
| 750 | return error.SkipZigTest; | 748 | return error.SkipZigTest; |
| 751 | 749 | ||
| 752 | const S = struct { | 750 | const S = struct { |
| 751 | var handler_called_count: u32 = 0; | ||
| 752 | |||
| 753 | fn handler(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const anyopaque) callconv(.C) void { | 753 | fn handler(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const anyopaque) callconv(.C) void { |
| 754 | _ = ctx_ptr; | 754 | _ = ctx_ptr; |
| 755 | // Check that we received the correct signal. | 755 | // Check that we received the correct signal. |
| 756 | switch (native_os) { | 756 | switch (native_os) { |
| 757 | .netbsd => { | 757 | .netbsd => { |
| 758 | if (sig == os.SIG.USR1 and sig == info.info.signo) | 758 | if (sig == os.SIG.USR1 and sig == info.info.signo) |
| 759 | signal_test_failed = false; | 759 | handler_called_count += 1; |
| 760 | }, | 760 | }, |
| 761 | else => { | 761 | else => { |
| 762 | if (sig == os.SIG.USR1 and sig == info.signo) | 762 | if (sig == os.SIG.USR1 and sig == info.signo) |
| 763 | signal_test_failed = false; | 763 | handler_called_count += 1; |
| 764 | }, | 764 | }, |
| 765 | } | 765 | } |
| 766 | } | 766 | } |
| ... | @@ -774,18 +774,41 @@ test "sigaction" { | ... | @@ -774,18 +774,41 @@ test "sigaction" { |
| 774 | .flags = os.SA.SIGINFO | os.SA.RESETHAND, | 774 | .flags = os.SA.SIGINFO | os.SA.RESETHAND, |
| 775 | }; | 775 | }; |
| 776 | var old_sa: os.Sigaction = undefined; | 776 | var old_sa: os.Sigaction = undefined; |
| 777 | |||
| 777 | // Install the new signal handler. | 778 | // Install the new signal handler. |
| 778 | try os.sigaction(os.SIG.USR1, &sa, null); | 779 | try os.sigaction(os.SIG.USR1, &sa, null); |
| 780 | |||
| 779 | // Check that we can read it back correctly. | 781 | // Check that we can read it back correctly. |
| 780 | try os.sigaction(os.SIG.USR1, null, &old_sa); | 782 | try os.sigaction(os.SIG.USR1, null, &old_sa); |
| 781 | try testing.expectEqual(actual_handler, old_sa.handler.sigaction.?); | 783 | try testing.expectEqual(actual_handler, old_sa.handler.sigaction.?); |
| 782 | try testing.expect((old_sa.flags & os.SA.SIGINFO) != 0); | 784 | try testing.expect((old_sa.flags & os.SA.SIGINFO) != 0); |
| 785 | |||
| 783 | // Invoke the handler. | 786 | // Invoke the handler. |
| 784 | try os.raise(os.SIG.USR1); | 787 | try os.raise(os.SIG.USR1); |
| 785 | try testing.expect(signal_test_failed == false); | 788 | try testing.expect(S.handler_called_count == 1); |
| 786 | // Check if the handler has been correctly reset to SIG_DFL | 789 | |
| 790 | // Check if passing RESETHAND correctly reset the handler to SIG_DFL | ||
| 787 | try os.sigaction(os.SIG.USR1, null, &old_sa); | 791 | try os.sigaction(os.SIG.USR1, null, &old_sa); |
| 788 | try testing.expectEqual(os.SIG.DFL, old_sa.handler.handler); | 792 | try testing.expectEqual(os.SIG.DFL, old_sa.handler.handler); |
| 793 | |||
| 794 | // Reinstall the signal w/o RESETHAND and re-raise | ||
| 795 | sa.flags = os.SA.SIGINFO; | ||
| 796 | try os.sigaction(os.SIG.USR1, &sa, null); | ||
| 797 | try os.raise(os.SIG.USR1); | ||
| 798 | try testing.expect(S.handler_called_count == 2); | ||
| 799 | |||
| 800 | // Now set the signal to ignored | ||
| 801 | sa.handler = .{ .handler = os.SIG.IGN }; | ||
| 802 | sa.flags = 0; | ||
| 803 | try os.sigaction(os.SIG.USR1, &sa, null); | ||
| 804 | |||
| 805 | // Re-raise to ensure handler is actually ignored | ||
| 806 | try os.raise(os.SIG.USR1); | ||
| 807 | try testing.expect(S.handler_called_count == 2); | ||
| 808 | |||
| 809 | // Ensure that ignored state is returned when querying | ||
| 810 | try os.sigaction(os.SIG.USR1, null, &old_sa); | ||
| 811 | try testing.expectEqual(os.SIG.IGN, old_sa.handler.handler.?); | ||
| 789 | } | 812 | } |
| 790 | 813 | ||
| 791 | test "dup & dup2" { | 814 | test "dup & dup2" { |