feature. See also
. The project being documented here (as the example) is the Zig library itself.
posix.ptrace
pub fn ptrace(request: u32, pid: pid_t, addr: usize, data: usize) PtraceError!void
File
Code
pub fn ptrace(request: u32, pid: pid_t, addr: usize, data: usize) PtraceError!void {
return switch (native_os) {
.windows,
.wasi,
.emscripten,
.haiku,
.illumos,
.plan9,
=> @compileError("ptrace unsupported by target OS"),
.linux => switch (errno(if (builtin.link_libc) std.c.ptrace(
@intCast(request),
pid,
@ptrFromInt(addr),
@ptrFromInt(data),
) else linux.ptrace(request, pid, addr, data, 0))) {
.SUCCESS => {},
.SRCH => error.ProcessNotFound,
.FAULT => unreachable,
.INVAL => unreachable,
.IO => return error.InputOutput,
.PERM => error.PermissionDenied,
.BUSY => error.DeviceBusy,
else => |err| return unexpectedErrno(err),
},
.driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => switch (errno(std.c.ptrace(
@fromBackingInt(@intCast(request)),
pid,
@ptrFromInt(addr),
@intCast(data),
))) {
.SUCCESS => {},
.SRCH => error.ProcessNotFound,
.INVAL => unreachable,
.PERM => error.PermissionDenied,
.BUSY => error.DeviceBusy,
else => |err| return unexpectedErrno(err),
},
.dragonfly => switch (errno(std.c.ptrace(
@intCast(request),
pid,
@ptrFromInt(addr),
@intCast(data),
))) {
.SUCCESS => {},
.SRCH => error.ProcessNotFound,
.INVAL => unreachable,
.PERM => error.PermissionDenied,
.BUSY => error.DeviceBusy,
else => |err| return unexpectedErrno(err),
},
.freebsd => switch (errno(std.c.ptrace(
@intCast(request),
pid,
@ptrFromInt(addr),
@intCast(data),
))) {
.SUCCESS => {},
.SRCH => error.ProcessNotFound,
.INVAL => unreachable,
.PERM => error.PermissionDenied,
.BUSY => error.DeviceBusy,
.NOENT, .NOMEM => error.OutOfMemory,
.NAMETOOLONG => error.NameTooLong,
else => |err| return unexpectedErrno(err),
},
.netbsd => switch (errno(std.c.ptrace(
@intCast(request),
pid,
@ptrFromInt(addr),
@intCast(data),
))) {
.SUCCESS => {},
.SRCH => error.ProcessNotFound,
.INVAL => unreachable,
.PERM => error.PermissionDenied,
.BUSY => error.DeviceBusy,
.DEADLK => error.DeadLock,
else => |err| return unexpectedErrno(err),
},
.openbsd => switch (errno(std.c.ptrace(
@intCast(request),
pid,
@ptrFromInt(addr),
@intCast(data),
))) {
.SUCCESS => {},
.SRCH => error.ProcessNotFound,
.INVAL => unreachable,
.PERM => error.PermissionDenied,
.BUSY => error.DeviceBusy,
.NOTSUP => error.OperationUnsupported,
else => |err| return unexpectedErrno(err),
},
else => @compileError("std.posix.ptrace unimplemented for target OS"),
};
}