summaryrefslogtreecommitdiff
path: root/src/pal
diff options
context:
space:
mode:
authorLeandro A. F. Pereira <leandro.pereira@microsoft.com>2019-06-10 15:44:29 -0700
committerJan Vorlicek <janvorli@microsoft.com>2019-06-11 00:44:29 +0200
commit90372481b01781243cd86f4eea93b8f976fba397 (patch)
treeb91196cc11ff81c678fc28e1be61766cdd866bbf /src/pal
parent730c3c5c66183418adbbc63acd40d261c9ce23ed (diff)
downloadcoreclr-90372481b01781243cd86f4eea93b8f976fba397.tar.gz
coreclr-90372481b01781243cd86f4eea93b8f976fba397.tar.bz2
coreclr-90372481b01781243cd86f4eea93b8f976fba397.zip
Use pread() to read DOS/NT headers when mapping PE files (#25059)
Shaves off two syscalls per managed assembly load.
Diffstat (limited to 'src/pal')
-rw-r--r--src/pal/src/map/map.cpp16
1 files changed, 2 insertions, 14 deletions
diff --git a/src/pal/src/map/map.cpp b/src/pal/src/map/map.cpp
index 7e6c89bbb7..ba764c0522 100644
--- a/src/pal/src/map/map.cpp
+++ b/src/pal/src/map/map.cpp
@@ -2255,25 +2255,13 @@ void * MAPMapPEFile(HANDLE hFile)
//Step 1: Read the PE headers and reserve enough space for the whole image somewhere.
IMAGE_DOS_HEADER dosHeader;
IMAGE_NT_HEADERS ntHeader;
- errno = 0;
- if (0 != lseek(fd, 0, SEEK_SET))
- {
- palError = FILEGetLastErrorFromErrno();
- ERROR_(LOADER)( "lseek failed\n" );
- goto done;
- }
- if (sizeof(dosHeader) != read(fd, &dosHeader, sizeof(dosHeader)))
+ if (sizeof(dosHeader) != pread(fd, &dosHeader, sizeof(dosHeader), 0))
{
palError = FILEGetLastErrorFromErrno();
ERROR_(LOADER)( "reading dos header failed\n" );
goto done;
}
- if (dosHeader.e_lfanew != lseek(fd, dosHeader.e_lfanew, SEEK_SET))
- {
- palError = FILEGetLastErrorFromErrno();
- goto done;
- }
- if (sizeof(ntHeader) != read(fd, &ntHeader, sizeof(ntHeader)))
+ if (sizeof(ntHeader) != pread(fd, &ntHeader, sizeof(ntHeader), dosHeader.e_lfanew))
{
palError = FILEGetLastErrorFromErrno();
goto done;