authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-27 16:16:49-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-29 06:20:51-07:00
log8b269f7e18ee1e0874b7cbf7cf2853b7e34b6a36
tree2ddc9ef9825a4a3fe8bc88a14d5edc028ae96ea5
parentcc751c01f13658280bc48905261f316b9b58b718

std: make signal numbers into an enum

fixes start logic for checking whether IO/POLL exist

12 files changed, 579 insertions(+), 656 deletions(-)

lib/std/Io/Threaded.zig+2-2
...@@ -75,10 +75,10 @@ const Closure = struct {...@@ -75,10 +75,10 @@ const Closure = struct {
75 .none, .canceling => {},75 .none, .canceling => {},
76 else => |tid| {76 else => |tid| {
77 if (std.Thread.use_pthreads) {77 if (std.Thread.use_pthreads) {
78 const rc = std.c.pthread_kill(tid.toThreadId(), posix.SIG.IO);78 const rc = std.c.pthread_kill(tid.toThreadId(), .IO);
79 if (is_debug) assert(rc == 0);79 if (is_debug) assert(rc == 0);
80 } else if (native_os == .linux) {80 } else if (native_os == .linux) {
81 _ = std.os.linux.tgkill(std.os.linux.getpid(), @bitCast(tid.toThreadId()), posix.SIG.IO);81 _ = std.os.linux.tgkill(std.os.linux.getpid(), @bitCast(tid.toThreadId()), .IO);
82 }82 }
83 },83 },
84 }84 }
lib/std/Progress.zig+3-3
...@@ -493,7 +493,7 @@ pub fn start(options: Options) Node {...@@ -493,7 +493,7 @@ pub fn start(options: Options) Node {
493 .mask = posix.sigemptyset(),493 .mask = posix.sigemptyset(),
494 .flags = (posix.SA.SIGINFO | posix.SA.RESTART),494 .flags = (posix.SA.SIGINFO | posix.SA.RESTART),
495 };495 };
496 posix.sigaction(posix.SIG.WINCH, &act, null);496 posix.sigaction(.WINCH, &act, null);
497 }497 }
498498
499 if (switch (global_progress.terminal_mode) {499 if (switch (global_progress.terminal_mode) {
...@@ -1535,10 +1535,10 @@ fn maybeUpdateSize(resize_flag: bool) void {...@@ -1535,10 +1535,10 @@ fn maybeUpdateSize(resize_flag: bool) void {
1535 }1535 }
1536}1536}
15371537
1538fn handleSigWinch(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.c) void {1538fn handleSigWinch(sig: posix.SIG, info: *const posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.c) void {
1539 _ = info;1539 _ = info;
1540 _ = ctx_ptr;1540 _ = ctx_ptr;
1541 assert(sig == posix.SIG.WINCH);1541 assert(sig == .WINCH);
1542 global_progress.redraw_event.set();1542 global_progress.redraw_event.set();
1543}1543}
15441544
lib/std/c.zig+353-348
...@@ -2587,25 +2587,24 @@ pub const SHUT = switch (native_os) {...@@ -2587,25 +2587,24 @@ pub const SHUT = switch (native_os) {
25872587
2588/// Signal types2588/// Signal types
2589pub const SIG = switch (native_os) {2589pub const SIG = switch (native_os) {
2590 .linux => linux.SIG,2590 .linux, .emscripten => linux.SIG,
2591 .emscripten => emscripten.SIG,2591 .windows => enum(u32) {
2592 .windows => struct {
2593 /// interrupt2592 /// interrupt
2594 pub const INT = 2;2593 INT = 2,
2595 /// illegal instruction - invalid function image2594 /// illegal instruction - invalid function image
2596 pub const ILL = 4;2595 ILL = 4,
2597 /// floating point exception2596 /// floating point exception
2598 pub const FPE = 8;2597 FPE = 8,
2599 /// segment violation2598 /// segment violation
2600 pub const SEGV = 11;2599 SEGV = 11,
2601 /// Software termination signal from kill2600 /// Software termination signal from kill
2602 pub const TERM = 15;2601 TERM = 15,
2603 /// Ctrl-Break sequence2602 /// Ctrl-Break sequence
2604 pub const BREAK = 21;2603 BREAK = 21,
2605 /// abnormal termination triggered by abort call2604 /// abnormal termination triggered by abort call
2606 pub const ABRT = 22;2605 ABRT = 22,
2607 /// SIGABRT compatible with other platforms, same as SIGABRT2606 /// SIGABRT compatible with other platforms, same as SIGABRT
2608 pub const ABRT_COMPAT = 6;2607 ABRT_COMPAT = 6,
26092608
2610 // Signal action codes2609 // Signal action codes
2611 /// default signal action2610 /// default signal action
...@@ -2621,7 +2620,7 @@ pub const SIG = switch (native_os) {...@@ -2621,7 +2620,7 @@ pub const SIG = switch (native_os) {
2621 /// Signal error value (returned by signal call on error)2620 /// Signal error value (returned by signal call on error)
2622 pub const ERR = -1;2621 pub const ERR = -1;
2623 },2622 },
2624 .macos, .ios, .tvos, .watchos, .visionos => struct {2623 .macos, .ios, .tvos, .watchos, .visionos => enum(u32) {
2625 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));2624 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
2626 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);2625 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
2627 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);2626 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
...@@ -2633,113 +2632,74 @@ pub const SIG = switch (native_os) {...@@ -2633,113 +2632,74 @@ pub const SIG = switch (native_os) {
2633 pub const UNBLOCK = 2;2632 pub const UNBLOCK = 2;
2634 /// set specified signal set2633 /// set specified signal set
2635 pub const SETMASK = 3;2634 pub const SETMASK = 3;
2635
2636 pub const IOT: SIG = .ABRT;
2637 pub const POLL: SIG = .EMT;
2638
2636 /// hangup2639 /// hangup
2637 pub const HUP = 1;2640 HUP = 1,
2638 /// interrupt2641 /// interrupt
2639 pub const INT = 2;2642 INT = 2,
2640 /// quit2643 /// quit
2641 pub const QUIT = 3;2644 QUIT = 3,
2642 /// illegal instruction (not reset when caught)2645 /// illegal instruction (not reset when caught)
2643 pub const ILL = 4;2646 ILL = 4,
2644 /// trace trap (not reset when caught)2647 /// trace trap (not reset when caught)
2645 pub const TRAP = 5;2648 TRAP = 5,
2646 /// abort()2649 /// abort()
2647 pub const ABRT = 6;2650 ABRT = 6,
2648 /// pollable event ([XSR] generated, not supported)
2649 pub const POLL = 7;
2650 /// compatibility
2651 pub const IOT = ABRT;
2652 /// EMT instruction2651 /// EMT instruction
2653 pub const EMT = 7;2652 EMT = 7,
2654 /// floating point exception2653 /// floating point exception
2655 pub const FPE = 8;2654 FPE = 8,
2656 /// kill (cannot be caught or ignored)2655 /// kill (cannot be caught or ignored)
2657 pub const KILL = 9;2656 KILL = 9,
2658 /// bus error2657 /// bus error
2659 pub const BUS = 10;2658 BUS = 10,
2660 /// segmentation violation2659 /// segmentation violation
2661 pub const SEGV = 11;2660 SEGV = 11,
2662 /// bad argument to system call2661 /// bad argument to system call
2663 pub const SYS = 12;2662 SYS = 12,
2664 /// write on a pipe with no one to read it2663 /// write on a pipe with no one to read it
2665 pub const PIPE = 13;2664 PIPE = 13,
2666 /// alarm clock2665 /// alarm clock
2667 pub const ALRM = 14;2666 ALRM = 14,
2668 /// software termination signal from kill2667 /// software termination signal from kill
2669 pub const TERM = 15;2668 TERM = 15,
2670 /// urgent condition on IO channel2669 /// urgent condition on IO channel
2671 pub const URG = 16;2670 URG = 16,
2672 /// sendable stop signal not from tty2671 /// sendable stop signal not from tty
2673 pub const STOP = 17;2672 STOP = 17,
2674 /// stop signal from tty2673 /// stop signal from tty
2675 pub const TSTP = 18;2674 TSTP = 18,
2676 /// continue a stopped process2675 /// continue a stopped process
2677 pub const CONT = 19;2676 CONT = 19,
2678 /// to parent on child stop or exit2677 /// to parent on child stop or exit
2679 pub const CHLD = 20;2678 CHLD = 20,
2680 /// to readers pgrp upon background tty read2679 /// to readers pgrp upon background tty read
2681 pub const TTIN = 21;2680 TTIN = 21,
2682 /// like TTIN for output if (tp->t_local&LTOSTOP)2681 /// like TTIN for output if (tp->t_local&LTOSTOP)
2683 pub const TTOU = 22;2682 TTOU = 22,
2684 /// input/output possible signal2683 /// input/output possible signal
2685 pub const IO = 23;2684 IO = 23,
2686 /// exceeded CPU time limit2685 /// exceeded CPU time limit
2687 pub const XCPU = 24;2686 XCPU = 24,
2688 /// exceeded file size limit2687 /// exceeded file size limit
2689 pub const XFSZ = 25;2688 XFSZ = 25,
2690 /// virtual time alarm2689 /// virtual time alarm
2691 pub const VTALRM = 26;2690 VTALRM = 26,
2692 /// profiling time alarm2691 /// profiling time alarm
2693 pub const PROF = 27;2692 PROF = 27,
2694 /// window size changes2693 /// window size changes
2695 pub const WINCH = 28;2694 WINCH = 28,
2696 /// information request2695 /// information request
2697 pub const INFO = 29;2696 INFO = 29,
2698 /// user defined signal 12697 /// user defined signal 1
2699 pub const USR1 = 30;2698 USR1 = 30,
2700 /// user defined signal 22699 /// user defined signal 2
2701 pub const USR2 = 31;2700 USR2 = 31,
2702 },2701 },
2703 .freebsd => struct {2702 .freebsd => enum(u32) {
2704 pub const HUP = 1;
2705 pub const INT = 2;
2706 pub const QUIT = 3;
2707 pub const ILL = 4;
2708 pub const TRAP = 5;
2709 pub const ABRT = 6;
2710 pub const IOT = ABRT;
2711 pub const EMT = 7;
2712 pub const FPE = 8;
2713 pub const KILL = 9;
2714 pub const BUS = 10;
2715 pub const SEGV = 11;
2716 pub const SYS = 12;
2717 pub const PIPE = 13;
2718 pub const ALRM = 14;
2719 pub const TERM = 15;
2720 pub const URG = 16;
2721 pub const STOP = 17;
2722 pub const TSTP = 18;
2723 pub const CONT = 19;
2724 pub const CHLD = 20;
2725 pub const TTIN = 21;
2726 pub const TTOU = 22;
2727 pub const IO = 23;
2728 pub const XCPU = 24;
2729 pub const XFSZ = 25;
2730 pub const VTALRM = 26;
2731 pub const PROF = 27;
2732 pub const WINCH = 28;
2733 pub const INFO = 29;
2734 pub const USR1 = 30;
2735 pub const USR2 = 31;
2736 pub const THR = 32;
2737 pub const LWP = THR;
2738 pub const LIBRT = 33;
2739
2740 pub const RTMIN = 65;
2741 pub const RTMAX = 126;
2742
2743 pub const BLOCK = 1;2703 pub const BLOCK = 1;
2744 pub const UNBLOCK = 2;2704 pub const UNBLOCK = 2;
2745 pub const SETMASK = 3;2705 pub const SETMASK = 3;
...@@ -2763,8 +2723,48 @@ pub const SIG = switch (native_os) {...@@ -2763,8 +2723,48 @@ pub const SIG = switch (native_os) {
2763 pub inline fn VALID(sig: usize) usize {2723 pub inline fn VALID(sig: usize) usize {
2764 return sig <= MAXSIG and sig > 0;2724 return sig <= MAXSIG and sig > 0;
2765 }2725 }
2726
2727 pub const IOT: SIG = .ABRT;
2728 pub const LWP: SIG = .THR;
2729
2730 pub const RTMIN = 65;
2731 pub const RTMAX = 126;
2732
2733 HUP = 1,
2734 INT = 2,
2735 QUIT = 3,
2736 ILL = 4,
2737 TRAP = 5,
2738 ABRT = 6,
2739 EMT = 7,
2740 FPE = 8,
2741 KILL = 9,
2742 BUS = 10,
2743 SEGV = 11,
2744 SYS = 12,
2745 PIPE = 13,
2746 ALRM = 14,
2747 TERM = 15,
2748 URG = 16,
2749 STOP = 17,
2750 TSTP = 18,
2751 CONT = 19,
2752 CHLD = 20,
2753 TTIN = 21,
2754 TTOU = 22,
2755 IO = 23,
2756 XCPU = 24,
2757 XFSZ = 25,
2758 VTALRM = 26,
2759 PROF = 27,
2760 WINCH = 28,
2761 INFO = 29,
2762 USR1 = 30,
2763 USR2 = 31,
2764 THR = 32,
2765 LIBRT = 33,
2766 },2766 },
2767 .illumos => struct {2767 .illumos => enum(u32) {
2768 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);2768 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
2769 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));2769 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
2770 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);2770 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
...@@ -2773,54 +2773,9 @@ pub const SIG = switch (native_os) {...@@ -2773,54 +2773,9 @@ pub const SIG = switch (native_os) {
2773 pub const WORDS = 4;2773 pub const WORDS = 4;
2774 pub const MAXSIG = 75;2774 pub const MAXSIG = 75;
27752775
2776 pub const SIG_BLOCK = 1;2776 pub const BLOCK = 1;
2777 pub const SIG_UNBLOCK = 2;2777 pub const UNBLOCK = 2;
2778 pub const SIG_SETMASK = 3;2778 pub const SETMASK = 3;
2779
2780 pub const HUP = 1;
2781 pub const INT = 2;
2782 pub const QUIT = 3;
2783 pub const ILL = 4;
2784 pub const TRAP = 5;
2785 pub const IOT = 6;
2786 pub const ABRT = 6;
2787 pub const EMT = 7;
2788 pub const FPE = 8;
2789 pub const KILL = 9;
2790 pub const BUS = 10;
2791 pub const SEGV = 11;
2792 pub const SYS = 12;
2793 pub const PIPE = 13;
2794 pub const ALRM = 14;
2795 pub const TERM = 15;
2796 pub const USR1 = 16;
2797 pub const USR2 = 17;
2798 pub const CLD = 18;
2799 pub const CHLD = 18;
2800 pub const PWR = 19;
2801 pub const WINCH = 20;
2802 pub const URG = 21;
2803 pub const POLL = 22;
2804 pub const IO = .POLL;
2805 pub const STOP = 23;
2806 pub const TSTP = 24;
2807 pub const CONT = 25;
2808 pub const TTIN = 26;
2809 pub const TTOU = 27;
2810 pub const VTALRM = 28;
2811 pub const PROF = 29;
2812 pub const XCPU = 30;
2813 pub const XFSZ = 31;
2814 pub const WAITING = 32;
2815 pub const LWP = 33;
2816 pub const FREEZE = 34;
2817 pub const THAW = 35;
2818 pub const CANCEL = 36;
2819 pub const LOST = 37;
2820 pub const XRES = 38;
2821 pub const JVM1 = 39;
2822 pub const JVM2 = 40;
2823 pub const INFO = 41;
28242779
2825 pub const RTMIN = 42;2780 pub const RTMIN = 42;
2826 pub const RTMAX = 74;2781 pub const RTMAX = 74;
...@@ -2837,8 +2792,54 @@ pub const SIG = switch (native_os) {...@@ -2837,8 +2792,54 @@ pub const SIG = switch (native_os) {
2837 pub inline fn VALID(sig: usize) usize {2792 pub inline fn VALID(sig: usize) usize {
2838 return sig <= MAXSIG and sig > 0;2793 return sig <= MAXSIG and sig > 0;
2839 }2794 }
2795
2796 pub const POLL: SIG = .IO;
2797
2798 HUP = 1,
2799 INT = 2,
2800 QUIT = 3,
2801 ILL = 4,
2802 TRAP = 5,
2803 IOT = 6,
2804 ABRT = 6,
2805 EMT = 7,
2806 FPE = 8,
2807 KILL = 9,
2808 BUS = 10,
2809 SEGV = 11,
2810 SYS = 12,
2811 PIPE = 13,
2812 ALRM = 14,
2813 TERM = 15,
2814 USR1 = 16,
2815 USR2 = 17,
2816 CLD = 18,
2817 CHLD = 18,
2818 PWR = 19,
2819 WINCH = 20,
2820 URG = 21,
2821 IO = 22,
2822 STOP = 23,
2823 TSTP = 24,
2824 CONT = 25,
2825 TTIN = 26,
2826 TTOU = 27,
2827 VTALRM = 28,
2828 PROF = 29,
2829 XCPU = 30,
2830 XFSZ = 31,
2831 WAITING = 32,
2832 LWP = 33,
2833 FREEZE = 34,
2834 THAW = 35,
2835 CANCEL = 36,
2836 LOST = 37,
2837 XRES = 38,
2838 JVM1 = 39,
2839 JVM2 = 40,
2840 INFO = 41,
2840 },2841 },
2841 .netbsd => struct {2842 .netbsd => enum(u32) {
2842 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);2843 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
2843 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);2844 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
2844 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));2845 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
...@@ -2850,40 +2851,6 @@ pub const SIG = switch (native_os) {...@@ -2850,40 +2851,6 @@ pub const SIG = switch (native_os) {
2850 pub const UNBLOCK = 2;2851 pub const UNBLOCK = 2;
2851 pub const SETMASK = 3;2852 pub const SETMASK = 3;
28522853
2853 pub const HUP = 1;
2854 pub const INT = 2;
2855 pub const QUIT = 3;
2856 pub const ILL = 4;
2857 pub const TRAP = 5;
2858 pub const ABRT = 6;
2859 pub const IOT = ABRT;
2860 pub const EMT = 7;
2861 pub const FPE = 8;
2862 pub const KILL = 9;
2863 pub const BUS = 10;
2864 pub const SEGV = 11;
2865 pub const SYS = 12;
2866 pub const PIPE = 13;
2867 pub const ALRM = 14;
2868 pub const TERM = 15;
2869 pub const URG = 16;
2870 pub const STOP = 17;
2871 pub const TSTP = 18;
2872 pub const CONT = 19;
2873 pub const CHLD = 20;
2874 pub const TTIN = 21;
2875 pub const TTOU = 22;
2876 pub const IO = 23;
2877 pub const XCPU = 24;
2878 pub const XFSZ = 25;
2879 pub const VTALRM = 26;
2880 pub const PROF = 27;
2881 pub const WINCH = 28;
2882 pub const INFO = 29;
2883 pub const USR1 = 30;
2884 pub const USR2 = 31;
2885 pub const PWR = 32;
2886
2887 pub const RTMIN = 33;2854 pub const RTMIN = 33;
2888 pub const RTMAX = 63;2855 pub const RTMAX = 63;
28892856
...@@ -2899,8 +2866,43 @@ pub const SIG = switch (native_os) {...@@ -2899,8 +2866,43 @@ pub const SIG = switch (native_os) {
2899 pub inline fn VALID(sig: usize) usize {2866 pub inline fn VALID(sig: usize) usize {
2900 return sig <= MAXSIG and sig > 0;2867 return sig <= MAXSIG and sig > 0;
2901 }2868 }
2869
2870 pub const IOT: SIG = .ABRT;
2871
2872 HUP = 1,
2873 INT = 2,
2874 QUIT = 3,
2875 ILL = 4,
2876 TRAP = 5,
2877 ABRT = 6,
2878 EMT = 7,
2879 FPE = 8,
2880 KILL = 9,
2881 BUS = 10,
2882 SEGV = 11,
2883 SYS = 12,
2884 PIPE = 13,
2885 ALRM = 14,
2886 TERM = 15,
2887 URG = 16,
2888 STOP = 17,
2889 TSTP = 18,
2890 CONT = 19,
2891 CHLD = 20,
2892 TTIN = 21,
2893 TTOU = 22,
2894 IO = 23,
2895 XCPU = 24,
2896 XFSZ = 25,
2897 VTALRM = 26,
2898 PROF = 27,
2899 WINCH = 28,
2900 INFO = 29,
2901 USR1 = 30,
2902 USR2 = 31,
2903 PWR = 32,
2902 },2904 },
2903 .dragonfly => struct {2905 .dragonfly => enum(u32) {
2904 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);2906 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
2905 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);2907 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
2906 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));2908 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
...@@ -2909,137 +2911,140 @@ pub const SIG = switch (native_os) {...@@ -2909,137 +2911,140 @@ pub const SIG = switch (native_os) {
2909 pub const UNBLOCK = 2;2911 pub const UNBLOCK = 2;
2910 pub const SETMASK = 3;2912 pub const SETMASK = 3;
29112913
2912 pub const IOT = ABRT;
2913 pub const HUP = 1;
2914 pub const INT = 2;
2915 pub const QUIT = 3;
2916 pub const ILL = 4;
2917 pub const TRAP = 5;
2918 pub const ABRT = 6;
2919 pub const EMT = 7;
2920 pub const FPE = 8;
2921 pub const KILL = 9;
2922 pub const BUS = 10;
2923 pub const SEGV = 11;
2924 pub const SYS = 12;
2925 pub const PIPE = 13;
2926 pub const ALRM = 14;
2927 pub const TERM = 15;
2928 pub const URG = 16;
2929 pub const STOP = 17;
2930 pub const TSTP = 18;
2931 pub const CONT = 19;
2932 pub const CHLD = 20;
2933 pub const TTIN = 21;
2934 pub const TTOU = 22;
2935 pub const IO = 23;
2936 pub const XCPU = 24;
2937 pub const XFSZ = 25;
2938 pub const VTALRM = 26;
2939 pub const PROF = 27;
2940 pub const WINCH = 28;
2941 pub const INFO = 29;
2942 pub const USR1 = 30;
2943 pub const USR2 = 31;
2944 pub const THR = 32;
2945 pub const CKPT = 33;
2946 pub const CKPTEXIT = 34;
2947
2948 pub const WORDS = 4;2914 pub const WORDS = 4;
2949 },2915
2950 .haiku => struct {2916 pub const IOT: SIG = .ABRT;
2917
2918 HUP = 1,
2919 INT = 2,
2920 QUIT = 3,
2921 ILL = 4,
2922 TRAP = 5,
2923 ABRT = 6,
2924 EMT = 7,
2925 FPE = 8,
2926 KILL = 9,
2927 BUS = 10,
2928 SEGV = 11,
2929 SYS = 12,
2930 PIPE = 13,
2931 ALRM = 14,
2932 TERM = 15,
2933 URG = 16,
2934 STOP = 17,
2935 TSTP = 18,
2936 CONT = 19,
2937 CHLD = 20,
2938 TTIN = 21,
2939 TTOU = 22,
2940 IO = 23,
2941 XCPU = 24,
2942 XFSZ = 25,
2943 VTALRM = 26,
2944 PROF = 27,
2945 WINCH = 28,
2946 INFO = 29,
2947 USR1 = 30,
2948 USR2 = 31,
2949 THR = 32,
2950 CKPT = 33,
2951 CKPTEXIT = 34,
2952 },
2953 .haiku => enum(u32) {
2951 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);2954 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
2952 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);2955 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
2953 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));2956 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
29542957
2955 pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(3);2958 pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(3);
29562959
2957 pub const HUP = 1;
2958 pub const INT = 2;
2959 pub const QUIT = 3;
2960 pub const ILL = 4;
2961 pub const CHLD = 5;
2962 pub const ABRT = 6;
2963 pub const IOT = ABRT;
2964 pub const PIPE = 7;
2965 pub const FPE = 8;
2966 pub const KILL = 9;
2967 pub const STOP = 10;
2968 pub const SEGV = 11;
2969 pub const CONT = 12;
2970 pub const TSTP = 13;
2971 pub const ALRM = 14;
2972 pub const TERM = 15;
2973 pub const TTIN = 16;
2974 pub const TTOU = 17;
2975 pub const USR1 = 18;
2976 pub const USR2 = 19;
2977 pub const WINCH = 20;
2978 pub const KILLTHR = 21;
2979 pub const TRAP = 22;
2980 pub const POLL = 23;
2981 pub const PROF = 24;
2982 pub const SYS = 25;
2983 pub const URG = 26;
2984 pub const VTALRM = 27;
2985 pub const XCPU = 28;
2986 pub const XFSZ = 29;
2987 pub const BUS = 30;
2988 pub const RESERVED1 = 31;
2989 pub const RESERVED2 = 32;
2990
2991 pub const BLOCK = 1;2960 pub const BLOCK = 1;
2992 pub const UNBLOCK = 2;2961 pub const UNBLOCK = 2;
2993 pub const SETMASK = 3;2962 pub const SETMASK = 3;
2963
2964 pub const IOT: SIG = .ABRT;
2965
2966 HUP = 1,
2967 INT = 2,
2968 QUIT = 3,
2969 ILL = 4,
2970 CHLD = 5,
2971 ABRT = 6,
2972 PIPE = 7,
2973 FPE = 8,
2974 KILL = 9,
2975 STOP = 10,
2976 SEGV = 11,
2977 CONT = 12,
2978 TSTP = 13,
2979 ALRM = 14,
2980 TERM = 15,
2981 TTIN = 16,
2982 TTOU = 17,
2983 USR1 = 18,
2984 USR2 = 19,
2985 WINCH = 20,
2986 KILLTHR = 21,
2987 TRAP = 22,
2988 POLL = 23,
2989 PROF = 24,
2990 SYS = 25,
2991 URG = 26,
2992 VTALRM = 27,
2993 XCPU = 28,
2994 XFSZ = 29,
2995 BUS = 30,
2996 RESERVED1 = 31,
2997 RESERVED2 = 32,
2994 },2998 },
2995 .openbsd => struct {2999 .openbsd => enum(u32) {
2996 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);3000 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
2997 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);3001 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
2998 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));3002 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
2999 pub const CATCH: ?Sigaction.handler_fn = @ptrFromInt(2);3003 pub const CATCH: ?Sigaction.handler_fn = @ptrFromInt(2);
3000 pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(3);3004 pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(3);
30013005
3002 pub const HUP = 1;
3003 pub const INT = 2;
3004 pub const QUIT = 3;
3005 pub const ILL = 4;
3006 pub const TRAP = 5;
3007 pub const ABRT = 6;
3008 pub const IOT = ABRT;
3009 pub const EMT = 7;
3010 pub const FPE = 8;
3011 pub const KILL = 9;
3012 pub const BUS = 10;
3013 pub const SEGV = 11;
3014 pub const SYS = 12;
3015 pub const PIPE = 13;
3016 pub const ALRM = 14;
3017 pub const TERM = 15;
3018 pub const URG = 16;
3019 pub const STOP = 17;
3020 pub const TSTP = 18;
3021 pub const CONT = 19;
3022 pub const CHLD = 20;
3023 pub const TTIN = 21;
3024 pub const TTOU = 22;
3025 pub const IO = 23;
3026 pub const XCPU = 24;
3027 pub const XFSZ = 25;
3028 pub const VTALRM = 26;
3029 pub const PROF = 27;
3030 pub const WINCH = 28;
3031 pub const INFO = 29;
3032 pub const USR1 = 30;
3033 pub const USR2 = 31;
3034 pub const PWR = 32;
3035
3036 pub const BLOCK = 1;3006 pub const BLOCK = 1;
3037 pub const UNBLOCK = 2;3007 pub const UNBLOCK = 2;
3038 pub const SETMASK = 3;3008 pub const SETMASK = 3;
3009
3010 pub const IOT: SIG = .ABRT;
3011
3012 HUP = 1,
3013 INT = 2,
3014 QUIT = 3,
3015 ILL = 4,
3016 TRAP = 5,
3017 ABRT = 6,
3018 EMT = 7,
3019 FPE = 8,
3020 KILL = 9,
3021 BUS = 10,
3022 SEGV = 11,
3023 SYS = 12,
3024 PIPE = 13,
3025 ALRM = 14,
3026 TERM = 15,
3027 URG = 16,
3028 STOP = 17,
3029 TSTP = 18,
3030 CONT = 19,
3031 CHLD = 20,
3032 TTIN = 21,
3033 TTOU = 22,
3034 IO = 23,
3035 XCPU = 24,
3036 XFSZ = 25,
3037 VTALRM = 26,
3038 PROF = 27,
3039 WINCH = 28,
3040 INFO = 29,
3041 USR1 = 30,
3042 USR2 = 31,
3043 PWR = 32,
3039 },3044 },
3040 // https://github.com/SerenityOS/serenity/blob/046c23f567a17758d762a33bdf04bacbfd088f9f/Kernel/API/POSIX/signal.h3045 // https://github.com/SerenityOS/serenity/blob/046c23f567a17758d762a33bdf04bacbfd088f9f/Kernel/API/POSIX/signal.h
3041 // https://github.com/SerenityOS/serenity/blob/046c23f567a17758d762a33bdf04bacbfd088f9f/Kernel/API/POSIX/signal_numbers.h3046 // https://github.com/SerenityOS/serenity/blob/046c23f567a17758d762a33bdf04bacbfd088f9f/Kernel/API/POSIX/signal_numbers.h
3042 .serenity => struct {3047 .serenity => enum(u32) {
3043 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);3048 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
3044 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));3049 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
3045 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);3050 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
...@@ -3048,39 +3053,39 @@ pub const SIG = switch (native_os) {...@@ -3048,39 +3053,39 @@ pub const SIG = switch (native_os) {
3048 pub const UNBLOCK = 2;3053 pub const UNBLOCK = 2;
3049 pub const SETMASK = 3;3054 pub const SETMASK = 3;
30503055
3051 pub const INVAL = 0;3056 INVAL = 0,
3052 pub const HUP = 1;3057 HUP = 1,
3053 pub const INT = 2;3058 INT = 2,
3054 pub const QUIT = 3;3059 QUIT = 3,
3055 pub const ILL = 4;3060 ILL = 4,
3056 pub const TRAP = 5;3061 TRAP = 5,
3057 pub const ABRT = 6;3062 ABRT = 6,
3058 pub const BUS = 7;3063 BUS = 7,
3059 pub const FPE = 8;3064 FPE = 8,
3060 pub const KILL = 9;3065 KILL = 9,
3061 pub const USR1 = 10;3066 USR1 = 10,
3062 pub const SEGV = 11;3067 SEGV = 11,
3063 pub const USR2 = 12;3068 USR2 = 12,
3064 pub const PIPE = 13;3069 PIPE = 13,
3065 pub const ALRM = 14;3070 ALRM = 14,
3066 pub const TERM = 15;3071 TERM = 15,
3067 pub const STKFLT = 16;3072 STKFLT = 16,
3068 pub const CHLD = 17;3073 CHLD = 17,
3069 pub const CONT = 18;3074 CONT = 18,
3070 pub const STOP = 19;3075 STOP = 19,
3071 pub const TSTP = 20;3076 TSTP = 20,
3072 pub const TTIN = 21;3077 TTIN = 21,
3073 pub const TTOU = 22;3078 TTOU = 22,
3074 pub const URG = 23;3079 URG = 23,
3075 pub const XCPU = 24;3080 XCPU = 24,
3076 pub const XFSZ = 25;3081 XFSZ = 25,
3077 pub const VTALRM = 26;3082 VTALRM = 26,
3078 pub const PROF = 27;3083 PROF = 27,
3079 pub const WINCH = 28;3084 WINCH = 28,
3080 pub const IO = 29;3085 IO = 29,
3081 pub const INFO = 30;3086 INFO = 30,
3082 pub const SYS = 31;3087 SYS = 31,
3083 pub const CANCEL = 32;3088 CANCEL = 32,
3084 },3089 },
3085 else => void,3090 else => void,
3086};3091};
...@@ -3117,8 +3122,8 @@ pub const SYS = switch (native_os) {...@@ -3117,8 +3122,8 @@ pub const SYS = switch (native_os) {
31173122
3118/// A common format for the Sigaction struct across a variety of Linux flavors.3123/// A common format for the Sigaction struct across a variety of Linux flavors.
3119const common_linux_Sigaction = extern struct {3124const common_linux_Sigaction = extern struct {
3120 pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;3125 pub const handler_fn = *align(1) const fn (SIG) callconv(.c) void;
3121 pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;3126 pub const sigaction_fn = *const fn (SIG, *const siginfo_t, ?*anyopaque) callconv(.c) void;
31223127
3123 handler: extern union {3128 handler: extern union {
3124 handler: ?handler_fn,3129 handler: ?handler_fn,
...@@ -3139,8 +3144,8 @@ pub const Sigaction = switch (native_os) {...@@ -3139,8 +3144,8 @@ pub const Sigaction = switch (native_os) {
3139 => if (builtin.target.abi.isMusl())3144 => if (builtin.target.abi.isMusl())
3140 common_linux_Sigaction3145 common_linux_Sigaction
3141 else if (builtin.target.ptrBitWidth() == 64) extern struct {3146 else if (builtin.target.ptrBitWidth() == 64) extern struct {
3142 pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;3147 pub const handler_fn = *align(1) const fn (SIG) callconv(.c) void;
3143 pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;3148 pub const sigaction_fn = *const fn (SIG, *const siginfo_t, ?*anyopaque) callconv(.c) void;
31443149
3145 flags: c_uint,3150 flags: c_uint,
3146 handler: extern union {3151 handler: extern union {
...@@ -3150,8 +3155,8 @@ pub const Sigaction = switch (native_os) {...@@ -3150,8 +3155,8 @@ pub const Sigaction = switch (native_os) {
3150 mask: sigset_t,3155 mask: sigset_t,
3151 restorer: ?*const fn () callconv(.c) void = null,3156 restorer: ?*const fn () callconv(.c) void = null,
3152 } else extern struct {3157 } else extern struct {
3153 pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;3158 pub const handler_fn = *align(1) const fn (SIG) callconv(.c) void;
3154 pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;3159 pub const sigaction_fn = *const fn (SIG, *const siginfo_t, ?*anyopaque) callconv(.c) void;
31553160
3156 flags: c_uint,3161 flags: c_uint,
3157 handler: extern union {3162 handler: extern union {
...@@ -3163,8 +3168,8 @@ pub const Sigaction = switch (native_os) {...@@ -3163,8 +3168,8 @@ pub const Sigaction = switch (native_os) {
3163 __resv: [1]c_int = .{0},3168 __resv: [1]c_int = .{0},
3164 },3169 },
3165 .s390x => if (builtin.abi == .gnu) extern struct {3170 .s390x => if (builtin.abi == .gnu) extern struct {
3166 pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;3171 pub const handler_fn = *align(1) const fn (SIG) callconv(.c) void;
3167 pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;3172 pub const sigaction_fn = *const fn (SIG, *const siginfo_t, ?*anyopaque) callconv(.c) void;
31683173
3169 handler: extern union {3174 handler: extern union {
3170 handler: ?handler_fn,3175 handler: ?handler_fn,
...@@ -3179,8 +3184,8 @@ pub const Sigaction = switch (native_os) {...@@ -3179,8 +3184,8 @@ pub const Sigaction = switch (native_os) {
3179 },3184 },
3180 .emscripten => emscripten.Sigaction,3185 .emscripten => emscripten.Sigaction,
3181 .netbsd, .macos, .ios, .tvos, .watchos, .visionos => extern struct {3186 .netbsd, .macos, .ios, .tvos, .watchos, .visionos => extern struct {
3182 pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;3187 pub const handler_fn = *align(1) const fn (SIG) callconv(.c) void;
3183 pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;3188 pub const sigaction_fn = *const fn (SIG, *const siginfo_t, ?*anyopaque) callconv(.c) void;
31843189
3185 handler: extern union {3190 handler: extern union {
3186 handler: ?handler_fn,3191 handler: ?handler_fn,
...@@ -3190,8 +3195,8 @@ pub const Sigaction = switch (native_os) {...@@ -3190,8 +3195,8 @@ pub const Sigaction = switch (native_os) {
3190 flags: c_uint,3195 flags: c_uint,
3191 },3196 },
3192 .dragonfly, .freebsd => extern struct {3197 .dragonfly, .freebsd => extern struct {
3193 pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;3198 pub const handler_fn = *align(1) const fn (SIG) callconv(.c) void;
3194 pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;3199 pub const sigaction_fn = *const fn (SIG, *const siginfo_t, ?*anyopaque) callconv(.c) void;
31953200
3196 /// signal handler3201 /// signal handler
3197 handler: extern union {3202 handler: extern union {
...@@ -3204,8 +3209,8 @@ pub const Sigaction = switch (native_os) {...@@ -3204,8 +3209,8 @@ pub const Sigaction = switch (native_os) {
3204 mask: sigset_t,3209 mask: sigset_t,
3205 },3210 },
3206 .illumos => extern struct {3211 .illumos => extern struct {
3207 pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;3212 pub const handler_fn = *align(1) const fn (SIG) callconv(.c) void;
3208 pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;3213 pub const sigaction_fn = *const fn (SIG, *const siginfo_t, ?*anyopaque) callconv(.c) void;
32093214
3210 /// signal options3215 /// signal options
3211 flags: c_uint,3216 flags: c_uint,
...@@ -3218,8 +3223,8 @@ pub const Sigaction = switch (native_os) {...@@ -3218,8 +3223,8 @@ pub const Sigaction = switch (native_os) {
3218 mask: sigset_t,3223 mask: sigset_t,
3219 },3224 },
3220 .haiku => extern struct {3225 .haiku => extern struct {
3221 pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;3226 pub const handler_fn = *align(1) const fn (SIG) callconv(.c) void;
3222 pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;3227 pub const sigaction_fn = *const fn (SIG, *const siginfo_t, ?*anyopaque) callconv(.c) void;
32233228
3224 /// signal handler3229 /// signal handler
3225 handler: extern union {3230 handler: extern union {
...@@ -3237,8 +3242,8 @@ pub const Sigaction = switch (native_os) {...@@ -3237,8 +3242,8 @@ pub const Sigaction = switch (native_os) {
3237 userdata: *allowzero anyopaque = undefined,3242 userdata: *allowzero anyopaque = undefined,
3238 },3243 },
3239 .openbsd => extern struct {3244 .openbsd => extern struct {
3240 pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;3245 pub const handler_fn = *align(1) const fn (SIG) callconv(.c) void;
3241 pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;3246 pub const sigaction_fn = *const fn (SIG, *const siginfo_t, ?*anyopaque) callconv(.c) void;
32423247
3243 /// signal handler3248 /// signal handler
3244 handler: extern union {3249 handler: extern union {
...@@ -3252,8 +3257,8 @@ pub const Sigaction = switch (native_os) {...@@ -3252,8 +3257,8 @@ pub const Sigaction = switch (native_os) {
3252 },3257 },
3253 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/signal.h#L39-L463258 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/signal.h#L39-L46
3254 .serenity => extern struct {3259 .serenity => extern struct {
3255 pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;3260 pub const handler_fn = *align(1) const fn (SIG) callconv(.c) void;
3256 pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;3261 pub const sigaction_fn = *const fn (SIG, *const siginfo_t, ?*anyopaque) callconv(.c) void;
32573262
3258 handler: extern union {3263 handler: extern union {
3259 handler: ?handler_fn,3264 handler: ?handler_fn,
...@@ -4433,7 +4438,7 @@ pub const siginfo_t = switch (native_os) {...@@ -4433,7 +4438,7 @@ pub const siginfo_t = switch (native_os) {
4433 .linux => linux.siginfo_t,4438 .linux => linux.siginfo_t,
4434 .emscripten => emscripten.siginfo_t,4439 .emscripten => emscripten.siginfo_t,
4435 .driverkit, .macos, .ios, .tvos, .watchos, .visionos => extern struct {4440 .driverkit, .macos, .ios, .tvos, .watchos, .visionos => extern struct {
4436 signo: c_int,4441 signo: SIG,
4437 errno: c_int,4442 errno: c_int,
4438 code: c_int,4443 code: c_int,
4439 pid: pid_t,4444 pid: pid_t,
...@@ -4449,7 +4454,7 @@ pub const siginfo_t = switch (native_os) {...@@ -4449,7 +4454,7 @@ pub const siginfo_t = switch (native_os) {
4449 },4454 },
4450 .freebsd => extern struct {4455 .freebsd => extern struct {
4451 // Signal number.4456 // Signal number.
4452 signo: c_int,4457 signo: SIG,
4453 // Errno association.4458 // Errno association.
4454 errno: c_int,4459 errno: c_int,
4455 /// Signal code.4460 /// Signal code.
...@@ -4492,7 +4497,7 @@ pub const siginfo_t = switch (native_os) {...@@ -4492,7 +4497,7 @@ pub const siginfo_t = switch (native_os) {
4492 },4497 },
4493 },4498 },
4494 .illumos => extern struct {4499 .illumos => extern struct {
4495 signo: c_int,4500 signo: SIG,
4496 code: c_int,4501 code: c_int,
4497 errno: c_int,4502 errno: c_int,
4498 // 64bit architectures insert 4bytes of padding here, this is done by4503 // 64bit architectures insert 4bytes of padding here, this is done by
...@@ -4549,7 +4554,7 @@ pub const siginfo_t = switch (native_os) {...@@ -4549,7 +4554,7 @@ pub const siginfo_t = switch (native_os) {
4549 info: netbsd._ksiginfo,4554 info: netbsd._ksiginfo,
4550 },4555 },
4551 .dragonfly => extern struct {4556 .dragonfly => extern struct {
4552 signo: c_int,4557 signo: SIG,
4553 errno: c_int,4558 errno: c_int,
4554 code: c_int,4559 code: c_int,
4555 pid: c_int,4560 pid: c_int,
...@@ -4561,7 +4566,7 @@ pub const siginfo_t = switch (native_os) {...@@ -4561,7 +4566,7 @@ pub const siginfo_t = switch (native_os) {
4561 __spare__: [7]c_int,4566 __spare__: [7]c_int,
4562 },4567 },
4563 .haiku => extern struct {4568 .haiku => extern struct {
4564 signo: i32,4569 signo: SIG,
4565 code: i32,4570 code: i32,
4566 errno: i32,4571 errno: i32,
45674572
...@@ -4570,7 +4575,7 @@ pub const siginfo_t = switch (native_os) {...@@ -4570,7 +4575,7 @@ pub const siginfo_t = switch (native_os) {
4570 addr: *allowzero anyopaque,4575 addr: *allowzero anyopaque,
4571 },4576 },
4572 .openbsd => extern struct {4577 .openbsd => extern struct {
4573 signo: c_int,4578 signo: SIG,
4574 code: c_int,4579 code: c_int,
4575 errno: c_int,4580 errno: c_int,
4576 data: extern union {4581 data: extern union {
...@@ -4605,7 +4610,7 @@ pub const siginfo_t = switch (native_os) {...@@ -4605,7 +4610,7 @@ pub const siginfo_t = switch (native_os) {
4605 },4610 },
4606 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/signal.h#L27-L374611 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/signal.h#L27-L37
4607 .serenity => extern struct {4612 .serenity => extern struct {
4608 signo: c_int,4613 signo: SIG,
4609 code: c_int,4614 code: c_int,
4610 errno: c_int,4615 errno: c_int,
4611 pid: pid_t,4616 pid: pid_t,
...@@ -10581,7 +10586,7 @@ pub extern "c" fn lseek(fd: fd_t, offset: off_t, whence: whence_t) off_t;...@@ -10581,7 +10586,7 @@ pub extern "c" fn lseek(fd: fd_t, offset: off_t, whence: whence_t) off_t;
10581pub extern "c" fn open(path: [*:0]const u8, oflag: O, ...) c_int;10586pub extern "c" fn open(path: [*:0]const u8, oflag: O, ...) c_int;
10582pub extern "c" fn openat(fd: c_int, path: [*:0]const u8, oflag: O, ...) c_int;10587pub extern "c" fn openat(fd: c_int, path: [*:0]const u8, oflag: O, ...) c_int;
10583pub extern "c" fn ftruncate(fd: c_int, length: off_t) c_int;10588pub extern "c" fn ftruncate(fd: c_int, length: off_t) c_int;
10584pub extern "c" fn raise(sig: c_int) c_int;10589pub extern "c" fn raise(sig: SIG) c_int;
10585pub extern "c" fn read(fd: fd_t, buf: [*]u8, nbyte: usize) isize;10590pub extern "c" fn read(fd: fd_t, buf: [*]u8, nbyte: usize) isize;
10586pub extern "c" fn readv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint) isize;10591pub extern "c" fn readv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint) isize;
10587pub extern "c" fn pread(fd: fd_t, buf: [*]u8, nbyte: usize, offset: off_t) isize;10592pub extern "c" fn pread(fd: fd_t, buf: [*]u8, nbyte: usize, offset: off_t) isize;
...@@ -10699,7 +10704,7 @@ pub const recvmsg = switch (native_os) {...@@ -10699,7 +10704,7 @@ pub const recvmsg = switch (native_os) {
10699 else => private.recvmsg,10704 else => private.recvmsg,
10700};10705};
1070110706
10702pub extern "c" fn kill(pid: pid_t, sig: c_int) c_int;10707pub extern "c" fn kill(pid: pid_t, sig: SIG) c_int;
1070310708
10704pub extern "c" fn setuid(uid: uid_t) c_int;10709pub extern "c" fn setuid(uid: uid_t) c_int;
10705pub extern "c" fn setgid(gid: gid_t) c_int;10710pub extern "c" fn setgid(gid: gid_t) c_int;
...@@ -10763,7 +10768,7 @@ pub const pthread_setname_np = switch (native_os) {...@@ -10763,7 +10768,7 @@ pub const pthread_setname_np = switch (native_os) {
10763};10768};
1076410769
10765pub extern "c" fn pthread_getname_np(thread: pthread_t, name: [*:0]u8, len: usize) c_int;10770pub extern "c" fn pthread_getname_np(thread: pthread_t, name: [*:0]u8, len: usize) c_int;
10766pub extern "c" fn pthread_kill(pthread_t, signal: c_int) c_int;10771pub extern "c" fn pthread_kill(pthread_t, signal: SIG) c_int;
1076710772
10768pub const pthread_threadid_np = switch (native_os) {10773pub const pthread_threadid_np = switch (native_os) {
10769 .macos, .ios, .tvos, .watchos, .visionos => private.pthread_threadid_np,10774 .macos, .ios, .tvos, .watchos, .visionos => private.pthread_threadid_np,
...@@ -11356,12 +11361,12 @@ const private = struct {...@@ -11356,12 +11361,12 @@ const private = struct {
11356 extern "c" fn recvmsg(sockfd: fd_t, msg: *msghdr, flags: u32) isize;11361 extern "c" fn recvmsg(sockfd: fd_t, msg: *msghdr, flags: u32) isize;
11357 extern "c" fn sched_yield() c_int;11362 extern "c" fn sched_yield() c_int;
11358 extern "c" fn sendfile(out_fd: fd_t, in_fd: fd_t, offset: ?*off_t, count: usize) isize;11363 extern "c" fn sendfile(out_fd: fd_t, in_fd: fd_t, offset: ?*off_t, count: usize) isize;
11359 extern "c" fn sigaction(sig: c_int, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;11364 extern "c" fn sigaction(sig: SIG, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;
11360 extern "c" fn sigdelset(set: ?*sigset_t, signo: c_int) c_int;11365 extern "c" fn sigdelset(set: ?*sigset_t, signo: SIG) c_int;
11361 extern "c" fn sigaddset(set: ?*sigset_t, signo: c_int) c_int;11366 extern "c" fn sigaddset(set: ?*sigset_t, signo: SIG) c_int;
11362 extern "c" fn sigfillset(set: ?*sigset_t) c_int;11367 extern "c" fn sigfillset(set: ?*sigset_t) c_int;
11363 extern "c" fn sigemptyset(set: ?*sigset_t) c_int;11368 extern "c" fn sigemptyset(set: ?*sigset_t) c_int;
11364 extern "c" fn sigismember(set: ?*const sigset_t, signo: c_int) c_int;11369 extern "c" fn sigismember(set: ?*const sigset_t, signo: SIG) c_int;
11365 extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;11370 extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
11366 extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;11371 extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
11367 extern "c" fn socketpair(domain: c_uint, sock_type: c_uint, protocol: c_uint, sv: *[2]fd_t) c_int;11372 extern "c" fn socketpair(domain: c_uint, sock_type: c_uint, protocol: c_uint, sv: *[2]fd_t) c_int;
...@@ -11413,7 +11418,7 @@ const private = struct {...@@ -11413,7 +11418,7 @@ const private = struct {
11413 extern "c" fn __libc_thr_yield() c_int;11418 extern "c" fn __libc_thr_yield() c_int;
11414 extern "c" fn __msync13(addr: *align(page_size) const anyopaque, len: usize, flags: c_int) c_int;11419 extern "c" fn __msync13(addr: *align(page_size) const anyopaque, len: usize, flags: c_int) c_int;
11415 extern "c" fn __nanosleep50(rqtp: *const timespec, rmtp: ?*timespec) c_int;11420 extern "c" fn __nanosleep50(rqtp: *const timespec, rmtp: ?*timespec) c_int;
11416 extern "c" fn __sigaction14(sig: c_int, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;11421 extern "c" fn __sigaction14(sig: SIG, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;
11417 extern "c" fn __sigemptyset14(set: ?*sigset_t) c_int;11422 extern "c" fn __sigemptyset14(set: ?*sigset_t) c_int;
11418 extern "c" fn __sigfillset14(set: ?*sigset_t) c_int;11423 extern "c" fn __sigfillset14(set: ?*sigset_t) c_int;
11419 extern "c" fn __sigprocmask14(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;11424 extern "c" fn __sigprocmask14(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
lib/std/debug.zig+10-10
...@@ -1409,10 +1409,10 @@ pub fn maybeEnableSegfaultHandler() void {...@@ -1409,10 +1409,10 @@ pub fn maybeEnableSegfaultHandler() void {
1409var windows_segfault_handle: ?windows.HANDLE = null;1409var windows_segfault_handle: ?windows.HANDLE = null;
14101410
1411pub fn updateSegfaultHandler(act: ?*const posix.Sigaction) void {1411pub fn updateSegfaultHandler(act: ?*const posix.Sigaction) void {
1412 posix.sigaction(posix.SIG.SEGV, act, null);1412 posix.sigaction(.SEGV, act, null);
1413 posix.sigaction(posix.SIG.ILL, act, null);1413 posix.sigaction(.ILL, act, null);
1414 posix.sigaction(posix.SIG.BUS, act, null);1414 posix.sigaction(.BUS, act, null);
1415 posix.sigaction(posix.SIG.FPE, act, null);1415 posix.sigaction(.FPE, act, null);
1416}1416}
14171417
1418/// Attaches a global handler for several signals which, when triggered, prints output to stderr1418/// Attaches a global handler for several signals which, when triggered, prints output to stderr
...@@ -1457,7 +1457,7 @@ fn resetSegfaultHandler() void {...@@ -1457,7 +1457,7 @@ fn resetSegfaultHandler() void {
1457 updateSegfaultHandler(&act);1457 updateSegfaultHandler(&act);
1458}1458}
14591459
1460fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.c) noreturn {1460fn handleSegfaultPosix(sig: posix.SIG, info: *const posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.c) noreturn {
1461 if (use_trap_panic) @trap();1461 if (use_trap_panic) @trap();
1462 const addr: ?usize, const name: []const u8 = info: {1462 const addr: ?usize, const name: []const u8 = info: {
1463 if (native_os == .linux and native_arch == .x86_64) {1463 if (native_os == .linux and native_arch == .x86_64) {
...@@ -1469,7 +1469,7 @@ fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopa...@@ -1469,7 +1469,7 @@ fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopa
1469 // for example when reading/writing model-specific registers1469 // for example when reading/writing model-specific registers
1470 // by executing `rdmsr` or `wrmsr` in user-space (unprivileged mode).1470 // by executing `rdmsr` or `wrmsr` in user-space (unprivileged mode).
1471 const SI_KERNEL = 0x80;1471 const SI_KERNEL = 0x80;
1472 if (sig == posix.SIG.SEGV and info.code == SI_KERNEL) {1472 if (sig == .SEGV and info.code == SI_KERNEL) {
1473 break :info .{ null, "General protection exception" };1473 break :info .{ null, "General protection exception" };
1474 }1474 }
1475 }1475 }
...@@ -1496,10 +1496,10 @@ fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopa...@@ -1496,10 +1496,10 @@ fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopa
1496 else => comptime unreachable,1496 else => comptime unreachable,
1497 };1497 };
1498 const name = switch (sig) {1498 const name = switch (sig) {
1499 posix.SIG.SEGV => "Segmentation fault",1499 .SEGV => "Segmentation fault",
1500 posix.SIG.ILL => "Illegal instruction",1500 .ILL => "Illegal instruction",
1501 posix.SIG.BUS => "Bus error",1501 .BUS => "Bus error",
1502 posix.SIG.FPE => "Arithmetic exception",1502 .FPE => "Arithmetic exception",
1503 else => unreachable,1503 else => unreachable,
1504 };1504 };
1505 break :info .{ addr, name };1505 break :info .{ addr, name };
lib/std/os/emscripten.zig+1-44
...@@ -479,50 +479,7 @@ pub const SHUT = struct {...@@ -479,50 +479,7 @@ pub const SHUT = struct {
479 pub const RDWR = 2;479 pub const RDWR = 2;
480};480};
481481
482pub const SIG = struct {482pub const SIG = linux.SIG;
483 pub const BLOCK = 0;
484 pub const UNBLOCK = 1;
485 pub const SETMASK = 2;
486
487 pub const HUP = 1;
488 pub const INT = 2;
489 pub const QUIT = 3;
490 pub const ILL = 4;
491 pub const TRAP = 5;
492 pub const ABRT = 6;
493 pub const IOT = ABRT;
494 pub const BUS = 7;
495 pub const FPE = 8;
496 pub const KILL = 9;
497 pub const USR1 = 10;
498 pub const SEGV = 11;
499 pub const USR2 = 12;
500 pub const PIPE = 13;
501 pub const ALRM = 14;
502 pub const TERM = 15;
503 pub const STKFLT = 16;
504 pub const CHLD = 17;
505 pub const CONT = 18;
506 pub const STOP = 19;
507 pub const TSTP = 20;
508 pub const TTIN = 21;
509 pub const TTOU = 22;
510 pub const URG = 23;
511 pub const XCPU = 24;
512 pub const XFSZ = 25;
513 pub const VTALRM = 26;
514 pub const PROF = 27;
515 pub const WINCH = 28;
516 pub const IO = 29;
517 pub const POLL = 29;
518 pub const PWR = 30;
519 pub const SYS = 31;
520 pub const UNUSED = SIG.SYS;
521
522 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(std.math.maxInt(usize));
523 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
524 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
525};
526483
527pub const Sigaction = extern struct {484pub const Sigaction = extern struct {
528 pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;485 pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;
lib/std/os/linux.zig+139-137
...@@ -622,7 +622,7 @@ pub fn fork() usize {...@@ -622,7 +622,7 @@ pub fn fork() usize {
622 } else if (@hasField(SYS, "fork")) {622 } else if (@hasField(SYS, "fork")) {
623 return syscall0(.fork);623 return syscall0(.fork);
624 } else {624 } else {
625 return syscall2(.clone, SIG.CHLD, 0);625 return syscall2(.clone, @intFromEnum(SIG.CHLD), 0);
626 }626 }
627}627}
628628
...@@ -1532,16 +1532,16 @@ pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize {...@@ -1532,16 +1532,16 @@ pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize {
1532 return syscall3(.getrandom, @intFromPtr(buf), count, flags);1532 return syscall3(.getrandom, @intFromPtr(buf), count, flags);
1533}1533}
15341534
1535pub fn kill(pid: pid_t, sig: i32) usize {1535pub fn kill(pid: pid_t, sig: SIG) usize {
1536 return syscall2(.kill, @as(usize, @bitCast(@as(isize, pid))), @as(usize, @bitCast(@as(isize, sig))));1536 return syscall2(.kill, @as(usize, @bitCast(@as(isize, pid))), @intFromEnum(sig));
1537}1537}
15381538
1539pub fn tkill(tid: pid_t, sig: i32) usize {1539pub fn tkill(tid: pid_t, sig: SIG) usize {
1540 return syscall2(.tkill, @as(usize, @bitCast(@as(isize, tid))), @as(usize, @bitCast(@as(isize, sig))));1540 return syscall2(.tkill, @as(usize, @bitCast(@as(isize, tid))), @intFromEnum(sig));
1541}1541}
15421542
1543pub fn tgkill(tgid: pid_t, tid: pid_t, sig: i32) usize {1543pub fn tgkill(tgid: pid_t, tid: pid_t, sig: SIG) usize {
1544 return syscall3(.tgkill, @as(usize, @bitCast(@as(isize, tgid))), @as(usize, @bitCast(@as(isize, tid))), @as(usize, @bitCast(@as(isize, sig))));1544 return syscall3(.tgkill, @as(usize, @bitCast(@as(isize, tgid))), @as(usize, @bitCast(@as(isize, tid))), @intFromEnum(sig));
1545}1545}
15461546
1547pub fn link(oldpath: [*:0]const u8, newpath: [*:0]const u8) usize {1547pub fn link(oldpath: [*:0]const u8, newpath: [*:0]const u8) usize {
...@@ -1923,11 +1923,11 @@ pub fn sigprocmask(flags: u32, noalias set: ?*const sigset_t, noalias oldset: ?*...@@ -1923,11 +1923,11 @@ pub fn sigprocmask(flags: u32, noalias set: ?*const sigset_t, noalias oldset: ?*
1923 return syscall4(.rt_sigprocmask, flags, @intFromPtr(set), @intFromPtr(oldset), NSIG / 8);1923 return syscall4(.rt_sigprocmask, flags, @intFromPtr(set), @intFromPtr(oldset), NSIG / 8);
1924}1924}
19251925
1926pub fn sigaction(sig: u8, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) usize {1926pub fn sigaction(sig: SIG, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) usize {
1927 assert(sig > 0);1927 assert(@intFromEnum(sig) > 0);
1928 assert(sig < NSIG);1928 assert(@intFromEnum(sig) < NSIG);
1929 assert(sig != SIG.KILL);1929 assert(sig != .KILL);
1930 assert(sig != SIG.STOP);1930 assert(sig != .STOP);
19311931
1932 var ksa: k_sigaction = undefined;1932 var ksa: k_sigaction = undefined;
1933 var oldksa: k_sigaction = undefined;1933 var oldksa: k_sigaction = undefined;
...@@ -1958,8 +1958,8 @@ pub fn sigaction(sig: u8, noalias act: ?*const Sigaction, noalias oact: ?*Sigact...@@ -1958,8 +1958,8 @@ pub fn sigaction(sig: u8, noalias act: ?*const Sigaction, noalias oact: ?*Sigact
19581958
1959 const result = switch (native_arch) {1959 const result = switch (native_arch) {
1960 // The sparc version of rt_sigaction needs the restorer function to be passed as an argument too.1960 // The sparc version of rt_sigaction needs the restorer function to be passed as an argument too.
1961 .sparc, .sparc64 => syscall5(.rt_sigaction, sig, ksa_arg, oldksa_arg, @intFromPtr(ksa.restorer), mask_size),1961 .sparc, .sparc64 => syscall5(.rt_sigaction, @intFromEnum(sig), ksa_arg, oldksa_arg, @intFromPtr(ksa.restorer), mask_size),
1962 else => syscall4(.rt_sigaction, sig, ksa_arg, oldksa_arg, mask_size),1962 else => syscall4(.rt_sigaction, @intFromEnum(sig), ksa_arg, oldksa_arg, mask_size),
1963 };1963 };
1964 if (E.init(result) != .SUCCESS) return result;1964 if (E.init(result) != .SUCCESS) return result;
19651965
...@@ -2009,27 +2009,27 @@ pub fn sigfillset() sigset_t {...@@ -2009,27 +2009,27 @@ pub fn sigfillset() sigset_t {
2009 return [_]SigsetElement{~@as(SigsetElement, 0)} ** sigset_len;2009 return [_]SigsetElement{~@as(SigsetElement, 0)} ** sigset_len;
2010}2010}
20112011
2012fn sigset_bit_index(sig: usize) struct { word: usize, mask: SigsetElement } {2012fn sigset_bit_index(sig: SIG) struct { word: usize, mask: SigsetElement } {
2013 assert(sig > 0);2013 assert(@intFromEnum(sig) > 0);
2014 assert(sig < NSIG);2014 assert(@intFromEnum(sig) < NSIG);
2015 const bit = sig - 1;2015 const bit = @intFromEnum(sig) - 1;
2016 return .{2016 return .{
2017 .word = bit / @bitSizeOf(SigsetElement),2017 .word = bit / @bitSizeOf(SigsetElement),
2018 .mask = @as(SigsetElement, 1) << @truncate(bit % @bitSizeOf(SigsetElement)),2018 .mask = @as(SigsetElement, 1) << @truncate(bit % @bitSizeOf(SigsetElement)),
2019 };2019 };
2020}2020}
20212021
2022pub fn sigaddset(set: *sigset_t, sig: usize) void {2022pub fn sigaddset(set: *sigset_t, sig: SIG) void {
2023 const index = sigset_bit_index(sig);2023 const index = sigset_bit_index(sig);
2024 (set.*)[index.word] |= index.mask;2024 (set.*)[index.word] |= index.mask;
2025}2025}
20262026
2027pub fn sigdelset(set: *sigset_t, sig: usize) void {2027pub fn sigdelset(set: *sigset_t, sig: SIG) void {
2028 const index = sigset_bit_index(sig);2028 const index = sigset_bit_index(sig);
2029 (set.*)[index.word] ^= index.mask;2029 (set.*)[index.word] ^= index.mask;
2030}2030}
20312031
2032pub fn sigismember(set: *const sigset_t, sig: usize) bool {2032pub fn sigismember(set: *const sigset_t, sig: SIG) bool {
2033 const index = sigset_bit_index(sig);2033 const index = sigset_bit_index(sig);
2034 return ((set.*)[index.word] & index.mask) != 0;2034 return ((set.*)[index.word] & index.mask) != 0;
2035}2035}
...@@ -2635,11 +2635,11 @@ pub fn pidfd_getfd(pidfd: fd_t, targetfd: fd_t, flags: u32) usize {...@@ -2635,11 +2635,11 @@ pub fn pidfd_getfd(pidfd: fd_t, targetfd: fd_t, flags: u32) usize {
2635 );2635 );
2636}2636}
26372637
2638pub fn pidfd_send_signal(pidfd: fd_t, sig: i32, info: ?*siginfo_t, flags: u32) usize {2638pub fn pidfd_send_signal(pidfd: fd_t, sig: SIG, info: ?*siginfo_t, flags: u32) usize {
2639 return syscall4(2639 return syscall4(
2640 .pidfd_send_signal,2640 .pidfd_send_signal,
2641 @as(usize, @bitCast(@as(isize, pidfd))),2641 @as(usize, @bitCast(@as(isize, pidfd))),
2642 @as(usize, @bitCast(@as(isize, sig))),2642 @intFromEnum(sig),
2643 @intFromPtr(info),2643 @intFromPtr(info),
2644 flags,2644 flags,
2645 );2645 );
...@@ -3736,136 +3736,138 @@ pub const SA = if (is_mips) struct {...@@ -3736,136 +3736,138 @@ pub const SA = if (is_mips) struct {
3736 pub const RESTORER = 0x04000000;3736 pub const RESTORER = 0x04000000;
3737};3737};
37383738
3739pub const SIG = if (is_mips) struct {3739pub const SIG = if (is_mips) enum(u32) {
3740 pub const BLOCK = 1;3740 pub const BLOCK = 1;
3741 pub const UNBLOCK = 2;3741 pub const UNBLOCK = 2;
3742 pub const SETMASK = 3;3742 pub const SETMASK = 3;
37433743
3744 // https://github.com/torvalds/linux/blob/ca91b9500108d4cf083a635c2e11c884d5dd20ea/arch/mips/include/uapi/asm/signal.h#L25
3745 pub const HUP = 1;
3746 pub const INT = 2;
3747 pub const QUIT = 3;
3748 pub const ILL = 4;
3749 pub const TRAP = 5;
3750 pub const ABRT = 6;
3751 pub const IOT = ABRT;
3752 pub const EMT = 7;
3753 pub const FPE = 8;
3754 pub const KILL = 9;
3755 pub const BUS = 10;
3756 pub const SEGV = 11;
3757 pub const SYS = 12;
3758 pub const PIPE = 13;
3759 pub const ALRM = 14;
3760 pub const TERM = 15;
3761 pub const USR1 = 16;
3762 pub const USR2 = 17;
3763 pub const CHLD = 18;
3764 pub const PWR = 19;
3765 pub const WINCH = 20;
3766 pub const URG = 21;
3767 pub const IO = 22;
3768 pub const POLL = IO;
3769 pub const STOP = 23;
3770 pub const TSTP = 24;
3771 pub const CONT = 25;
3772 pub const TTIN = 26;
3773 pub const TTOU = 27;
3774 pub const VTALRM = 28;
3775 pub const PROF = 29;
3776 pub const XCPU = 30;
3777 pub const XFZ = 31;
3778
3779 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));3744 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
3780 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);3745 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
3781 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);3746 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
3782} else if (is_sparc) struct {3747
3748 pub const IOT: SIG = .ABRT;
3749 pub const POLL: SIG = .IO;
3750
3751 // /arch/mips/include/uapi/asm/signal.h#L25
3752 HUP = 1,
3753 INT = 2,
3754 QUIT = 3,
3755 ILL = 4,
3756 TRAP = 5,
3757 ABRT = 6,
3758 EMT = 7,
3759 FPE = 8,
3760 KILL = 9,
3761 BUS = 10,
3762 SEGV = 11,
3763 SYS = 12,
3764 PIPE = 13,
3765 ALRM = 14,
3766 TERM = 15,
3767 USR1 = 16,
3768 USR2 = 17,
3769 CHLD = 18,
3770 PWR = 19,
3771 WINCH = 20,
3772 URG = 21,
3773 IO = 22,
3774 STOP = 23,
3775 TSTP = 24,
3776 CONT = 25,
3777 TTIN = 26,
3778 TTOU = 27,
3779 VTALRM = 28,
3780 PROF = 29,
3781 XCPU = 30,
3782 XFZ = 31,
3783} else if (is_sparc) enum(u32) {
3783 pub const BLOCK = 1;3784 pub const BLOCK = 1;
3784 pub const UNBLOCK = 2;3785 pub const UNBLOCK = 2;
3785 pub const SETMASK = 4;3786 pub const SETMASK = 4;
37863787
3787 pub const HUP = 1;
3788 pub const INT = 2;
3789 pub const QUIT = 3;
3790 pub const ILL = 4;
3791 pub const TRAP = 5;
3792 pub const ABRT = 6;
3793 pub const EMT = 7;
3794 pub const FPE = 8;
3795 pub const KILL = 9;
3796 pub const BUS = 10;
3797 pub const SEGV = 11;
3798 pub const SYS = 12;
3799 pub const PIPE = 13;
3800 pub const ALRM = 14;
3801 pub const TERM = 15;
3802 pub const URG = 16;
3803 pub const STOP = 17;
3804 pub const TSTP = 18;
3805 pub const CONT = 19;
3806 pub const CHLD = 20;
3807 pub const TTIN = 21;
3808 pub const TTOU = 22;
3809 pub const POLL = 23;
3810 pub const XCPU = 24;
3811 pub const XFSZ = 25;
3812 pub const VTALRM = 26;
3813 pub const PROF = 27;
3814 pub const WINCH = 28;
3815 pub const LOST = 29;
3816 pub const USR1 = 30;
3817 pub const USR2 = 31;
3818 pub const IOT = ABRT;
3819 pub const CLD = CHLD;
3820 pub const PWR = LOST;
3821 pub const IO = SIG.POLL;
3822
3823 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));3788 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
3824 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);3789 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
3825 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);3790 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
3826} else struct {3791
3792 pub const IOT: SIG = .ABRT;
3793 pub const CLD: SIG = .CHLD;
3794 pub const PWR: SIG = .LOST;
3795 pub const POLL: SIG = .IO;
3796
3797 HUP = 1,
3798 INT = 2,
3799 QUIT = 3,
3800 ILL = 4,
3801 TRAP = 5,
3802 ABRT = 6,
3803 EMT = 7,
3804 FPE = 8,
3805 KILL = 9,
3806 BUS = 10,
3807 SEGV = 11,
3808 SYS = 12,
3809 PIPE = 13,
3810 ALRM = 14,
3811 TERM = 15,
3812 URG = 16,
3813 STOP = 17,
3814 TSTP = 18,
3815 CONT = 19,
3816 CHLD = 20,
3817 TTIN = 21,
3818 TTOU = 22,
3819 IO = 23,
3820 XCPU = 24,
3821 XFSZ = 25,
3822 VTALRM = 26,
3823 PROF = 27,
3824 WINCH = 28,
3825 LOST = 29,
3826 USR1 = 30,
3827 USR2 = 31,
3828} else enum(u32) {
3827 pub const BLOCK = 0;3829 pub const BLOCK = 0;
3828 pub const UNBLOCK = 1;3830 pub const UNBLOCK = 1;
3829 pub const SETMASK = 2;3831 pub const SETMASK = 2;
38303832
3831 pub const HUP = 1;
3832 pub const INT = 2;
3833 pub const QUIT = 3;
3834 pub const ILL = 4;
3835 pub const TRAP = 5;
3836 pub const ABRT = 6;
3837 pub const IOT = ABRT;
3838 pub const BUS = 7;
3839 pub const FPE = 8;
3840 pub const KILL = 9;
3841 pub const USR1 = 10;
3842 pub const SEGV = 11;
3843 pub const USR2 = 12;
3844 pub const PIPE = 13;
3845 pub const ALRM = 14;
3846 pub const TERM = 15;
3847 pub const STKFLT = 16;
3848 pub const CHLD = 17;
3849 pub const CONT = 18;
3850 pub const STOP = 19;
3851 pub const TSTP = 20;
3852 pub const TTIN = 21;
3853 pub const TTOU = 22;
3854 pub const URG = 23;
3855 pub const XCPU = 24;
3856 pub const XFSZ = 25;
3857 pub const VTALRM = 26;
3858 pub const PROF = 27;
3859 pub const WINCH = 28;
3860 pub const IO = 29;
3861 pub const POLL = 29;
3862 pub const PWR = 30;
3863 pub const SYS = 31;
3864 pub const UNUSED = SIG.SYS;
3865
3866 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));3833 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
3867 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);3834 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
3868 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);3835 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
3836
3837 pub const POLL: SIG = .IO;
3838 pub const IOT: SIG = .ABRT;
3839
3840 HUP = 1,
3841 INT = 2,
3842 QUIT = 3,
3843 ILL = 4,
3844 TRAP = 5,
3845 ABRT = 6,
3846 BUS = 7,
3847 FPE = 8,
3848 KILL = 9,
3849 USR1 = 10,
3850 SEGV = 11,
3851 USR2 = 12,
3852 PIPE = 13,
3853 ALRM = 14,
3854 TERM = 15,
3855 STKFLT = 16,
3856 CHLD = 17,
3857 CONT = 18,
3858 STOP = 19,
3859 TSTP = 20,
3860 TTIN = 21,
3861 TTOU = 22,
3862 URG = 23,
3863 XCPU = 24,
3864 XFSZ = 25,
3865 VTALRM = 26,
3866 PROF = 27,
3867 WINCH = 28,
3868 IO = 29,
3869 PWR = 30,
3870 SYS = 31,
3869};3871};
38703872
3871pub const kernel_rwf = u32;3873pub const kernel_rwf = u32;
...@@ -5786,7 +5788,7 @@ pub const TFD = switch (native_arch) {...@@ -5786,7 +5788,7 @@ pub const TFD = switch (native_arch) {
5786};5788};
57875789
5788const k_sigaction_funcs = struct {5790const k_sigaction_funcs = struct {
5789 const handler = ?*align(1) const fn (i32) callconv(.c) void;5791 const handler = ?*align(1) const fn (SIG) callconv(.c) void;
5790 const restorer = *const fn () callconv(.c) void;5792 const restorer = *const fn () callconv(.c) void;
5791};5793};
57925794
...@@ -5817,8 +5819,8 @@ pub const k_sigaction = switch (native_arch) {...@@ -5817,8 +5819,8 @@ pub const k_sigaction = switch (native_arch) {
5817///5819///
5818/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.5820/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
5819pub const Sigaction = struct {5821pub const Sigaction = struct {
5820 pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;5822 pub const handler_fn = *align(1) const fn (SIG) callconv(.c) void;
5821 pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;5823 pub const sigaction_fn = *const fn (SIG, *const siginfo_t, ?*anyopaque) callconv(.c) void;
58225824
5823 handler: extern union {5825 handler: extern union {
5824 handler: ?handler_fn,5826 handler: ?handler_fn,
...@@ -6260,14 +6262,14 @@ const siginfo_fields_union = extern union {...@@ -6260,14 +6262,14 @@ const siginfo_fields_union = extern union {
62606262
6261pub const siginfo_t = if (is_mips)6263pub const siginfo_t = if (is_mips)
6262 extern struct {6264 extern struct {
6263 signo: i32,6265 signo: SIG,
6264 code: i32,6266 code: i32,
6265 errno: i32,6267 errno: i32,
6266 fields: siginfo_fields_union,6268 fields: siginfo_fields_union,
6267 }6269 }
6268else6270else
6269 extern struct {6271 extern struct {
6270 signo: i32,6272 signo: SIG,
6271 errno: i32,6273 errno: i32,
6272 code: i32,6274 code: i32,
6273 fields: siginfo_fields_union,6275 fields: siginfo_fields_union,
lib/std/os/linux/test.zig+24-46
...@@ -1,5 +1,7 @@...@@ -1,5 +1,7 @@
1const std = @import("../../std.zig");
2const builtin = @import("builtin");1const builtin = @import("builtin");
2
3const std = @import("../../std.zig");
4const assert = std.debug.assert;
3const linux = std.os.linux;5const linux = std.os.linux;
4const mem = std.mem;6const mem = std.mem;
5const elf = std.elf;7const elf = std.elf;
...@@ -128,58 +130,32 @@ test "fadvise" {...@@ -128,58 +130,32 @@ test "fadvise" {
128}130}
129131
130test "sigset_t" {132test "sigset_t" {
131 std.debug.assert(@sizeOf(linux.sigset_t) == (linux.NSIG / 8));133 const SIG = linux.SIG;
134 assert(@sizeOf(linux.sigset_t) == (linux.NSIG / 8));
132135
133 var sigset = linux.sigemptyset();136 var sigset = linux.sigemptyset();
134137
135 // See that none are set, then set each one, see that they're all set, then138 // See that none are set, then set each one, see that they're all set, then
136 // remove them all, and then see that none are set.139 // remove them all, and then see that none are set.
137 for (1..linux.NSIG) |i| {140 for (1..linux.NSIG) |i| {
138 try expectEqual(linux.sigismember(&sigset, @truncate(i)), false);141 const sig = std.meta.intToEnum(SIG, i) catch continue;
142 try expectEqual(false, linux.sigismember(&sigset, sig));
139 }143 }
140 for (1..linux.NSIG) |i| {144 for (1..linux.NSIG) |i| {
141 linux.sigaddset(&sigset, @truncate(i));145 const sig = std.meta.intToEnum(SIG, i) catch continue;
146 linux.sigaddset(&sigset, sig);
142 }147 }
143 for (1..linux.NSIG) |i| {148 for (1..linux.NSIG) |i| {
144 try expectEqual(linux.sigismember(&sigset, @truncate(i)), true);149 const sig = std.meta.intToEnum(SIG, i) catch continue;
150 try expectEqual(true, linux.sigismember(&sigset, sig));
145 }151 }
146 for (1..linux.NSIG) |i| {152 for (1..linux.NSIG) |i| {
147 linux.sigdelset(&sigset, @truncate(i));153 const sig = std.meta.intToEnum(SIG, i) catch continue;
154 linux.sigdelset(&sigset, sig);
148 }155 }
149 for (1..linux.NSIG) |i| {156 for (1..linux.NSIG) |i| {
150 try expectEqual(linux.sigismember(&sigset, @truncate(i)), false);157 const sig = std.meta.intToEnum(SIG, i) catch continue;
151 }158 try expectEqual(false, linux.sigismember(&sigset, sig));
152
153 // Kernel sigset_t is either 2+ 32-bit values or 1+ 64-bit value(s).
154 const sigset_len = @typeInfo(linux.sigset_t).array.len;
155 const sigset_elemis64 = 64 == @bitSizeOf(@typeInfo(linux.sigset_t).array.child);
156
157 linux.sigaddset(&sigset, 1);
158 try expectEqual(sigset[0], 1);
159 if (sigset_len > 1) {
160 try expectEqual(sigset[1], 0);
161 }
162
163 linux.sigaddset(&sigset, 31);
164 try expectEqual(sigset[0], 0x4000_0001);
165 if (sigset_len > 1) {
166 try expectEqual(sigset[1], 0);
167 }
168
169 linux.sigaddset(&sigset, 36);
170 if (sigset_elemis64) {
171 try expectEqual(sigset[0], 0x8_4000_0001);
172 } else {
173 try expectEqual(sigset[0], 0x4000_0001);
174 try expectEqual(sigset[1], 0x8);
175 }
176
177 linux.sigaddset(&sigset, 64);
178 if (sigset_elemis64) {
179 try expectEqual(sigset[0], 0x8000_0008_4000_0001);
180 } else {
181 try expectEqual(sigset[0], 0x4000_0001);
182 try expectEqual(sigset[1], 0x8000_0008);
183 }159 }
184}160}
185161
...@@ -187,14 +163,16 @@ test "sigfillset" {...@@ -187,14 +163,16 @@ test "sigfillset" {
187 // unlike the C library, all the signals are set in the kernel-level fillset163 // unlike the C library, all the signals are set in the kernel-level fillset
188 const sigset = linux.sigfillset();164 const sigset = linux.sigfillset();
189 for (1..linux.NSIG) |i| {165 for (1..linux.NSIG) |i| {
190 try expectEqual(linux.sigismember(&sigset, @truncate(i)), true);166 const sig = std.meta.intToEnum(linux.SIG, i) catch continue;
167 try expectEqual(true, linux.sigismember(&sigset, sig));
191 }168 }
192}169}
193170
194test "sigemptyset" {171test "sigemptyset" {
195 const sigset = linux.sigemptyset();172 const sigset = linux.sigemptyset();
196 for (1..linux.NSIG) |i| {173 for (1..linux.NSIG) |i| {
197 try expectEqual(linux.sigismember(&sigset, @truncate(i)), false);174 const sig = std.meta.intToEnum(linux.SIG, i) catch continue;
175 try expectEqual(false, linux.sigismember(&sigset, sig));
198 }176 }
199}177}
200178
...@@ -208,14 +186,14 @@ test "sysinfo" {...@@ -208,14 +186,14 @@ test "sysinfo" {
208}186}
209187
210comptime {188comptime {
211 std.debug.assert(128 == @as(u32, @bitCast(linux.FUTEX_OP{ .cmd = @enumFromInt(0), .private = true, .realtime = false })));189 assert(128 == @as(u32, @bitCast(linux.FUTEX_OP{ .cmd = @enumFromInt(0), .private = true, .realtime = false })));
212 std.debug.assert(256 == @as(u32, @bitCast(linux.FUTEX_OP{ .cmd = @enumFromInt(0), .private = false, .realtime = true })));190 assert(256 == @as(u32, @bitCast(linux.FUTEX_OP{ .cmd = @enumFromInt(0), .private = false, .realtime = true })));
213191
214 // Check futex_param4 union is packed correctly192 // Check futex_param4 union is packed correctly
215 const param_union = linux.futex_param4{193 const param_union = linux.futex_param4{
216 .val2 = 0xaabbcc,194 .val2 = 0xaabbcc,
217 };195 };
218 std.debug.assert(@intFromPtr(param_union.timeout) == 0xaabbcc);196 assert(@intFromPtr(param_union.timeout) == 0xaabbcc);
219}197}
220198
221test "futex v1" {199test "futex v1" {
...@@ -298,8 +276,8 @@ test "futex v1" {...@@ -298,8 +276,8 @@ test "futex v1" {
298}276}
299277
300comptime {278comptime {
301 std.debug.assert(2 == @as(u32, @bitCast(linux.FUTEX2_FLAGS{ .size = .U32, .private = false })));279 assert(2 == @as(u32, @bitCast(linux.FUTEX2_FLAGS{ .size = .U32, .private = false })));
302 std.debug.assert(128 == @as(u32, @bitCast(linux.FUTEX2_FLAGS{ .size = @enumFromInt(0), .private = true })));280 assert(128 == @as(u32, @bitCast(linux.FUTEX2_FLAGS{ .size = @enumFromInt(0), .private = true })));
303}281}
304282
305test "futex2_waitv" {283test "futex2_waitv" {
lib/std/posix.zig+11-11
...@@ -708,7 +708,7 @@ pub fn abort() noreturn {...@@ -708,7 +708,7 @@ pub fn abort() noreturn {
708 // for user-defined signal handlers that want to restore some state in708 // for user-defined signal handlers that want to restore some state in
709 // some program sections and crash in others.709 // some program sections and crash in others.
710 // So, the user-installed SIGABRT handler is run, if present.710 // So, the user-installed SIGABRT handler is run, if present.
711 raise(SIG.ABRT) catch {};711 raise(.ABRT) catch {};
712712
713 // Disable all signal handlers.713 // Disable all signal handlers.
714 const filledset = linux.sigfillset();714 const filledset = linux.sigfillset();
...@@ -728,17 +728,17 @@ pub fn abort() noreturn {...@@ -728,17 +728,17 @@ pub fn abort() noreturn {
728 .mask = sigemptyset(),728 .mask = sigemptyset(),
729 .flags = 0,729 .flags = 0,
730 };730 };
731 sigaction(SIG.ABRT, &sigact, null);731 sigaction(.ABRT, &sigact, null);
732732
733 _ = linux.tkill(linux.gettid(), SIG.ABRT);733 _ = linux.tkill(linux.gettid(), .ABRT);
734734
735 var sigabrtmask = sigemptyset();735 var sigabrtmask = sigemptyset();
736 sigaddset(&sigabrtmask, SIG.ABRT);736 sigaddset(&sigabrtmask, .ABRT);
737 sigprocmask(SIG.UNBLOCK, &sigabrtmask, null);737 sigprocmask(SIG.UNBLOCK, &sigabrtmask, null);
738738
739 // Beyond this point should be unreachable.739 // Beyond this point should be unreachable.
740 @as(*allowzero volatile u8, @ptrFromInt(0)).* = 0;740 @as(*allowzero volatile u8, @ptrFromInt(0)).* = 0;
741 raise(SIG.KILL) catch {};741 raise(.KILL) catch {};
742 exit(127); // Pid 1 might not be signalled in some containers.742 exit(127); // Pid 1 might not be signalled in some containers.
743 }743 }
744 switch (native_os) {744 switch (native_os) {
...@@ -749,7 +749,7 @@ pub fn abort() noreturn {...@@ -749,7 +749,7 @@ pub fn abort() noreturn {
749749
750pub const RaiseError = UnexpectedError;750pub const RaiseError = UnexpectedError;
751751
752pub fn raise(sig: u8) RaiseError!void {752pub fn raise(sig: SIG) RaiseError!void {
753 if (builtin.link_libc) {753 if (builtin.link_libc) {
754 switch (errno(system.raise(sig))) {754 switch (errno(system.raise(sig))) {
755 .SUCCESS => return,755 .SUCCESS => return,
...@@ -777,7 +777,7 @@ pub fn raise(sig: u8) RaiseError!void {...@@ -777,7 +777,7 @@ pub fn raise(sig: u8) RaiseError!void {
777777
778pub const KillError = error{ ProcessNotFound, PermissionDenied } || UnexpectedError;778pub const KillError = error{ ProcessNotFound, PermissionDenied } || UnexpectedError;
779779
780pub fn kill(pid: pid_t, sig: u8) KillError!void {780pub fn kill(pid: pid_t, sig: SIG) KillError!void {
781 switch (errno(system.kill(pid, sig))) {781 switch (errno(system.kill(pid, sig))) {
782 .SUCCESS => return,782 .SUCCESS => return,
783 .INVAL => unreachable, // invalid signal783 .INVAL => unreachable, // invalid signal
...@@ -5235,7 +5235,7 @@ pub fn sigemptyset() sigset_t {...@@ -5235,7 +5235,7 @@ pub fn sigemptyset() sigset_t {
5235 return system.sigemptyset();5235 return system.sigemptyset();
5236}5236}
52375237
5238pub fn sigaddset(set: *sigset_t, sig: u8) void {5238pub fn sigaddset(set: *sigset_t, sig: SIG) void {
5239 if (builtin.link_libc) {5239 if (builtin.link_libc) {
5240 switch (errno(system.sigaddset(set, sig))) {5240 switch (errno(system.sigaddset(set, sig))) {
5241 .SUCCESS => return,5241 .SUCCESS => return,
...@@ -5245,7 +5245,7 @@ pub fn sigaddset(set: *sigset_t, sig: u8) void {...@@ -5245,7 +5245,7 @@ pub fn sigaddset(set: *sigset_t, sig: u8) void {
5245 system.sigaddset(set, sig);5245 system.sigaddset(set, sig);
5246}5246}
52475247
5248pub fn sigdelset(set: *sigset_t, sig: u8) void {5248pub fn sigdelset(set: *sigset_t, sig: SIG) void {
5249 if (builtin.link_libc) {5249 if (builtin.link_libc) {
5250 switch (errno(system.sigdelset(set, sig))) {5250 switch (errno(system.sigdelset(set, sig))) {
5251 .SUCCESS => return,5251 .SUCCESS => return,
...@@ -5255,7 +5255,7 @@ pub fn sigdelset(set: *sigset_t, sig: u8) void {...@@ -5255,7 +5255,7 @@ pub fn sigdelset(set: *sigset_t, sig: u8) void {
5255 system.sigdelset(set, sig);5255 system.sigdelset(set, sig);
5256}5256}
52575257
5258pub fn sigismember(set: *const sigset_t, sig: u8) bool {5258pub fn sigismember(set: *const sigset_t, sig: SIG) bool {
5259 if (builtin.link_libc) {5259 if (builtin.link_libc) {
5260 const rc = system.sigismember(set, sig);5260 const rc = system.sigismember(set, sig);
5261 switch (errno(rc)) {5261 switch (errno(rc)) {
...@@ -5267,7 +5267,7 @@ pub fn sigismember(set: *const sigset_t, sig: u8) bool {...@@ -5267,7 +5267,7 @@ pub fn sigismember(set: *const sigset_t, sig: u8) bool {
5267}5267}
52685268
5269/// Examine and change a signal action.5269/// Examine and change a signal action.
5270pub fn sigaction(sig: u8, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) void {5270pub fn sigaction(sig: SIG, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) void {
5271 switch (errno(system.sigaction(sig, act, oact))) {5271 switch (errno(system.sigaction(sig, act, oact))) {
5272 .SUCCESS => return,5272 .SUCCESS => return,
5273 // EINVAL means the signal is either invalid or some signal that cannot have its action5273 // EINVAL means the signal is either invalid or some signal that cannot have its action
lib/std/posix/test.zig+14-8
...@@ -536,14 +536,15 @@ test "sigset empty/full" {...@@ -536,14 +536,15 @@ test "sigset empty/full" {
536536
537 var set: posix.sigset_t = posix.sigemptyset();537 var set: posix.sigset_t = posix.sigemptyset();
538 for (1..posix.NSIG) |i| {538 for (1..posix.NSIG) |i| {
539 try expectEqual(false, posix.sigismember(&set, @truncate(i)));539 const sig = std.meta.intToEnum(posix.SIG, i) catch continue;
540 try expectEqual(false, posix.sigismember(&set, sig));
540 }541 }
541542
542 // The C library can reserve some (unnamed) signals, so can't check the full543 // The C library can reserve some (unnamed) signals, so can't check the full
543 // NSIG set is defined, but just test a couple:544 // NSIG set is defined, but just test a couple:
544 set = posix.sigfillset();545 set = posix.sigfillset();
545 try expectEqual(true, posix.sigismember(&set, @truncate(posix.SIG.CHLD)));546 try expectEqual(true, posix.sigismember(&set, .CHLD));
546 try expectEqual(true, posix.sigismember(&set, @truncate(posix.SIG.INT)));547 try expectEqual(true, posix.sigismember(&set, .INT));
547}548}
548549
549// Some signals (i.e., 32 - 34 on glibc/musl) are not allowed to be added to a550// Some signals (i.e., 32 - 34 on glibc/musl) are not allowed to be added to a
...@@ -564,25 +565,30 @@ test "sigset add/del" {...@@ -564,25 +565,30 @@ test "sigset add/del" {
564 // See that none are set, then set each one, see that they're all set, then565 // See that none are set, then set each one, see that they're all set, then
565 // remove them all, and then see that none are set.566 // remove them all, and then see that none are set.
566 for (1..posix.NSIG) |i| {567 for (1..posix.NSIG) |i| {
567 try expectEqual(false, posix.sigismember(&sigset, @truncate(i)));568 const sig = std.meta.intToEnum(posix.SIG, i) catch continue;
569 try expectEqual(false, posix.sigismember(&sigset, sig));
568 }570 }
569 for (1..posix.NSIG) |i| {571 for (1..posix.NSIG) |i| {
570 if (!reserved_signo(i)) {572 if (!reserved_signo(i)) {
571 posix.sigaddset(&sigset, @truncate(i));573 const sig = std.meta.intToEnum(posix.SIG, i) catch continue;
574 posix.sigaddset(&sigset, sig);
572 }575 }
573 }576 }
574 for (1..posix.NSIG) |i| {577 for (1..posix.NSIG) |i| {
575 if (!reserved_signo(i)) {578 if (!reserved_signo(i)) {
576 try expectEqual(true, posix.sigismember(&sigset, @truncate(i)));579 const sig = std.meta.intToEnum(posix.SIG, i) catch continue;
580 try expectEqual(true, posix.sigismember(&sigset, sig));
577 }581 }
578 }582 }
579 for (1..posix.NSIG) |i| {583 for (1..posix.NSIG) |i| {
580 if (!reserved_signo(i)) {584 if (!reserved_signo(i)) {
581 posix.sigdelset(&sigset, @truncate(i));585 const sig = std.meta.intToEnum(posix.SIG, i) catch continue;
586 posix.sigdelset(&sigset, sig);
582 }587 }
583 }588 }
584 for (1..posix.NSIG) |i| {589 for (1..posix.NSIG) |i| {
585 try expectEqual(false, posix.sigismember(&sigset, @truncate(i)));590 const sig = std.meta.intToEnum(posix.SIG, i) catch continue;
591 try expectEqual(false, posix.sigismember(&sigset, sig));
586 }592 }
587}593}
588594
lib/std/start.zig+9-30
...@@ -758,45 +758,24 @@ pub fn call_wWinMain() std.os.windows.INT {...@@ -758,45 +758,24 @@ pub fn call_wWinMain() std.os.windows.INT {
758}758}
759759
760fn maybeIgnoreSignals() void {760fn maybeIgnoreSignals() void {
761 switch (builtin.os.tag) {
762 .linux,
763 .plan9,
764 .illumos,
765 .netbsd,
766 .openbsd,
767 .haiku,
768 .macos,
769 .ios,
770 .watchos,
771 .tvos,
772 .visionos,
773 .dragonfly,
774 .freebsd,
775 .serenity,
776 => {},
777 else => return,
778 }
779 const posix = std.posix;761 const posix = std.posix;
762 if (posix.Sigaction == void) return;
780 const act: posix.Sigaction = .{763 const act: posix.Sigaction = .{
781 // Set handler to a noop function instead of `SIG.IGN` to prevent764 // Set handler to a noop function instead of `IGN` to prevent
782 // leaking signal disposition to a child process.765 // leaking signal disposition to a child process.
783 .handler = .{ .handler = noopSigHandler },766 .handler = .{ .handler = noopSigHandler },
784 .mask = posix.sigemptyset(),767 .mask = posix.sigemptyset(),
785 .flags = 0,768 .flags = 0,
786 };769 };
787770
788 if (@hasField(posix.SIG, "POLL") and !std.options.keep_sigpoll)771 if (@hasField(posix.SIG, "IO") and !std.options.keep_sig_io)
789 posix.sigaction(posix.SIG.POLL, &act, null);772 posix.sigaction(.IO, &act, null);
790773
791 if (@hasField(posix.SIG, "IO") and774 if (@hasField(posix.SIG, "POLL") and !std.options.keep_sig_poll)
792 (!@hasField(posix.SIG, "POLL") or posix.SIG.IO != posix.SIG.POLL) and775 posix.sigaction(.POLL, &act, null);
793 !std.options.keep_sigio)
794 {
795 posix.sigaction(posix.SIG.IO, &act, null);
796 }
797776
798 if (@hasField(posix.SIG, "PIPE") and !std.options.keep_sigpipe)777 if (@hasField(posix.SIG, "PIPE") and !std.options.keep_sig_pipe)
799 posix.sigaction(posix.SIG.PIPE, &act, null);778 posix.sigaction(.PIPE, &act, null);
800}779}
801780
802fn noopSigHandler(_: i32) callconv(.c) void {}781fn noopSigHandler(_: std.posix.SIG) callconv(.c) void {}
lib/std/std.zig+3-3
...@@ -144,8 +144,8 @@ pub const Options = struct {...@@ -144,8 +144,8 @@ pub const Options = struct {
144144
145 crypto_fork_safety: bool = true,145 crypto_fork_safety: bool = true,
146146
147 keep_sigpoll: bool = false,147 keep_sig_poll: bool = false,
148 keep_sigio: bool = false,148 keep_sig_io: bool = false,
149149
150 /// By default Zig disables SIGPIPE by setting a "no-op" handler for it. Set this option150 /// By default Zig disables SIGPIPE by setting a "no-op" handler for it. Set this option
151 /// to `true` to prevent that.151 /// to `true` to prevent that.
...@@ -158,7 +158,7 @@ pub const Options = struct {...@@ -158,7 +158,7 @@ pub const Options = struct {
158 /// cases it's unclear why the process was terminated. By capturing SIGPIPE instead, functions that158 /// cases it's unclear why the process was terminated. By capturing SIGPIPE instead, functions that
159 /// write to broken pipes will return the EPIPE error (error.BrokenPipe) and the program can handle159 /// write to broken pipes will return the EPIPE error (error.BrokenPipe) and the program can handle
160 /// it like any other error.160 /// it like any other error.
161 keep_sigpipe: bool = false,161 keep_sig_pipe: bool = false,
162162
163 /// By default, std.http.Client will support HTTPS connections. Set this option to `true` to163 /// By default, std.http.Client will support HTTPS connections. Set this option to `true` to
164 /// disable TLS support.164 /// disable TLS support.
test/standalone/posix/sigaction.zig+10-14
...@@ -17,12 +17,12 @@ fn test_sigaction() !void {...@@ -17,12 +17,12 @@ fn test_sigaction() !void {
17 return; // https://github.com/ziglang/zig/issues/1538117 return; // https://github.com/ziglang/zig/issues/15381
18 }18 }
1919
20 const test_signo = std.posix.SIG.URG; // URG only because it is ignored by default in debuggers20 const test_signo: std.posix.SIG = .URG; // URG only because it is ignored by default in debuggers
2121
22 const S = struct {22 const S = struct {
23 var handler_called_count: u32 = 0;23 var handler_called_count: u32 = 0;
2424
25 fn handler(sig: i32, info: *const std.posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.c) void {25 fn handler(sig: std.posix.SIG, info: *const std.posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.c) void {
26 _ = ctx_ptr;26 _ = ctx_ptr;
27 // Check that we received the correct signal.27 // Check that we received the correct signal.
28 const info_sig = switch (native_os) {28 const info_sig = switch (native_os) {
...@@ -80,20 +80,18 @@ fn test_sigaction() !void {...@@ -80,20 +80,18 @@ fn test_sigaction() !void {
80}80}
8181
82fn test_sigset_bits() !void {82fn test_sigset_bits() !void {
83 const NO_SIG: i32 = 0;
84
85 const S = struct {83 const S = struct {
86 var expected_sig: i32 = undefined;84 var expected_sig: std.posix.SIG = undefined;
87 var seen_sig: i32 = NO_SIG;85 var seen_sig: ?std.posix.SIG = null;
8886
89 fn handler(sig: i32, info: *const std.posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.c) void {87 fn handler(sig: std.posix.SIG, info: *const std.posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.c) void {
90 _ = ctx_ptr;88 _ = ctx_ptr;
9189
92 const info_sig = switch (native_os) {90 const info_sig = switch (native_os) {
93 .netbsd => info.info.signo,91 .netbsd => info.info.signo,
94 else => info.signo,92 else => info.signo,
95 };93 };
96 if (seen_sig == NO_SIG and sig == expected_sig and sig == info_sig) {94 if (seen_sig == null and sig == expected_sig and sig == info_sig) {
97 seen_sig = sig;95 seen_sig = sig;
98 }96 }
99 }97 }
...@@ -107,11 +105,9 @@ fn test_sigset_bits() !void {...@@ -107,11 +105,9 @@ fn test_sigset_bits() !void {
107 // big-endian), try sending a blocked signal to make sure the mask matches the105 // big-endian), try sending a blocked signal to make sure the mask matches the
108 // signal. (Send URG and CHLD because they're ignored by default in the106 // signal. (Send URG and CHLD because they're ignored by default in the
109 // debugger, vs. USR1 or other named signals)107 // debugger, vs. USR1 or other named signals)
110 inline for ([_]i32{ std.posix.SIG.URG, std.posix.SIG.CHLD, 62, 94, 126 }) |test_signo| {108 inline for ([_]std.posix.SIG{ .URG, .CHLD }) |test_signo| {
111 if (test_signo >= std.posix.NSIG) continue;
112
113 S.expected_sig = test_signo;109 S.expected_sig = test_signo;
114 S.seen_sig = NO_SIG;110 S.seen_sig = null;
115111
116 const sa: std.posix.Sigaction = .{112 const sa: std.posix.Sigaction = .{
117 .handler = .{ .sigaction = &S.handler },113 .handler = .{ .sigaction = &S.handler },
...@@ -135,14 +131,14 @@ fn test_sigset_bits() !void {...@@ -135,14 +131,14 @@ fn test_sigset_bits() !void {
135 switch (std.posix.errno(rc)) {131 switch (std.posix.errno(rc)) {
136 .SUCCESS => {132 .SUCCESS => {
137 // See that the signal is blocked, then unblocked133 // See that the signal is blocked, then unblocked
138 try std.testing.expectEqual(NO_SIG, S.seen_sig);134 try std.testing.expectEqual(null, S.seen_sig);
139 std.posix.sigprocmask(std.posix.SIG.UNBLOCK, &block_one, null);135 std.posix.sigprocmask(std.posix.SIG.UNBLOCK, &block_one, null);
140 try std.testing.expectEqual(test_signo, S.seen_sig);136 try std.testing.expectEqual(test_signo, S.seen_sig);
141 },137 },
142 .INVAL => {138 .INVAL => {
143 // Signal won't get delviered. Just clean up.139 // Signal won't get delviered. Just clean up.
144 std.posix.sigprocmask(std.posix.SIG.UNBLOCK, &block_one, null);140 std.posix.sigprocmask(std.posix.SIG.UNBLOCK, &block_one, null);
145 try std.testing.expectEqual(NO_SIG, S.seen_sig);141 try std.testing.expectEqual(null, S.seen_sig);
146 },142 },
147 else => |errno| return std.posix.unexpectedErrno(errno),143 else => |errno| return std.posix.unexpectedErrno(errno),
148 }144 }