| ... | ... | @@ -1041,63 +1041,6 @@ pub fn uname(uts: *utsname) usize { |
| 1041 | 1041 | return syscall1(SYS_uname, @ptrToInt(uts)); |
| 1042 | 1042 | } |
| 1043 | 1043 | |
| 1044 | | // XXX: This should be weak |
| 1045 | | extern const __ehdr_start: elf.Ehdr; |
| 1046 | | |
| 1047 | | pub fn dl_iterate_phdr(comptime T: type, callback: extern fn (info: *dl_phdr_info, size: usize, data: ?*T) i32, data: ?*T) isize { |
| 1048 | | if (builtin.link_libc) { |
| 1049 | | return std.c.dl_iterate_phdr(@ptrCast(std.c.dl_iterate_phdr_callback, callback), @ptrCast(?*c_void, data)); |
| 1050 | | } |
| 1051 | | |
| 1052 | | const elf_base = @ptrToInt(&__ehdr_start); |
| 1053 | | const n_phdr = __ehdr_start.e_phnum; |
| 1054 | | const phdrs = (@intToPtr([*]elf.Phdr, elf_base + __ehdr_start.e_phoff))[0..n_phdr]; |
| 1055 | | |
| 1056 | | var it = dl.linkmap_iterator(phdrs) catch return 0; |
| 1057 | | |
| 1058 | | // The executable has no dynamic link segment, create a single entry for |
| 1059 | | // the whole ELF image |
| 1060 | | if (it.end()) { |
| 1061 | | var info = dl_phdr_info{ |
| 1062 | | .dlpi_addr = elf_base, |
| 1063 | | .dlpi_name = "/proc/self/exe", |
| 1064 | | .dlpi_phdr = @intToPtr([*]elf.Phdr, elf_base + __ehdr_start.e_phoff), |
| 1065 | | .dlpi_phnum = __ehdr_start.e_phnum, |
| 1066 | | }; |
| 1067 | | |
| 1068 | | return callback(&info, @sizeOf(dl_phdr_info), data); |
| 1069 | | } |
| 1070 | | |
| 1071 | | // Last return value from the callback function |
| 1072 | | var last_r: isize = 0; |
| 1073 | | while (it.next()) |entry| { |
| 1074 | | var dlpi_phdr: usize = undefined; |
| 1075 | | var dlpi_phnum: u16 = undefined; |
| 1076 | | |
| 1077 | | if (entry.l_addr != 0) { |
| 1078 | | const elf_header = @intToPtr(*elf.Ehdr, entry.l_addr); |
| 1079 | | dlpi_phdr = entry.l_addr + elf_header.e_phoff; |
| 1080 | | dlpi_phnum = elf_header.e_phnum; |
| 1081 | | } else { |
| 1082 | | // This is the running ELF image |
| 1083 | | dlpi_phdr = elf_base + __ehdr_start.e_phoff; |
| 1084 | | dlpi_phnum = __ehdr_start.e_phnum; |
| 1085 | | } |
| 1086 | | |
| 1087 | | var info = dl_phdr_info{ |
| 1088 | | .dlpi_addr = entry.l_addr, |
| 1089 | | .dlpi_name = entry.l_name, |
| 1090 | | .dlpi_phdr = @intToPtr([*]elf.Phdr, dlpi_phdr), |
| 1091 | | .dlpi_phnum = dlpi_phnum, |
| 1092 | | }; |
| 1093 | | |
| 1094 | | last_r = callback(&info, @sizeOf(dl_phdr_info), data); |
| 1095 | | if (last_r != 0) break; |
| 1096 | | } |
| 1097 | | |
| 1098 | | return last_r; |
| 1099 | | } |
| 1100 | | |
| 1101 | 1044 | pub fn io_uring_setup(entries: u32, p: *io_uring_params) usize { |
| 1102 | 1045 | return syscall2(SYS_io_uring_setup, entries, @ptrToInt(p)); |
| 1103 | 1046 | } |