| author | |
| committer | |
| log | 35e3069ab7af0a5fd65c5fe8e35b01458dbcb132 |
| tree | 95b3efb3d74726be1da81f11fbf4dbecb35952fa |
| parent | c9d763502fb1ff9ee76f0745c493e65c1333b1b1 |
2 files changed, 29 insertions(+), 0 deletions(-)
lib/std/os.zig+1| ... | @@ -42,6 +42,7 @@ pub const uefi = @import("os/uefi.zig"); | ... | @@ -42,6 +42,7 @@ pub const uefi = @import("os/uefi.zig"); |
| 42 | pub const wasi = @import("os/wasi.zig"); | 42 | pub const wasi = @import("os/wasi.zig"); |
| 43 | pub const windows = @import("os/windows.zig"); | 43 | pub const windows = @import("os/windows.zig"); |
| 44 | pub const posix_spawn = @import("os/posix_spawn.zig"); | 44 | pub const posix_spawn = @import("os/posix_spawn.zig"); |
| 45 | pub const ptrace = @import("os/ptrace.zig"); | ||
| 45 | 46 | ||
| 46 | comptime { | 47 | comptime { |
| 47 | assert(@import("std") == std); // std lib tests require --zig-lib-dir | 48 | assert(@import("std") == std); // std lib tests require --zig-lib-dir |
lib/std/os/ptrace.zig created+28| ... | @@ -0,0 +1,28 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | const os = @import("../os.zig"); | ||
| 5 | const system = os.system; | ||
| 6 | const errno = system.getErrno; | ||
| 7 | const pid_t = system.pid_t; | ||
| 8 | const unexpectedErrno = os.unexpectedErrno; | ||
| 9 | const UnexpectedError = os.UnexpectedError; | ||
| 10 | |||
| 11 | pub usingnamespace ptrace; | ||
| 12 | |||
| 13 | const ptrace = if (builtin.target.isDarwin()) struct { | ||
| 14 | pub const PtraceError = error{ | ||
| 15 | ProcessNotFound, | ||
| 16 | PermissionDenied, | ||
| 17 | } || UnexpectedError; | ||
| 18 | |||
| 19 | pub fn ptrace(request: i32, pid: pid_t) PtraceError!void { | ||
| 20 | switch (errno(system.ptrace(request, pid, null, 0))) { | ||
| 21 | .SUCCESS => return, | ||
| 22 | .SRCH => return error.ProcessNotFound, | ||
| 23 | .INVAL => unreachable, | ||
| 24 | .BUSY, .PERM => return error.PermissionDenied, | ||
| 25 | else => |err| return unexpectedErrno(err), | ||
| 26 | } | ||
| 27 | } | ||
| 28 | } else struct {}; | ||