| ... | ... | @@ -1067,87 +1067,6 @@ pub fn getBaseAddress() usize { |
| 1067 | 1067 | } |
| 1068 | 1068 | } |
| 1069 | 1069 | |
| 1070 | | /// Caller owns the result value and each inner slice. |
| 1071 | | /// TODO Remove the `Allocator` requirement from this API, which will remove the `Allocator` |
| 1072 | | /// requirement from `std.zig.system.NativeTargetInfo.detect`. Most likely this will require |
| 1073 | | /// introducing a new, lower-level function which takes a callback function, and then this |
| 1074 | | /// function which takes an allocator can exist on top of it. |
| 1075 | | pub fn getSelfExeSharedLibPaths(allocator: Allocator) error{OutOfMemory}![][:0]u8 { |
| 1076 | | switch (builtin.link_mode) { |
| 1077 | | .Static => return &[_][:0]u8{}, |
| 1078 | | .Dynamic => {}, |
| 1079 | | } |
| 1080 | | const List = std.ArrayList([:0]u8); |
| 1081 | | switch (builtin.os.tag) { |
| 1082 | | .linux, |
| 1083 | | .freebsd, |
| 1084 | | .netbsd, |
| 1085 | | .dragonfly, |
| 1086 | | .openbsd, |
| 1087 | | .solaris, |
| 1088 | | => { |
| 1089 | | var paths = List.init(allocator); |
| 1090 | | errdefer { |
| 1091 | | const slice = paths.toOwnedSlice(); |
| 1092 | | for (slice) |item| { |
| 1093 | | allocator.free(item); |
| 1094 | | } |
| 1095 | | allocator.free(slice); |
| 1096 | | } |
| 1097 | | try os.dl_iterate_phdr(&paths, error{OutOfMemory}, struct { |
| 1098 | | fn callback(info: *os.dl_phdr_info, size: usize, list: *List) !void { |
| 1099 | | _ = size; |
| 1100 | | const name = info.dlpi_name orelse return; |
| 1101 | | if (name[0] == '/') { |
| 1102 | | const item = try list.allocator.dupeZ(u8, mem.sliceTo(name, 0)); |
| 1103 | | errdefer list.allocator.free(item); |
| 1104 | | try list.append(item); |
| 1105 | | } |
| 1106 | | } |
| 1107 | | }.callback); |
| 1108 | | return paths.toOwnedSlice(); |
| 1109 | | }, |
| 1110 | | .macos, .ios, .watchos, .tvos => { |
| 1111 | | var paths = List.init(allocator); |
| 1112 | | errdefer { |
| 1113 | | const slice = paths.toOwnedSlice(); |
| 1114 | | for (slice) |item| { |
| 1115 | | allocator.free(item); |
| 1116 | | } |
| 1117 | | allocator.free(slice); |
| 1118 | | } |
| 1119 | | const img_count = std.c._dyld_image_count(); |
| 1120 | | var i: u32 = 0; |
| 1121 | | while (i < img_count) : (i += 1) { |
| 1122 | | const name = std.c._dyld_get_image_name(i); |
| 1123 | | const item = try allocator.dupeZ(u8, mem.sliceTo(name, 0)); |
| 1124 | | errdefer allocator.free(item); |
| 1125 | | try paths.append(item); |
| 1126 | | } |
| 1127 | | return paths.toOwnedSlice(); |
| 1128 | | }, |
| 1129 | | // revisit if Haiku implements dl_iterat_phdr (https://dev.haiku-os.org/ticket/15743) |
| 1130 | | .haiku => { |
| 1131 | | var paths = List.init(allocator); |
| 1132 | | errdefer { |
| 1133 | | const slice = paths.toOwnedSlice(); |
| 1134 | | for (slice) |item| { |
| 1135 | | allocator.free(item); |
| 1136 | | } |
| 1137 | | allocator.free(slice); |
| 1138 | | } |
| 1139 | | |
| 1140 | | var b = "/boot/system/runtime_loader"; |
| 1141 | | const item = try allocator.dupeZ(u8, mem.sliceTo(b, 0)); |
| 1142 | | errdefer allocator.free(item); |
| 1143 | | try paths.append(item); |
| 1144 | | |
| 1145 | | return paths.toOwnedSlice(); |
| 1146 | | }, |
| 1147 | | else => @compileError("getSelfExeSharedLibPaths unimplemented for this target"), |
| 1148 | | } |
| 1149 | | } |
| 1150 | | |
| 1151 | 1070 | /// Tells whether calling the `execv` or `execve` functions will be a compile error. |
| 1152 | 1071 | pub const can_execv = switch (builtin.os.tag) { |
| 1153 | 1072 | .windows, .haiku, .wasi => false, |