| author | |
| committer | |
| log | 9b4cae4750ca7f2ce46286f6f55766ff95859521 |
| tree | 652dec0001acec88a2b346ee310a52640e7b564e |
| parent | bfda12efcf2f6b4bc6803f520108b7ce05636965 |
7 files changed, 101 insertions(+), 11 deletions(-)
lib/std/c.zig+15-2| ... | @@ -10856,6 +10856,18 @@ pub const pthread_threadid_np = switch (native_os) { | ... | @@ -10856,6 +10856,18 @@ pub const pthread_threadid_np = switch (native_os) { |
| 10856 | else => {}, | 10856 | else => {}, |
| 10857 | }; | 10857 | }; |
| 10858 | 10858 | ||
| 10859 | pub const caddr_t = ?[*]u8; | ||
| 10860 | |||
| 10861 | pub const ptrace = switch (native_os) { | ||
| 10862 | .linux, .serenity => private.ptrace, | ||
| 10863 | .macos, .ios, .tvos, .watchos, .visionos => darwin.ptrace, | ||
| 10864 | .dragonfly => dragonfly.ptrace, | ||
| 10865 | .freebsd => freebsd.ptrace, | ||
| 10866 | .netbsd => netbsd.ptrace, | ||
| 10867 | .openbsd => openbsd.ptrace, | ||
| 10868 | else => {}, | ||
| 10869 | }; | ||
| 10870 | |||
| 10859 | pub extern "c" fn sem_init(sem: *sem_t, pshared: c_int, value: c_uint) c_int; | 10871 | pub extern "c" fn sem_init(sem: *sem_t, pshared: c_int, value: c_uint) c_int; |
| 10860 | pub extern "c" fn sem_destroy(sem: *sem_t) c_int; | 10872 | pub extern "c" fn sem_destroy(sem: *sem_t) c_int; |
| 10861 | pub extern "c" fn sem_open(name: [*:0]const u8, flag: c_int, mode: mode_t, value: c_uint) *sem_t; | 10873 | pub extern "c" fn sem_open(name: [*:0]const u8, flag: c_int, mode: mode_t, value: c_uint) *sem_t; |
| ... | @@ -11305,7 +11317,6 @@ pub const pthread_attr_get_qos_class_np = darwin.pthread_attr_get_qos_class_np; | ... | @@ -11305,7 +11317,6 @@ pub const pthread_attr_get_qos_class_np = darwin.pthread_attr_get_qos_class_np; |
| 11305 | pub const pthread_attr_set_qos_class_np = darwin.pthread_attr_set_qos_class_np; | 11317 | pub const pthread_attr_set_qos_class_np = darwin.pthread_attr_set_qos_class_np; |
| 11306 | pub const pthread_get_qos_class_np = darwin.pthread_get_qos_class_np; | 11318 | pub const pthread_get_qos_class_np = darwin.pthread_get_qos_class_np; |
| 11307 | pub const pthread_set_qos_class_self_np = darwin.pthread_set_qos_class_self_np; | 11319 | pub const pthread_set_qos_class_self_np = darwin.pthread_set_qos_class_self_np; |
| 11308 | pub const ptrace = darwin.ptrace; | ||
| 11309 | pub const qos_class_t = darwin.qos_class_t; | 11320 | pub const qos_class_t = darwin.qos_class_t; |
| 11310 | pub const task_flavor_t = darwin.task_flavor_t; | 11321 | pub const task_flavor_t = darwin.task_flavor_t; |
| 11311 | pub const task_for_pid = darwin.task_for_pid; | 11322 | pub const task_for_pid = darwin.task_for_pid; |
| ... | @@ -11341,7 +11352,6 @@ pub const vm_region_submap_info_64 = darwin.vm_region_submap_info_64; | ... | @@ -11341,7 +11352,6 @@ pub const vm_region_submap_info_64 = darwin.vm_region_submap_info_64; |
| 11341 | pub const vm_region_submap_short_info_64 = darwin.vm_region_submap_short_info_64; | 11352 | pub const vm_region_submap_short_info_64 = darwin.vm_region_submap_short_info_64; |
| 11342 | pub const vm_region_top_info = darwin.vm_region_top_info; | 11353 | pub const vm_region_top_info = darwin.vm_region_top_info; |
| 11343 | 11354 | ||
| 11344 | pub const caddr_t = darwin.caddr_t; | ||
| 11345 | pub const exception_behavior_array_t = darwin.exception_behavior_array_t; | 11355 | pub const exception_behavior_array_t = darwin.exception_behavior_array_t; |
| 11346 | pub const exception_behavior_t = darwin.exception_behavior_t; | 11356 | pub const exception_behavior_t = darwin.exception_behavior_t; |
| 11347 | pub const exception_data_t = darwin.exception_data_t; | 11357 | pub const exception_data_t = darwin.exception_data_t; |
| ... | @@ -11466,6 +11476,9 @@ const private = struct { | ... | @@ -11466,6 +11476,9 @@ const private = struct { |
| 11466 | extern "c" fn mlockall(flags: MCL) c_int; | 11476 | extern "c" fn mlockall(flags: MCL) c_int; |
| 11467 | extern "c" fn munlockall() c_int; | 11477 | extern "c" fn munlockall() c_int; |
| 11468 | 11478 | ||
| 11479 | // linux and https://github.com/SerenityOS/serenity/blob/502caef9a40bccc7459f9835f2174a601106299a/Userland/Libraries/LibC/sys/ptrace.cpp | ||
| 11480 | extern "c" fn ptrace(request: c_int, pid: pid_t, addr: ?*anyopaque, data: ?*anyopaque) c_long; | ||
| 11481 | |||
| 11469 | /// macos modernized symbols. | 11482 | /// macos modernized symbols. |
| 11470 | /// x86_64 links to $INODE64 suffix for 64-bit support. | 11483 | /// x86_64 links to $INODE64 suffix for 64-bit support. |
| 11471 | /// Note these are not necessary on aarch64. | 11484 | /// Note these are not necessary on aarch64. |
lib/std/c/darwin.zig+1-2| ... | @@ -4,6 +4,7 @@ const native_arch = builtin.target.cpu.arch; | ... | @@ -4,6 +4,7 @@ const native_arch = builtin.target.cpu.arch; |
| 4 | const assert = std.debug.assert; | 4 | const assert = std.debug.assert; |
| 5 | const AF = std.c.AF; | 5 | const AF = std.c.AF; |
| 6 | const PROT = std.c.PROT; | 6 | const PROT = std.c.PROT; |
| 7 | const caddr_t = std.c.caddr_t; | ||
| 7 | const fd_t = std.c.fd_t; | 8 | const fd_t = std.c.fd_t; |
| 8 | const iovec_const = std.posix.iovec_const; | 9 | const iovec_const = std.posix.iovec_const; |
| 9 | const mode_t = std.c.mode_t; | 10 | const mode_t = std.c.mode_t; |
| ... | @@ -1318,8 +1319,6 @@ pub const PT = enum(c_int) { | ... | @@ -1318,8 +1319,6 @@ pub const PT = enum(c_int) { |
| 1318 | _, | 1319 | _, |
| 1319 | }; | 1320 | }; |
| 1320 | 1321 | ||
| 1321 | pub const caddr_t = ?[*]u8; | ||
| 1322 | |||
| 1323 | pub extern "c" fn ptrace(request: PT, pid: pid_t, addr: caddr_t, data: c_int) c_int; | 1322 | pub extern "c" fn ptrace(request: PT, pid: pid_t, addr: caddr_t, data: c_int) c_int; |
| 1324 | 1323 | ||
| 1325 | pub const POSIX_SPAWN = packed struct(c_short) { | 1324 | pub const POSIX_SPAWN = packed struct(c_short) { |
lib/std/c/dragonfly.zig+2| ... | @@ -1,6 +1,7 @@ | ... | @@ -1,6 +1,7 @@ |
| 1 | const std = @import("../std.zig"); | 1 | const std = @import("../std.zig"); |
| 2 | 2 | ||
| 3 | const SIG = std.c.SIG; | 3 | const SIG = std.c.SIG; |
| 4 | const caddr_t = std.c.caddr_t; | ||
| 4 | const gid_t = std.c.gid_t; | 5 | const gid_t = std.c.gid_t; |
| 5 | const iovec = std.c.iovec; | 6 | const iovec = std.c.iovec; |
| 6 | const pid_t = std.c.pid_t; | 7 | const pid_t = std.c.pid_t; |
| ... | @@ -8,6 +9,7 @@ const socklen_t = std.c.socklen_t; | ... | @@ -8,6 +9,7 @@ const socklen_t = std.c.socklen_t; |
| 8 | const uid_t = std.c.uid_t; | 9 | const uid_t = std.c.uid_t; |
| 9 | 10 | ||
| 10 | pub extern "c" fn lwp_gettid() c_int; | 11 | pub extern "c" fn lwp_gettid() c_int; |
| 12 | pub extern "c" fn ptrace(request: c_int, pid: pid_t, addr: caddr_t, data: c_int) c_int; | ||
| 11 | pub extern "c" fn umtx_sleep(ptr: *const volatile c_int, value: c_int, timeout: c_int) c_int; | 13 | pub extern "c" fn umtx_sleep(ptr: *const volatile c_int, value: c_int, timeout: c_int) c_int; |
| 12 | pub extern "c" fn umtx_wakeup(ptr: *const volatile c_int, count: c_int) c_int; | 14 | pub extern "c" fn umtx_wakeup(ptr: *const volatile c_int, count: c_int) c_int; |
| 13 | 15 |
lib/std/c/freebsd.zig+3| ... | @@ -5,6 +5,7 @@ const assert = std.debug.assert; | ... | @@ -5,6 +5,7 @@ const assert = std.debug.assert; |
| 5 | const PATH_MAX = std.c.PATH_MAX; | 5 | const PATH_MAX = std.c.PATH_MAX; |
| 6 | const blkcnt_t = std.c.blkcnt_t; | 6 | const blkcnt_t = std.c.blkcnt_t; |
| 7 | const blksize_t = std.c.blksize_t; | 7 | const blksize_t = std.c.blksize_t; |
| 8 | const caddr_t = std.c.caddr_t; | ||
| 8 | const dev_t = std.c.dev_t; | 9 | const dev_t = std.c.dev_t; |
| 9 | const fd_t = std.c.fd_t; | 10 | const fd_t = std.c.fd_t; |
| 10 | const gid_t = std.c.gid_t; | 11 | const gid_t = std.c.gid_t; |
| ... | @@ -25,6 +26,8 @@ comptime { | ... | @@ -25,6 +26,8 @@ comptime { |
| 25 | assert(builtin.os.tag == .freebsd); // Prevent access of std.c symbols on wrong OS. | 26 | assert(builtin.os.tag == .freebsd); // Prevent access of std.c symbols on wrong OS. |
| 26 | } | 27 | } |
| 27 | 28 | ||
| 29 | pub extern "c" fn ptrace(request: c_int, pid: pid_t, addr: caddr_t, data: c_int) c_int; | ||
| 30 | |||
| 28 | pub extern "c" fn kinfo_getfile(pid: pid_t, cntp: *c_int) ?[*]kinfo_file; | 31 | pub extern "c" fn kinfo_getfile(pid: pid_t, cntp: *c_int) ?[*]kinfo_file; |
| 29 | pub extern "c" fn copy_file_range(fd_in: fd_t, off_in: ?*off_t, fd_out: fd_t, off_out: ?*off_t, len: usize, flags: u32) usize; | 32 | pub extern "c" fn copy_file_range(fd_in: fd_t, off_in: ?*off_t, fd_out: fd_t, off_out: ?*off_t, len: usize, flags: u32) usize; |
| 30 | 33 |
lib/std/c/netbsd.zig+2| ... | @@ -5,6 +5,8 @@ const pthread_t = std.c.pthread_t; | ... | @@ -5,6 +5,8 @@ const pthread_t = std.c.pthread_t; |
| 5 | const sigval_t = std.c.sigval_t; | 5 | const sigval_t = std.c.sigval_t; |
| 6 | const uid_t = std.c.uid_t; | 6 | const uid_t = std.c.uid_t; |
| 7 | 7 | ||
| 8 | pub extern "c" fn ptrace(request: c_int, pid: pid_t, addr: ?*anyopaque, data: c_int) c_int; | ||
| 9 | |||
| 8 | pub const lwpid_t = i32; | 10 | pub const lwpid_t = i32; |
| 9 | 11 | ||
| 10 | pub extern "c" fn _lwp_self() lwpid_t; | 12 | pub extern "c" fn _lwp_self() lwpid_t; |
lib/std/c/openbsd.zig+3| ... | @@ -2,6 +2,7 @@ const std = @import("../std.zig"); | ... | @@ -2,6 +2,7 @@ const std = @import("../std.zig"); |
| 2 | const assert = std.debug.assert; | 2 | const assert = std.debug.assert; |
| 3 | const maxInt = std.math.maxInt; | 3 | const maxInt = std.math.maxInt; |
| 4 | const builtin = @import("builtin"); | 4 | const builtin = @import("builtin"); |
| 5 | const caddr_t = std.c.caddr_t; | ||
| 5 | const iovec = std.posix.iovec; | 6 | const iovec = std.posix.iovec; |
| 6 | const iovec_const = std.posix.iovec_const; | 7 | const iovec_const = std.posix.iovec_const; |
| 7 | const passwd = std.c.passwd; | 8 | const passwd = std.c.passwd; |
| ... | @@ -13,6 +14,8 @@ comptime { | ... | @@ -13,6 +14,8 @@ comptime { |
| 13 | assert(builtin.os.tag == .openbsd); // Prevent access of std.c symbols on wrong OS. | 14 | assert(builtin.os.tag == .openbsd); // Prevent access of std.c symbols on wrong OS. |
| 14 | } | 15 | } |
| 15 | 16 | ||
| 17 | pub extern "c" fn ptrace(request: c_int, pid: pid_t, addr: caddr_t, data: c_int) c_int; | ||
| 18 | |||
| 16 | pub const pthread_spinlock_t = extern struct { | 19 | pub const pthread_spinlock_t = extern struct { |
| 17 | inner: ?*anyopaque = null, | 20 | inner: ?*anyopaque = null, |
| 18 | }; | 21 | }; |
lib/std/posix.zig+75-7| ... | @@ -7377,18 +7377,33 @@ pub fn timerfd_gettime(fd: i32) TimerFdGetError!system.itimerspec { | ... | @@ -7377,18 +7377,33 @@ pub fn timerfd_gettime(fd: i32) TimerFdGetError!system.itimerspec { |
| 7377 | } | 7377 | } |
| 7378 | 7378 | ||
| 7379 | pub const PtraceError = error{ | 7379 | pub const PtraceError = error{ |
| 7380 | DeadLock, | ||
| 7380 | DeviceBusy, | 7381 | DeviceBusy, |
| 7381 | InputOutput, | 7382 | InputOutput, |
| 7383 | NameTooLong, | ||
| 7384 | OperationNotSupported, | ||
| 7385 | OutOfMemory, | ||
| 7382 | ProcessNotFound, | 7386 | ProcessNotFound, |
| 7383 | PermissionDenied, | 7387 | PermissionDenied, |
| 7384 | } || UnexpectedError; | 7388 | } || UnexpectedError; |
| 7385 | 7389 | ||
| 7386 | pub fn ptrace(request: u32, pid: pid_t, addr: usize, signal: usize) PtraceError!void { | 7390 | pub fn ptrace(request: u32, pid: pid_t, addr: usize, data: usize) PtraceError!void { |
| 7387 | if (native_os == .windows or native_os == .wasi) | ||
| 7388 | @compileError("Unsupported OS"); | ||
| 7389 | |||
| 7390 | return switch (native_os) { | 7391 | return switch (native_os) { |
| 7391 | .linux => switch (errno(linux.ptrace(request, pid, addr, signal, 0))) { | 7392 | .windows, |
| 7393 | .wasi, | ||
| 7394 | .emscripten, | ||
| 7395 | .haiku, | ||
| 7396 | .solaris, | ||
| 7397 | .illumos, | ||
| 7398 | .plan9, | ||
| 7399 | => @compileError("ptrace unsupported by target OS"), | ||
| 7400 | |||
| 7401 | .linux => switch (errno(if (builtin.link_libc) std.c.ptrace( | ||
| 7402 | @intCast(request), | ||
| 7403 | pid, | ||
| 7404 | @ptrFromInt(addr), | ||
| 7405 | @ptrFromInt(data), | ||
| 7406 | ) else linux.ptrace(request, pid, addr, data, 0))) { | ||
| 7392 | .SUCCESS => {}, | 7407 | .SUCCESS => {}, |
| 7393 | .SRCH => error.ProcessNotFound, | 7408 | .SRCH => error.ProcessNotFound, |
| 7394 | .FAULT => unreachable, | 7409 | .FAULT => unreachable, |
| ... | @@ -7400,27 +7415,80 @@ pub fn ptrace(request: u32, pid: pid_t, addr: usize, signal: usize) PtraceError! | ... | @@ -7400,27 +7415,80 @@ pub fn ptrace(request: u32, pid: pid_t, addr: usize, signal: usize) PtraceError! |
| 7400 | }, | 7415 | }, |
| 7401 | 7416 | ||
| 7402 | .macos, .ios, .tvos, .watchos, .visionos => switch (errno(std.c.ptrace( | 7417 | .macos, .ios, .tvos, .watchos, .visionos => switch (errno(std.c.ptrace( |
| 7418 | @enumFromInt(request), | ||
| 7419 | pid, | ||
| 7420 | @ptrFromInt(addr), | ||
| 7421 | @intCast(data), | ||
| 7422 | ))) { | ||
| 7423 | .SUCCESS => {}, | ||
| 7424 | .SRCH => error.ProcessNotFound, | ||
| 7425 | .INVAL => unreachable, | ||
| 7426 | .PERM => error.PermissionDenied, | ||
| 7427 | .BUSY => error.DeviceBusy, | ||
| 7428 | else => |err| return unexpectedErrno(err), | ||
| 7429 | }, | ||
| 7430 | |||
| 7431 | .dragonfly => switch (errno(std.c.ptrace( | ||
| 7432 | @intCast(request), | ||
| 7433 | pid, | ||
| 7434 | @ptrFromInt(addr), | ||
| 7435 | @intCast(data), | ||
| 7436 | ))) { | ||
| 7437 | .SUCCESS => {}, | ||
| 7438 | .SRCH => error.ProcessNotFound, | ||
| 7439 | .INVAL => unreachable, | ||
| 7440 | .PERM => error.PermissionDenied, | ||
| 7441 | .BUSY => error.DeviceBusy, | ||
| 7442 | else => |err| return unexpectedErrno(err), | ||
| 7443 | }, | ||
| 7444 | |||
| 7445 | .freebsd => switch (errno(std.c.ptrace( | ||
| 7446 | @intCast(request), | ||
| 7447 | pid, | ||
| 7448 | @ptrFromInt(addr), | ||
| 7449 | @intCast(data), | ||
| 7450 | ))) { | ||
| 7451 | .SUCCESS => {}, | ||
| 7452 | .SRCH => error.ProcessNotFound, | ||
| 7453 | .INVAL => unreachable, | ||
| 7454 | .PERM => error.PermissionDenied, | ||
| 7455 | .BUSY => error.DeviceBusy, | ||
| 7456 | .NOENT, .NOMEM => error.OutOfMemory, | ||
| 7457 | .NAMETOOLONG => error.NameTooLong, | ||
| 7458 | else => |err| return unexpectedErrno(err), | ||
| 7459 | }, | ||
| 7460 | |||
| 7461 | .netbsd => switch (errno(std.c.ptrace( | ||
| 7403 | @intCast(request), | 7462 | @intCast(request), |
| 7404 | pid, | 7463 | pid, |
| 7405 | @ptrFromInt(addr), | 7464 | @ptrFromInt(addr), |
| 7406 | @intCast(signal), | 7465 | @intCast(data), |
| 7407 | ))) { | 7466 | ))) { |
| 7408 | .SUCCESS => {}, | 7467 | .SUCCESS => {}, |
| 7409 | .SRCH => error.ProcessNotFound, | 7468 | .SRCH => error.ProcessNotFound, |
| 7410 | .INVAL => unreachable, | 7469 | .INVAL => unreachable, |
| 7411 | .PERM => error.PermissionDenied, | 7470 | .PERM => error.PermissionDenied, |
| 7412 | .BUSY => error.DeviceBusy, | 7471 | .BUSY => error.DeviceBusy, |
| 7472 | .DEADLK => error.DeadLock, | ||
| 7413 | else => |err| return unexpectedErrno(err), | 7473 | else => |err| return unexpectedErrno(err), |
| 7414 | }, | 7474 | }, |
| 7415 | 7475 | ||
| 7416 | else => switch (errno(system.ptrace(request, pid, addr, signal))) { | 7476 | .openbsd => switch (errno(std.c.ptrace( |
| 7477 | @intCast(request), | ||
| 7478 | pid, | ||
| 7479 | @ptrFromInt(addr), | ||
| 7480 | @intCast(data), | ||
| 7481 | ))) { | ||
| 7417 | .SUCCESS => {}, | 7482 | .SUCCESS => {}, |
| 7418 | .SRCH => error.ProcessNotFound, | 7483 | .SRCH => error.ProcessNotFound, |
| 7419 | .INVAL => unreachable, | 7484 | .INVAL => unreachable, |
| 7420 | .PERM => error.PermissionDenied, | 7485 | .PERM => error.PermissionDenied, |
| 7421 | .BUSY => error.DeviceBusy, | 7486 | .BUSY => error.DeviceBusy, |
| 7487 | .NOTSUP => error.OperationNotSupported, | ||
| 7422 | else => |err| return unexpectedErrno(err), | 7488 | else => |err| return unexpectedErrno(err), |
| 7423 | }, | 7489 | }, |
| 7490 | |||
| 7491 | else => @compileError("std.posix.ptrace unimplemented for target OS"), | ||
| 7424 | }; | 7492 | }; |
| 7425 | } | 7493 | } |
| 7426 | 7494 |