| ... | ... | @@ -7129,22 +7129,49 @@ pub fn timerfd_gettime(fd: i32) TimerFdGetError!linux.itimerspec { |
| 7129 | 7129 | |
| 7130 | 7130 | pub const PtraceError = error{ |
| 7131 | 7131 | DeviceBusy, |
| 7132 | InputOutput, |
| 7133 | Overflow, |
| 7132 | 7134 | ProcessNotFound, |
| 7133 | 7135 | PermissionDenied, |
| 7134 | 7136 | } || UnexpectedError; |
| 7135 | 7137 | |
| 7136 | | /// TODO on other OSes |
| 7137 | | pub fn ptrace(request: i32, pid: pid_t, addr: ?[*]u8, signal: i32) PtraceError!void { |
| 7138 | | switch (builtin.os.tag) { |
| 7139 | | .macos, .ios, .tvos, .watchos => {}, |
| 7140 | | else => @compileError("TODO implement ptrace"), |
| 7141 | | } |
| 7142 | | return switch (errno(system.ptrace(request, pid, addr, signal))) { |
| 7143 | | .SUCCESS => {}, |
| 7144 | | .SRCH => error.ProcessNotFound, |
| 7145 | | .INVAL => unreachable, |
| 7146 | | .PERM => error.PermissionDenied, |
| 7147 | | .BUSY => error.DeviceBusy, |
| 7148 | | else => |err| return unexpectedErrno(err), |
| 7138 | pub fn ptrace(request: u32, pid: pid_t, addr: usize, signal: usize) PtraceError!void { |
| 7139 | if (builtin.os.tag == .windows or builtin.os.tag == .wasi) |
| 7140 | @compileError("Unsupported OS"); |
| 7141 | |
| 7142 | return switch (builtin.os.tag) { |
| 7143 | .linux => switch (errno(linux.ptrace(request, pid, addr, signal, 0))) { |
| 7144 | .SUCCESS => {}, |
| 7145 | .SRCH => error.ProcessNotFound, |
| 7146 | .FAULT => unreachable, |
| 7147 | .INVAL => unreachable, |
| 7148 | .IO => return error.InputOutput, |
| 7149 | .PERM => error.PermissionDenied, |
| 7150 | .BUSY => error.DeviceBusy, |
| 7151 | else => |err| return unexpectedErrno(err), |
| 7152 | }, |
| 7153 | |
| 7154 | .macos, .ios, .tvos, .watchos => switch (errno(darwin.ptrace( |
| 7155 | math.cast(i32, request) orelse return error.Overflow, |
| 7156 | pid, |
| 7157 | @intToPtr(?[*]u8, addr), |
| 7158 | math.cast(i32, signal) orelse return error.Overflow, |
| 7159 | ))) { |
| 7160 | .SUCCESS => {}, |
| 7161 | .SRCH => error.ProcessNotFound, |
| 7162 | .INVAL => unreachable, |
| 7163 | .PERM => error.PermissionDenied, |
| 7164 | .BUSY => error.DeviceBusy, |
| 7165 | else => |err| return unexpectedErrno(err), |
| 7166 | }, |
| 7167 | |
| 7168 | else => switch (errno(system.ptrace(request, pid, addr, signal))) { |
| 7169 | .SUCCESS => {}, |
| 7170 | .SRCH => error.ProcessNotFound, |
| 7171 | .INVAL => unreachable, |
| 7172 | .PERM => error.PermissionDenied, |
| 7173 | .BUSY => error.DeviceBusy, |
| 7174 | else => |err| return unexpectedErrno(err), |
| 7175 | }, |
| 7149 | 7176 | }; |
| 7150 | 7177 | } |