diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-01-14 18:04:11 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-03-15 10:48:12 -0700 |
| commit | 50a2bb58d23a686f52b389c062f0299cc2a5f8ed (patch) | |
| tree | 22eb3d26a53fc2fe511bc748fce6bc12508abd6a /src/link.zig | |
| parent | ae8e7c8f5a6065d12087aa547971001a399667b9 (diff) | |
| download | zig-50a2bb58d23a686f52b389c062f0299cc2a5f8ed.tar.gz zig-50a2bb58d23a686f52b389c062f0299cc2a5f8ed.zip | |
link: PTRACE_ATTACH/PTRACE_DETACH
Diffstat (limited to 'src/link.zig')
| -rw-r--r-- | src/link.zig | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/link.zig b/src/link.zig index 34a16a1a1b..a2f40eed65 100644 --- a/src/link.zig +++ b/src/link.zig @@ -378,7 +378,7 @@ pub const File = struct { if (build_options.only_c) unreachable; if (base.file != null) return; const emit = base.options.emit orelse return; - if (base.child_pid != null) { + if (base.child_pid) |pid| { // If we try to open the output file in write mode while it is running, // it will return ETXTBSY. So instead, we copy the file, atomically rename it // over top of the exe path, and then proceed normally. This changes the inode, @@ -388,6 +388,11 @@ pub const File = struct { }); try emit.directory.handle.copyFile(emit.sub_path, emit.directory.handle, tmp_sub_path, .{}); try emit.directory.handle.rename(tmp_sub_path, emit.sub_path); + + switch (std.os.errno(std.os.linux.ptrace(std.os.linux.PTRACE.ATTACH, pid, 0, 0, 0))) { + .SUCCESS => {}, + else => |errno| log.warn("ptrace failure: {s}", .{@tagName(errno)}), + } } base.file = try emit.directory.handle.createFile(emit.sub_path, .{ .truncate = false, @@ -437,6 +442,13 @@ pub const File = struct { } f.close(); base.file = null; + + if (base.child_pid) |pid| { + switch (std.os.errno(std.os.linux.ptrace(std.os.linux.PTRACE.DETACH, pid, 0, 0, 0))) { + .SUCCESS => {}, + else => |errno| log.warn("ptrace failure: {s}", .{@tagName(errno)}), + } + } }, .c, .spirv, .nvptx => {}, } |
