mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 14:25:16 +00:00
darwin: expose ptrace with errno handling
This commit is contained in:
parent
c9d763502f
commit
35e3069ab7
@ -42,6 +42,7 @@ pub const uefi = @import("os/uefi.zig");
|
||||
pub const wasi = @import("os/wasi.zig");
|
||||
pub const windows = @import("os/windows.zig");
|
||||
pub const posix_spawn = @import("os/posix_spawn.zig");
|
||||
pub const ptrace = @import("os/ptrace.zig");
|
||||
|
||||
comptime {
|
||||
assert(@import("std") == std); // std lib tests require --zig-lib-dir
|
||||
|
||||
28
lib/std/os/ptrace.zig
Normal file
28
lib/std/os/ptrace.zig
Normal file
@ -0,0 +1,28 @@
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
|
||||
const os = @import("../os.zig");
|
||||
const system = os.system;
|
||||
const errno = system.getErrno;
|
||||
const pid_t = system.pid_t;
|
||||
const unexpectedErrno = os.unexpectedErrno;
|
||||
const UnexpectedError = os.UnexpectedError;
|
||||
|
||||
pub usingnamespace ptrace;
|
||||
|
||||
const ptrace = if (builtin.target.isDarwin()) struct {
|
||||
pub const PtraceError = error{
|
||||
ProcessNotFound,
|
||||
PermissionDenied,
|
||||
} || UnexpectedError;
|
||||
|
||||
pub fn ptrace(request: i32, pid: pid_t) PtraceError!void {
|
||||
switch (errno(system.ptrace(request, pid, null, 0))) {
|
||||
.SUCCESS => return,
|
||||
.SRCH => return error.ProcessNotFound,
|
||||
.INVAL => unreachable,
|
||||
.BUSY, .PERM => return error.PermissionDenied,
|
||||
else => |err| return unexpectedErrno(err),
|
||||
}
|
||||
}
|
||||
} else struct {};
|
||||
Loading…
x
Reference in New Issue
Block a user