| author | |
| committer | |
| log | 6b960331ee1f688d9a6b4159e3aae48fdd0c184d |
| tree | f552833cab99e29e81f4c0d40e9682c749122613 |
| parent | bda355d976c11a6bf1c820b6f1c2a477acd214fd |
| parent | 95c83388e452d83e407fbaaf1431d5a19cfca4a3 |
| signature | Signed by PGP key 4AEE18F83AFDEB23 |
Clean up linux sigprocmask, raise4 files changed, 33 insertions(+), 37 deletions(-)
lib/std/c.zig+1-1| ... | @@ -101,7 +101,7 @@ pub extern "c" fn dup(fd: fd_t) c_int; | ... | @@ -101,7 +101,7 @@ pub extern "c" fn dup(fd: fd_t) c_int; |
| 101 | pub extern "c" fn dup2(old_fd: fd_t, new_fd: fd_t) c_int; | 101 | pub extern "c" fn dup2(old_fd: fd_t, new_fd: fd_t) c_int; |
| 102 | pub extern "c" fn readlink(noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize; | 102 | pub extern "c" fn readlink(noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize; |
| 103 | pub extern "c" fn realpath(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8; | 103 | pub extern "c" fn realpath(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8; |
| 104 | pub extern "c" fn sigprocmask(how: c_int, noalias set: *const sigset_t, noalias oset: ?*sigset_t) c_int; | 104 | pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int; |
| 105 | pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int; | 105 | pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int; |
| 106 | pub extern "c" fn sigaction(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int; | 106 | pub extern "c" fn sigaction(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int; |
| 107 | pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int; | 107 | pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int; |
lib/std/os.zig+9-4| ... | @@ -225,10 +225,15 @@ pub fn raise(sig: u8) RaiseError!void { | ... | @@ -225,10 +225,15 @@ pub fn raise(sig: u8) RaiseError!void { |
| 225 | 225 | ||
| 226 | if (builtin.os == .linux) { | 226 | if (builtin.os == .linux) { |
| 227 | var set: linux.sigset_t = undefined; | 227 | var set: linux.sigset_t = undefined; |
| 228 | linux.blockAppSignals(&set); | 228 | // block application signals |
| 229 | const tid = linux.syscall0(linux.SYS_gettid); | 229 | _ = linux.sigprocmask(SIG_BLOCK, &linux.app_mask, &set); |
| 230 | const rc = linux.syscall2(linux.SYS_tkill, tid, sig); | 230 | |
| 231 | linux.restoreSignals(&set); | 231 | const tid = linux.gettid(); |
| 232 | const rc = linux.tkill(tid, sig); | ||
| 233 | |||
| 234 | // restore signal mask | ||
| 235 | _ = linux.sigprocmask(SIG_SETMASK, &set, null); | ||
| 236 | |||
| 232 | switch (errno(rc)) { | 237 | switch (errno(rc)) { |
| 233 | 0 => return, | 238 | 0 => return, |
| 234 | else => |err| return unexpectedErrno(err), | 239 | else => |err| return unexpectedErrno(err), |
lib/std/os/bits/linux.zig+7-12| ... | @@ -764,19 +764,14 @@ pub const winsize = extern struct { | ... | @@ -764,19 +764,14 @@ pub const winsize = extern struct { |
| 764 | ws_ypixel: u16, | 764 | ws_ypixel: u16, |
| 765 | }; | 765 | }; |
| 766 | 766 | ||
| 767 | /// NSIG is the total number of signals defined. | ||
| 768 | /// As signal numbers are sequential, NSIG is one greater than the largest defined signal number. | ||
| 767 | pub const NSIG = if (is_mips) 128 else 65; | 769 | pub const NSIG = if (is_mips) 128 else 65; |
| 768 | pub const sigset_t = [128 / @sizeOf(usize)]usize; | ||
| 769 | 770 | ||
| 770 | pub usingnamespace if (NSIG == 65) | 771 | pub const sigset_t = [1024 / 32]u32; |
| 771 | struct { | 772 | |
| 772 | pub const all_mask = [2]u32{ 0xffffffff, 0xffffffff }; | 773 | pub const all_mask: sigset_t = [_]u32{0xffffffff} ** sigset_t.len; |
| 773 | pub const app_mask = [2]u32{ 0xfffffffc, 0x7fffffff }; | 774 | pub const app_mask: sigset_t = [2]u32{ 0xfffffffc, 0x7fffffff } ++ [_]u32{0xffffffff} ** 30; |
| 774 | } | ||
| 775 | else | ||
| 776 | struct { | ||
| 777 | pub const all_mask = [4]u32{ 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }; | ||
| 778 | pub const app_mask = [4]u32{ 0xfffffffc, 0x7fffffff, 0xffffffff, 0xffffffff }; | ||
| 779 | }; | ||
| 780 | 775 | ||
| 781 | pub const k_sigaction = if (is_mips) | 776 | pub const k_sigaction = if (is_mips) |
| 782 | extern struct { | 777 | extern struct { |
| ... | @@ -804,7 +799,7 @@ pub const Sigaction = extern struct { | ... | @@ -804,7 +799,7 @@ pub const Sigaction = extern struct { |
| 804 | pub const SIG_ERR = @intToPtr(extern fn (i32, *siginfo_t, *c_void) void, maxInt(usize)); | 799 | pub const SIG_ERR = @intToPtr(extern fn (i32, *siginfo_t, *c_void) void, maxInt(usize)); |
| 805 | pub const SIG_DFL = @intToPtr(?extern fn (i32, *siginfo_t, *c_void) void, 0); | 800 | pub const SIG_DFL = @intToPtr(?extern fn (i32, *siginfo_t, *c_void) void, 0); |
| 806 | pub const SIG_IGN = @intToPtr(extern fn (i32, *siginfo_t, *c_void) void, 1); | 801 | pub const SIG_IGN = @intToPtr(extern fn (i32, *siginfo_t, *c_void) void, 1); |
| 807 | pub const empty_sigset = [_]usize{0} ** sigset_t.len; | 802 | pub const empty_sigset = [_]u32{0} ** sigset_t.len; |
| 808 | 803 | ||
| 809 | pub const in_port_t = u16; | 804 | pub const in_port_t = u16; |
| 810 | pub const sa_family_t = u16; | 805 | pub const sa_family_t = u16; |
lib/std/os/linux.zig+16-20| ... | @@ -464,10 +464,18 @@ pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize { | ... | @@ -464,10 +464,18 @@ pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize { |
| 464 | return syscall3(SYS_getrandom, @ptrToInt(buf), count, flags); | 464 | return syscall3(SYS_getrandom, @ptrToInt(buf), count, flags); |
| 465 | } | 465 | } |
| 466 | 466 | ||
| 467 | pub fn kill(pid: i32, sig: i32) usize { | 467 | pub fn kill(pid: pid_t, sig: i32) usize { |
| 468 | return syscall2(SYS_kill, @bitCast(usize, @as(isize, pid)), @bitCast(usize, @as(isize, sig))); | 468 | return syscall2(SYS_kill, @bitCast(usize, @as(isize, pid)), @bitCast(usize, @as(isize, sig))); |
| 469 | } | 469 | } |
| 470 | 470 | ||
| 471 | pub fn tkill(tid: pid_t, sig: i32) usize { | ||
| 472 | return syscall2(SYS_tkill, @bitCast(usize, @as(isize, tid)), @bitCast(usize, @as(isize, sig))); | ||
| 473 | } | ||
| 474 | |||
| 475 | pub fn tgkill(tgid: pid_t, tid: pid_t, sig: i32) usize { | ||
| 476 | return syscall2(SYS_tgkill, @bitCast(usize, @as(isize, tgid)), @bitCast(usize, @as(isize, tid)), @bitCast(usize, @as(isize, sig))); | ||
| 477 | } | ||
| 478 | |||
| 471 | pub fn unlink(path: [*:0]const u8) usize { | 479 | pub fn unlink(path: [*:0]const u8) usize { |
| 472 | if (@hasDecl(@This(), "SYS_unlink")) { | 480 | if (@hasDecl(@This(), "SYS_unlink")) { |
| 473 | return syscall1(SYS_unlink, @ptrToInt(path)); | 481 | return syscall1(SYS_unlink, @ptrToInt(path)); |
| ... | @@ -480,7 +488,7 @@ pub fn unlinkat(dirfd: i32, path: [*:0]const u8, flags: u32) usize { | ... | @@ -480,7 +488,7 @@ pub fn unlinkat(dirfd: i32, path: [*:0]const u8, flags: u32) usize { |
| 480 | return syscall3(SYS_unlinkat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), flags); | 488 | return syscall3(SYS_unlinkat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), flags); |
| 481 | } | 489 | } |
| 482 | 490 | ||
| 483 | pub fn waitpid(pid: i32, status: *u32, flags: u32) usize { | 491 | pub fn waitpid(pid: pid_t, status: *u32, flags: u32) usize { |
| 484 | return syscall4(SYS_wait4, @bitCast(usize, @as(isize, pid)), @ptrToInt(status), flags, 0); | 492 | return syscall4(SYS_wait4, @bitCast(usize, @as(isize, pid)), @ptrToInt(status), flags, 0); |
| 485 | } | 493 | } |
| 486 | 494 | ||
| ... | @@ -657,15 +665,15 @@ pub fn setgroups(size: usize, list: *const u32) usize { | ... | @@ -657,15 +665,15 @@ pub fn setgroups(size: usize, list: *const u32) usize { |
| 657 | } | 665 | } |
| 658 | } | 666 | } |
| 659 | 667 | ||
| 660 | pub fn getpid() i32 { | 668 | pub fn getpid() pid_t { |
| 661 | return @bitCast(i32, @truncate(u32, syscall0(SYS_getpid))); | 669 | return @bitCast(pid_t, @truncate(u32, syscall0(SYS_getpid))); |
| 662 | } | 670 | } |
| 663 | 671 | ||
| 664 | pub fn gettid() i32 { | 672 | pub fn gettid() pid_t { |
| 665 | return @bitCast(i32, @truncate(u32, syscall0(SYS_gettid))); | 673 | return @bitCast(pid_t, @truncate(u32, syscall0(SYS_gettid))); |
| 666 | } | 674 | } |
| 667 | 675 | ||
| 668 | pub fn sigprocmask(flags: u32, noalias set: *const sigset_t, noalias oldset: ?*sigset_t) usize { | 676 | pub fn sigprocmask(flags: u32, noalias set: ?*const sigset_t, noalias oldset: ?*sigset_t) usize { |
| 669 | return syscall4(SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG / 8); | 677 | return syscall4(SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG / 8); |
| 670 | } | 678 | } |
| 671 | 679 | ||
| ... | @@ -697,18 +705,6 @@ pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigacti | ... | @@ -697,18 +705,6 @@ pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigacti |
| 697 | return 0; | 705 | return 0; |
| 698 | } | 706 | } |
| 699 | 707 | ||
| 700 | pub fn blockAllSignals(set: *sigset_t) void { | ||
| 701 | _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&all_mask), @ptrToInt(set), NSIG / 8); | ||
| 702 | } | ||
| 703 | |||
| 704 | pub fn blockAppSignals(set: *sigset_t) void { | ||
| 705 | _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&app_mask), @ptrToInt(set), NSIG / 8); | ||
| 706 | } | ||
| 707 | |||
| 708 | pub fn restoreSignals(set: *sigset_t) void { | ||
| 709 | _ = syscall4(SYS_rt_sigprocmask, SIG_SETMASK, @ptrToInt(set), 0, NSIG / 8); | ||
| 710 | } | ||
| 711 | |||
| 712 | pub fn sigaddset(set: *sigset_t, sig: u6) void { | 708 | pub fn sigaddset(set: *sigset_t, sig: u6) void { |
| 713 | const s = sig - 1; | 709 | const s = sig - 1; |
| 714 | (set.*)[@intCast(usize, s) / usize.bit_count] |= @intCast(usize, 1) << (s & (usize.bit_count - 1)); | 710 | (set.*)[@intCast(usize, s) / usize.bit_count] |= @intCast(usize, 1) << (s & (usize.bit_count - 1)); |
| ... | @@ -969,7 +965,7 @@ pub fn sched_yield() usize { | ... | @@ -969,7 +965,7 @@ pub fn sched_yield() usize { |
| 969 | return syscall0(SYS_sched_yield); | 965 | return syscall0(SYS_sched_yield); |
| 970 | } | 966 | } |
| 971 | 967 | ||
| 972 | pub fn sched_getaffinity(pid: i32, size: usize, set: *cpu_set_t) usize { | 968 | pub fn sched_getaffinity(pid: pid_t, size: usize, set: *cpu_set_t) usize { |
| 973 | const rc = syscall3(SYS_sched_getaffinity, @bitCast(usize, @as(isize, pid)), size, @ptrToInt(set)); | 969 | const rc = syscall3(SYS_sched_getaffinity, @bitCast(usize, @as(isize, pid)), size, @ptrToInt(set)); |
| 974 | if (@bitCast(isize, rc) < 0) return rc; | 970 | if (@bitCast(isize, rc) < 0) return rc; |
| 975 | if (rc < size) @memset(@ptrCast([*]u8, set) + rc, 0, size - rc); | 971 | if (rc < size) @memset(@ptrCast([*]u8, set) + rc, 0, size - rc); |