authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-03-27 15:39:24+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-03-27 21:08:04+01:00
loged6418544c4af7a12bc36fe7c8ec0feac78776c1
treea8abc052f6d8d4e3b72ef74f47f2858d37219d47
parent3ae9a99f628a78ad2f35d97a930b752f354443a1
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

Merge pull request #23373 from alexrp/get-base-address

`std.process`: Some minor fixes for `getBaseAddress()`

1 files changed, 4 insertions(+), 3 deletions(-)

lib/std/process.zig+4-3
...@@ -1651,14 +1651,15 @@ pub fn posixGetUserInfo(name: []const u8) !UserInfo {...@@ -1651,14 +1651,15 @@ pub fn posixGetUserInfo(name: []const u8) !UserInfo {
1651pub fn getBaseAddress() usize {1651pub fn getBaseAddress() usize {
1652 switch (native_os) {1652 switch (native_os) {
1653 .linux => {1653 .linux => {
1654 const base = std.os.linux.getauxval(std.elf.AT_BASE);1654 const getauxval = if (builtin.link_libc) std.c.getauxval else std.os.linux.getauxval;
1655 const base = getauxval(std.elf.AT_BASE);
1655 if (base != 0) {1656 if (base != 0) {
1656 return base;1657 return base;
1657 }1658 }
1658 const phdr = std.os.linux.getauxval(std.elf.AT_PHDR);1659 const phdr = getauxval(std.elf.AT_PHDR);
1659 return phdr - @sizeOf(std.elf.Ehdr);1660 return phdr - @sizeOf(std.elf.Ehdr);
1660 },1661 },
1661 .macos, .freebsd, .netbsd => {1662 .driverkit, .ios, .macos, .tvos, .visionos, .watchos => {
1662 return @intFromPtr(&std.c._mh_execute_header);1663 return @intFromPtr(&std.c._mh_execute_header);
1663 },1664 },
1664 .windows => return @intFromPtr(windows.kernel32.GetModuleHandleW(null)),1665 .windows => return @intFromPtr(windows.kernel32.GetModuleHandleW(null)),