Merge pull request #5392 from neobrain/fix_code_cache_dupfd

LinuxSyscalls: Re-open file descriptors for parsing ELF headers
This commit is contained in:
Ryan Houdek authored and GitHub committed 2026-03-23 09:42:45 -07:00
commit 65a436ca98
1 file changed
+5 -1
@@ -219,8 +219,12 @@ static ReadELFHeadersResult ReadELFHeaders(int FD, std::span<std::byte> HeaderDa
// Read from FD in case the caller didn't have a mapped header available
}
// Re-open the file with a fresh file descriptor (and let ELFParser close it on return).
// NOTE: FDs returned by dup() share the same cursor state, so reading from them would have observable side effects.
auto NewFD = open(fextl::fmt::format("/proc/self/fd/{}", FD).c_str(), O_RDONLY);
ELFParser Parser;
Parser.ReadElf(dup(FD));
Parser.ReadElf(NewFD);
auto Relocations = Parser.PopulateRelocations();
if (!Relocations.empty()) {