mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-07 22:34:28 +00:00
os.zig: expose ptrace wrapper for darwin and linux
This commit is contained in:
parent
2ac8d90df0
commit
a23ef3783b
1 changed files with 40 additions and 13 deletions
|
|
@ -7129,22 +7129,49 @@ pub fn timerfd_gettime(fd: i32) TimerFdGetError!linux.itimerspec {
|
||||||
|
|
||||||
pub const PtraceError = error{
|
pub const PtraceError = error{
|
||||||
DeviceBusy,
|
DeviceBusy,
|
||||||
|
InputOutput,
|
||||||
|
Overflow,
|
||||||
ProcessNotFound,
|
ProcessNotFound,
|
||||||
PermissionDenied,
|
PermissionDenied,
|
||||||
} || UnexpectedError;
|
} || UnexpectedError;
|
||||||
|
|
||||||
/// TODO on other OSes
|
pub fn ptrace(request: u32, pid: pid_t, addr: usize, signal: usize) PtraceError!void {
|
||||||
pub fn ptrace(request: i32, pid: pid_t, addr: ?[*]u8, signal: i32) PtraceError!void {
|
if (builtin.os.tag == .windows or builtin.os.tag == .wasi)
|
||||||
switch (builtin.os.tag) {
|
@compileError("Unsupported OS");
|
||||||
.macos, .ios, .tvos, .watchos => {},
|
|
||||||
else => @compileError("TODO implement ptrace"),
|
return switch (builtin.os.tag) {
|
||||||
}
|
.linux => switch (errno(linux.ptrace(request, pid, addr, signal, 0))) {
|
||||||
return switch (errno(system.ptrace(request, pid, addr, signal))) {
|
.SUCCESS => {},
|
||||||
|
.SRCH => error.ProcessNotFound,
|
||||||
|
.FAULT => unreachable,
|
||||||
|
.INVAL => unreachable,
|
||||||
|
.IO => return error.InputOutput,
|
||||||
|
.PERM => error.PermissionDenied,
|
||||||
|
.BUSY => error.DeviceBusy,
|
||||||
|
else => |err| return unexpectedErrno(err),
|
||||||
|
},
|
||||||
|
|
||||||
|
.macos, .ios, .tvos, .watchos => switch (errno(darwin.ptrace(
|
||||||
|
math.cast(i32, request) orelse return error.Overflow,
|
||||||
|
pid,
|
||||||
|
@intToPtr(?[*]u8, addr),
|
||||||
|
math.cast(i32, signal) orelse return error.Overflow,
|
||||||
|
))) {
|
||||||
.SUCCESS => {},
|
.SUCCESS => {},
|
||||||
.SRCH => error.ProcessNotFound,
|
.SRCH => error.ProcessNotFound,
|
||||||
.INVAL => unreachable,
|
.INVAL => unreachable,
|
||||||
.PERM => error.PermissionDenied,
|
.PERM => error.PermissionDenied,
|
||||||
.BUSY => error.DeviceBusy,
|
.BUSY => error.DeviceBusy,
|
||||||
else => |err| return unexpectedErrno(err),
|
else => |err| return unexpectedErrno(err),
|
||||||
|
},
|
||||||
|
|
||||||
|
else => switch (errno(system.ptrace(request, pid, addr, signal))) {
|
||||||
|
.SUCCESS => {},
|
||||||
|
.SRCH => error.ProcessNotFound,
|
||||||
|
.INVAL => unreachable,
|
||||||
|
.PERM => error.PermissionDenied,
|
||||||
|
.BUSY => error.DeviceBusy,
|
||||||
|
else => |err| return unexpectedErrno(err),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue