authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-03-27 15:39:24+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-03-27 15:39:24+01:00
logcc9634a2d3ac3ee7ec36e16ab9117aad6e2da625
tree8b313771a3ddd68ea00593dae43d98526d414188
parentb5a5260546ddd8953e493f75c5ee12c5a853263b
parentb9efdbb412fa9e5691553eca49aacd31e9d7ff69
signaturebadge-check Signed by PGP key B5690EEEBB952194

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