mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 14:23:09 +00:00
Merge pull request #23373 from alexrp/get-base-address
`std.process`: Some minor fixes for `getBaseAddress()`
This commit is contained in:
commit
cc9634a2d3
@ -1652,14 +1652,15 @@ pub fn posixGetUserInfo(name: []const u8) !UserInfo {
|
||||
pub fn getBaseAddress() usize {
|
||||
switch (native_os) {
|
||||
.linux => {
|
||||
const base = std.os.linux.getauxval(std.elf.AT_BASE);
|
||||
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 = std.os.linux.getauxval(std.elf.AT_PHDR);
|
||||
const phdr = getauxval(std.elf.AT_PHDR);
|
||||
return phdr - @sizeOf(std.elf.Ehdr);
|
||||
},
|
||||
.macos, .freebsd, .netbsd => {
|
||||
.driverkit, .ios, .macos, .tvos, .visionos, .watchos => {
|
||||
return @intFromPtr(&std.c._mh_execute_header);
|
||||
},
|
||||
.windows => return @intFromPtr(windows.kernel32.GetModuleHandleW(null)),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user