diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SyscallsSMCTracking.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/SyscallsSMCTracking.cpp index ad99ccabb..b1c516a6a 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/SyscallsSMCTracking.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/SyscallsSMCTracking.cpp @@ -219,8 +219,12 @@ static ReadELFHeadersResult ReadELFHeaders(int FD, std::span 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()) {