| author | |
| committer | |
| log | 629cc6cf285f60581f03b69ec8d012d2e370a029 |
| tree | c616cc3bdb5096753d4c6981a2be4a2257dd16bb |
| parent | 1d9b28403a1074cbbbd0605f07819136c9f96cdc |
* Define siginfo and sigaction for Darwin
* Define sigaction/handler union for maximum libc compatibility
* Minor correction to some type definitions9 files changed, 91 insertions(+), 41 deletions(-)
lib/std/debug.zig+2-2| ... | ... | @@ -1721,7 +1721,7 @@ pub fn attachSegfaultHandler() void { |
| 1721 | 1721 | return; |
| 1722 | 1722 | } |
| 1723 | 1723 | var act = os.Sigaction{ |
| 1724 | .sigaction = handleSegfaultLinux, | |
| 1724 | .handler = .{ .sigaction = handleSegfaultLinux }, | |
| 1725 | 1725 | .mask = os.empty_sigset, |
| 1726 | 1726 | .flags = (os.SA_SIGINFO | os.SA_RESTART | os.SA_RESETHAND), |
| 1727 | 1727 | }; |
| ... | ... | @@ -1740,7 +1740,7 @@ fn resetSegfaultHandler() void { |
| 1740 | 1740 | return; |
| 1741 | 1741 | } |
| 1742 | 1742 | var act = os.Sigaction{ |
| 1743 | .sigaction = os.SIG_DFL, | |
| 1743 | .handler = .{ .sigaction = os.SIG_DFL }, | |
| 1744 | 1744 | .mask = os.empty_sigset, |
| 1745 | 1745 | .flags = 0, |
| 1746 | 1746 | }; |
lib/std/os/bits/darwin.zig+26-4| ... | ... | @@ -124,13 +124,35 @@ pub const timespec = extern struct { |
| 124 | 124 | }; |
| 125 | 125 | |
| 126 | 126 | pub const sigset_t = u32; |
| 127 | pub const empty_sigset = sigset_t(0); | |
| 127 | pub const empty_sigset: sigset_t = 0; | |
| 128 | ||
| 129 | pub const siginfo_t = extern struct { | |
| 130 | signo: c_int, | |
| 131 | errno: c_int, | |
| 132 | code: c_int, | |
| 133 | pid: pid_t, | |
| 134 | uid: uid_t, | |
| 135 | status: c_int, | |
| 136 | addr: *c_void, | |
| 137 | value: extern union { | |
| 138 | int: c_int, | |
| 139 | ptr: *c_void, | |
| 140 | }, | |
| 141 | si_band: c_long, | |
| 142 | _pad: [7]c_ulong, | |
| 143 | }; | |
| 128 | 144 | |
| 129 | 145 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with function name. |
| 130 | 146 | pub const Sigaction = extern struct { |
| 131 | handler: fn (c_int) callconv(.C) void, | |
| 132 | sa_mask: sigset_t, | |
| 133 | sa_flags: c_int, | |
| 147 | pub const handler_fn = fn (c_int) callconv(.C) void; | |
| 148 | pub const sigaction_fn = fn (c_int, *const siginfo_t, ?*const c_void) callconv(.C) void; | |
| 149 | ||
| 150 | handler: extern union { | |
| 151 | handler: ?handler_fn, | |
| 152 | sigaction: ?sigaction_fn, | |
| 153 | }, | |
| 154 | mask: sigset_t, | |
| 155 | flags: c_uint, | |
| 134 | 156 | }; |
| 135 | 157 | |
| 136 | 158 | pub const dirent = extern struct { |
lib/std/os/bits/dragonfly.zig+9-5| ... | ... | @@ -530,12 +530,16 @@ pub const sigset_t = extern struct { |
| 530 | 530 | }; |
| 531 | 531 | pub const sig_atomic_t = c_int; |
| 532 | 532 | pub const Sigaction = extern struct { |
| 533 | __sigaction_u: extern union { | |
| 534 | __sa_handler: ?fn (c_int) callconv(.C) void, | |
| 535 | __sa_sigaction: ?fn (c_int, [*c]siginfo_t, ?*c_void) callconv(.C) void, | |
| 533 | pub const handler_fn = fn (c_int) callconv(.C) void; | |
| 534 | pub const sigaction_fn = fn (c_int, *const siginfo_t, ?*const c_void) callconv(.C) void; | |
| 535 | ||
| 536 | /// signal handler | |
| 537 | handler: extern union { | |
| 538 | handler: ?handler_fn, | |
| 539 | sigaction: ?sigaction_fn, | |
| 536 | 540 | }, |
| 537 | sa_flags: c_int, | |
| 538 | sa_mask: sigset_t, | |
| 541 | flags: c_uint, | |
| 542 | mask: sigset_t, | |
| 539 | 543 | }; |
| 540 | 544 | pub const sig_t = [*c]fn (c_int) callconv(.C) void; |
| 541 | 545 |
lib/std/os/bits/freebsd.zig+7-4| ... | ... | @@ -742,14 +742,17 @@ pub const SIG_IGN = @intToPtr(fn (i32) callconv(.C) void, 1); |
| 742 | 742 | |
| 743 | 743 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. |
| 744 | 744 | pub const Sigaction = extern struct { |
| 745 | pub const handler_fn = fn (c_int) callconv(.C) void; | |
| 746 | pub const sigaction_fn = fn (c_int, *const siginfo_t, ?*const c_void) callconv(.C) void; | |
| 747 | ||
| 745 | 748 | /// signal handler |
| 746 | __sigaction_u: extern union { | |
| 747 | __sa_handler: fn (i32) callconv(.C) void, | |
| 748 | __sa_sigaction: fn (i32, *__siginfo, usize) callconv(.C) void, | |
| 749 | handler: extern union { | |
| 750 | handler: ?handler_fn, | |
| 751 | sigaction: ?sigaction_fn, | |
| 749 | 752 | }, |
| 750 | 753 | |
| 751 | 754 | /// see signal options |
| 752 | sa_flags: u32, | |
| 755 | sa_flags: c_uint, | |
| 753 | 756 | |
| 754 | 757 | /// signal mask to apply |
| 755 | 758 | sa_mask: sigset_t, |
lib/std/os/bits/linux.zig+26-15| ... | ... | @@ -864,27 +864,38 @@ pub const sigset_t = [1024 / 32]u32; |
| 864 | 864 | pub const all_mask: sigset_t = [_]u32{0xffffffff} ** sigset_t.len; |
| 865 | 865 | pub const app_mask: sigset_t = [2]u32{ 0xfffffffc, 0x7fffffff } ++ [_]u32{0xffffffff} ** 30; |
| 866 | 866 | |
| 867 | pub const k_sigaction = if (is_mips) | |
| 868 | extern struct { | |
| 869 | flags: usize, | |
| 870 | sigaction: ?fn (i32, *const siginfo_t, ?*const c_void) callconv(.C) void, | |
| 871 | mask: [4]u32, | |
| 867 | pub const k_sigaction = switch (builtin.arch) { | |
| 868 | .mips, .mipsel => extern struct { | |
| 869 | flags: c_uint, | |
| 870 | handler: ?fn (c_int) callconv(.C) void, | |
| 871 | mask: [4]c_ulong, | |
| 872 | 872 | restorer: fn () callconv(.C) void, |
| 873 | } | |
| 874 | else | |
| 875 | extern struct { | |
| 876 | sigaction: ?fn (i32, *const siginfo_t, ?*const c_void) callconv(.C) void, | |
| 877 | flags: usize, | |
| 873 | }, | |
| 874 | .mips64, .mips64el => extern struct { | |
| 875 | flags: c_uint, | |
| 876 | handler: ?fn (c_int) callconv(.C) void, | |
| 877 | mask: [2]c_ulong, | |
| 878 | 878 | restorer: fn () callconv(.C) void, |
| 879 | mask: [2]u32, | |
| 880 | }; | |
| 879 | }, | |
| 880 | else => extern struct { | |
| 881 | handler: ?fn (c_int) callconv(.C) void, | |
| 882 | flags: c_ulong, | |
| 883 | restorer: fn () callconv(.C) void, | |
| 884 | mask: [2]c_uint, | |
| 885 | }, | |
| 886 | }; | |
| 881 | 887 | |
| 882 | 888 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. |
| 883 | 889 | pub const Sigaction = extern struct { |
| 884 | pub const sigaction_fn = fn (i32, *const siginfo_t, ?*const c_void) callconv(.C) void; | |
| 885 | sigaction: ?sigaction_fn, | |
| 890 | pub const handler_fn = fn (c_int) callconv(.C) void; | |
| 891 | pub const sigaction_fn = fn (c_int, *const siginfo_t, ?*const c_void) callconv(.C) void; | |
| 892 | ||
| 893 | handler: extern union { | |
| 894 | handler: ?handler_fn, | |
| 895 | sigaction: ?sigaction_fn, | |
| 896 | }, | |
| 886 | 897 | mask: sigset_t, |
| 887 | flags: u32, | |
| 898 | flags: c_uint, | |
| 888 | 899 | restorer: ?fn () callconv(.C) void = null, |
| 889 | 900 | }; |
| 890 | 901 |
lib/std/os/bits/netbsd.zig+8-3| ... | ... | @@ -716,13 +716,18 @@ pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1); |
| 716 | 716 | |
| 717 | 717 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. |
| 718 | 718 | pub const Sigaction = extern struct { |
| 719 | pub const sigaction_fn = fn (i32, *siginfo_t, ?*c_void) callconv(.C) void; | |
| 719 | pub const handler_fn = fn (c_int) callconv(.C) void; | |
| 720 | pub const sigaction_fn = fn (c_int, *const siginfo_t, ?*const c_void) callconv(.C) void; | |
| 721 | ||
| 720 | 722 | /// signal handler |
| 721 | sigaction: ?sigaction_fn, | |
| 723 | handler: extern union { | |
| 724 | handler: ?handler_fn, | |
| 725 | sigaction: ?sigaction_fn, | |
| 726 | }, | |
| 722 | 727 | /// signal mask to apply |
| 723 | 728 | mask: sigset_t, |
| 724 | 729 | /// signal options |
| 725 | flags: u32, | |
| 730 | flags: c_uint, | |
| 726 | 731 | }; |
| 727 | 732 | |
| 728 | 733 | pub const sigval_t = extern union { |
lib/std/os/bits/openbsd.zig+8-3| ... | ... | @@ -753,13 +753,18 @@ pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1); |
| 753 | 753 | |
| 754 | 754 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. |
| 755 | 755 | pub const Sigaction = extern struct { |
| 756 | pub const sigaction_fn = fn (c_int, *siginfo_t, ?*c_void) callconv(.C) void; | |
| 756 | pub const handler_fn = fn (c_int) callconv(.C) void; | |
| 757 | pub const sigaction_fn = fn (c_int, *const siginfo_t, ?*const c_void) callconv(.C) void; | |
| 758 | ||
| 757 | 759 | /// signal handler |
| 758 | sigaction: ?sigaction_fn, | |
| 760 | handler: extern union { | |
| 761 | handler: ?handler_fn, | |
| 762 | sigaction: ?sigaction_fn, | |
| 763 | }, | |
| 759 | 764 | /// signal mask to apply |
| 760 | 765 | mask: sigset_t, |
| 761 | 766 | /// signal options |
| 762 | flags: c_int, | |
| 767 | flags: c_uint, | |
| 763 | 768 | }; |
| 764 | 769 | |
| 765 | 770 | pub const sigval = extern union { |
lib/std/os/linux.zig+3-3| ... | ... | @@ -869,7 +869,7 @@ pub fn sigaction(sig: u6, noalias act: ?*const Sigaction, noalias oact: ?*Sigact |
| 869 | 869 | if (act) |new| { |
| 870 | 870 | const restorer_fn = if ((new.flags & SA_SIGINFO) != 0) restore_rt else restore; |
| 871 | 871 | ksa = k_sigaction{ |
| 872 | .sigaction = new.sigaction, | |
| 872 | .handler = new.handler.handler, | |
| 873 | 873 | .flags = new.flags | SA_RESTORER, |
| 874 | 874 | .mask = undefined, |
| 875 | 875 | .restorer = @ptrCast(fn () callconv(.C) void, restorer_fn), |
| ... | ... | @@ -888,8 +888,8 @@ pub fn sigaction(sig: u6, noalias act: ?*const Sigaction, noalias oact: ?*Sigact |
| 888 | 888 | if (getErrno(result) != 0) return result; |
| 889 | 889 | |
| 890 | 890 | if (oact) |old| { |
| 891 | old.sigaction = oldksa.sigaction; | |
| 892 | old.flags = @truncate(u32, oldksa.flags); | |
| 891 | old.handler.handler = oldksa.handler; | |
| 892 | old.flags = @truncate(c_uint, oldksa.flags); | |
| 893 | 893 | @memcpy(@ptrCast([*]u8, &old.mask), @ptrCast([*]const u8, &oldksa.mask), mask_size); |
| 894 | 894 | } |
| 895 | 895 |
lib/std/os/test.zig+2-2| ... | ... | @@ -662,7 +662,7 @@ test "sigaction" { |
| 662 | 662 | }; |
| 663 | 663 | |
| 664 | 664 | var sa = os.Sigaction{ |
| 665 | .sigaction = S.handler, | |
| 665 | .handler = .{ .sigaction = S.handler }, | |
| 666 | 666 | .mask = os.empty_sigset, |
| 667 | 667 | .flags = os.SA_SIGINFO | os.SA_RESETHAND, |
| 668 | 668 | }; |
| ... | ... | @@ -671,7 +671,7 @@ test "sigaction" { |
| 671 | 671 | os.sigaction(os.SIGUSR1, &sa, null); |
| 672 | 672 | // Check that we can read it back correctly. |
| 673 | 673 | os.sigaction(os.SIGUSR1, null, &old_sa); |
| 674 | testing.expectEqual(S.handler, old_sa.sigaction.?); | |
| 674 | testing.expectEqual(S.handler, old_sa.handler.sigaction.?); | |
| 675 | 675 | testing.expect((old_sa.flags & os.SA_RESETHAND) != 0); |
| 676 | 676 | // Invoke the handler. |
| 677 | 677 | try os.raise(os.SIGUSR1); |