authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-03 09:15:40-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-03-03 09:15:40-05:00
log387418277a4964714ddaec3336a602ec87dde0f9
tree3983b22b7288ae7acefd117f8234c2bce8c74bd7
parentd7579a2fcb0edaa1f6036101d00316abccac0c7e
parent755941830555b7423903053742fcc21d49cd3923
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #4601 from alexnask/fix_3997

Allow wrapping in VDSO lookup

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

lib/std/os/linux/vdso.zig+7-3
......@@ -22,7 +22,11 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
2222 }) {
2323 const this_ph = @intToPtr(*elf.Phdr, ph_addr);
2424 switch (this_ph.p_type) {
25 elf.PT_LOAD => base = vdso_addr + this_ph.p_offset - this_ph.p_vaddr,
25 // On WSL1 as well as older kernels, the VDSO ELF image is pre-linked in the upper half
26 // of the memory space (e.g. p_vaddr = 0xffffffffff700000 on WSL1).
27 // Wrapping operations are used on this line as well as subsequent calculations relative to base
28 // (lines 47, 78) to ensure no overflow check is tripped.
29 elf.PT_LOAD => base = vdso_addr +% this_ph.p_offset -% this_ph.p_vaddr,
2630 elf.PT_DYNAMIC => maybe_dynv = @intToPtr([*]usize, vdso_addr + this_ph.p_offset),
2731 else => {},
2832 }
......@@ -40,7 +44,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
4044 {
4145 var i: usize = 0;
4246 while (dynv[i] != 0) : (i += 2) {
43 const p = base + dynv[i + 1];
47 const p = base +% dynv[i + 1];
4448 switch (dynv[i]) {
4549 elf.DT_STRTAB => maybe_strings = @intToPtr([*]u8, p),
4650 elf.DT_SYMTAB => maybe_syms = @intToPtr([*]elf.Sym, p),
......@@ -71,7 +75,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
7175 if (!checkver(maybe_verdef.?, versym[i], vername, strings))
7276 continue;
7377 }
74 return base + syms[i].st_value;
78 return base +% syms[i].st_value;
7579 }
7680
7781 return 0;