Source
pub fn getBaseAddress() usize {
switch (native_os) {
.linux => {
const getauxval = if (builtin.link_libc) std.c.getauxval else std.os.linux.getauxval;
const base = getauxval(std.elf.AT_BASE);
if (base != 0) {
return base;
}
const phdr = getauxval(std.elf.AT_PHDR);
return phdr - @sizeOf(std.elf.Ehdr);
},
.driverkit, .ios, .macos, .tvos, .visionos, .watchos => {
return @intFromPtr(&std.c._mh_execute_header);
},
.windows => return @intFromPtr(windows.kernel32.GetModuleHandleW(null)),
else => @compileError("Unsupported OS"),
}
}