Skip to content

Commit 59465d6

Browse files
authored
Do not use /dev/zero to mmap anonymous memory (#48140)
* return void * Always use MAP_ANON * remove HAVE_MMAP_DEV_ZERO config
1 parent 42009d1 commit 59465d6

File tree

4 files changed

+2
-45
lines changed

4 files changed

+2
-45
lines changed

src/coreclr/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public partial class AssemblyLoadContext
1919

2020
[RequiresUnreferencedCode("Types and members the loaded assembly depends on might be removed")]
2121
[DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)]
22-
private static extern IntPtr LoadFromStream(IntPtr ptrNativeAssemblyLoadContext, IntPtr ptrAssemblyArray, int iAssemblyArrayLen, IntPtr ptrSymbols, int iSymbolArrayLen, ObjectHandleOnStack retAssembly);
22+
private static extern void LoadFromStream(IntPtr ptrNativeAssemblyLoadContext, IntPtr ptrAssemblyArray, int iAssemblyArrayLen, IntPtr ptrSymbols, int iSymbolArrayLen, ObjectHandleOnStack retAssembly);
2323

2424
[DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)]
2525
internal static extern void InternalSetProfileRoot(string directoryPath);

src/coreclr/pal/src/config.h.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@
116116
#cmakedefine01 HAVE_CLOCK_GETTIME_NSEC_NP
117117
#cmakedefine01 HAVE_CLOCK_THREAD_CPUTIME
118118
#cmakedefine01 HAVE_PTHREAD_CONDATTR_SETCLOCK
119-
#cmakedefine01 HAVE_MMAP_DEV_ZERO
120119
#cmakedefine01 MMAP_ANON_IGNORES_PROTECTION
121120
#cmakedefine01 ONE_SHARED_MAPPING_PER_FILEREGION_PER_PROCESS
122121
#cmakedefine01 PTHREAD_CREATE_MODIFIES_ERRNO

src/coreclr/pal/src/configure.cmake

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -477,26 +477,6 @@ int main()
477477
}" HAVE_CLOCK_THREAD_CPUTIME)
478478
set(CMAKE_REQUIRED_LIBRARIES)
479479

480-
check_cxx_source_runs("
481-
#include <stdlib.h>
482-
#include <sys/types.h>
483-
#include <sys/mman.h>
484-
#include <fcntl.h>
485-
486-
int main(void) {
487-
int devzero;
488-
void *retval;
489-
490-
devzero = open(\"/dev/zero\", O_RDWR);
491-
if (-1 == devzero) {
492-
exit(1);
493-
}
494-
retval = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, devzero, 0);
495-
if (retval == (void *)-1) {
496-
exit(1);
497-
}
498-
exit(0);
499-
}" HAVE_MMAP_DEV_ZERO)
500480
check_cxx_source_runs("
501481
#include <sys/types.h>
502482
#include <sys/mman.h>

src/coreclr/pal/src/map/map.cpp

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,10 @@ MAPmmapAndRecord(
102102
LPVOID *ppvBaseAddress
103103
);
104104

105-
#if !HAVE_MMAP_DEV_ZERO
106105
/* We need MAP_ANON. However on some platforms like HP-UX, it is defined as MAP_ANONYMOUS */
107106
#if !defined(MAP_ANON) && defined(MAP_ANONYMOUS)
108107
#define MAP_ANON MAP_ANONYMOUS
109108
#endif
110-
#endif
111109

112110
void
113111
FileMappingCleanupRoutine(
@@ -477,22 +475,7 @@ CorUnix::InternalCreateFileMapping(
477475
goto ExitInternalCreateFileMapping;
478476
}
479477

480-
#if HAVE_MMAP_DEV_ZERO
481-
482-
UnixFd = InternalOpen(pImmutableData->lpFileName, O_RDWR | O_CLOEXEC);
483-
if ( -1 == UnixFd )
484-
{
485-
ERROR( "Unable to open the file.\n");
486-
palError = ERROR_INTERNAL_ERROR;
487-
goto ExitInternalCreateFileMapping;
488-
}
489-
490-
#else //!HAVE_MMAP_DEV_ZERO
491-
492478
UnixFd = -1; /* will pass MAP_ANON to mmap() instead */
493-
494-
#endif //!HAVE_MMAP_DEV_ZERO
495-
496479
}
497480
else
498481
{
@@ -1057,13 +1040,11 @@ CorUnix::InternalMapViewOfFile(
10571040
if (FILE_MAP_COPY == dwDesiredAccess)
10581041
{
10591042
int flags = MAP_PRIVATE;
1060-
1061-
#if !HAVE_MMAP_DEV_ZERO
10621043
if (pProcessLocalData->UnixFd == -1)
10631044
{
10641045
flags |= MAP_ANON;
10651046
}
1066-
#endif
1047+
10671048
pvBaseAddress = mmap(
10681049
NULL,
10691050
dwNumberOfBytesToMap,
@@ -1079,13 +1060,10 @@ CorUnix::InternalMapViewOfFile(
10791060
if (prot != -1)
10801061
{
10811062
int flags = MAP_SHARED;
1082-
1083-
#if !HAVE_MMAP_DEV_ZERO
10841063
if (pProcessLocalData->UnixFd == -1)
10851064
{
10861065
flags |= MAP_ANON;
10871066
}
1088-
#endif
10891067

10901068
pvBaseAddress = mmap(
10911069
NULL,

0 commit comments

Comments
 (0)