Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 4670803

Browse files
committed
Mmap native images at default base address if env variable COMPlus_UseDefaultBaseAddr=0x1 is setup
1 parent 2273ccf commit 4670803

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

src/pal/src/include/pal/init.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ extern Volatile<INT> init_count;
4141

4242
extern SIZE_T g_defaultStackSize;
4343

44+
extern BOOL g_useDefaultBaseAddr;
45+
4446
/*++
4547
MACRO:
4648
PALIsInitialized

src/pal/src/init/pal.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ static pthread_mutex_t init_critsec_mutex = PTHREAD_MUTEX_INITIALIZER;
104104
// The default minimum stack size
105105
SIZE_T g_defaultStackSize = 0;
106106

107+
// The default value of parameter, whether to mmap images at default base address or not
108+
BOOL g_useDefaultBaseAddr = FALSE;
109+
107110
/* critical section to protect access to init_count. This is allocated on the
108111
very first PAL_Initialize call, and is freed afterward. */
109112
static PCRITICAL_SECTION init_critsec = NULL;
@@ -382,6 +385,20 @@ Initialize(
382385
}
383386
#endif // ENSURE_PRIMARY_STACK_SIZE
384387

388+
char* useDefaultBaseAddr = getenv("COMPlus_UseDefaultBaseAddr");
389+
if (useDefaultBaseAddr != NULL)
390+
{
391+
errno = 0;
392+
// Like all numeric values specific by the COMPlus_xxx variables, it is a
393+
// hexadecimal string without any prefix.
394+
long int flag = strtol(useDefaultBaseAddr, NULL, 16);
395+
396+
if (errno == 0)
397+
{
398+
g_useDefaultBaseAddr = (BOOL) flag;
399+
}
400+
}
401+
385402
// Initialize the TLS lookaside cache
386403
if (FALSE == TLSInitialize())
387404
{

src/pal/src/map/map.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2350,9 +2350,14 @@ void * MAPMapPEFile(HANDLE hFile)
23502350

23512351
if (loadedBase == NULL)
23522352
{
2353+
void *usedBaseAddr = NULL;
2354+
if (g_useDefaultBaseAddr)
2355+
{
2356+
usedBaseAddr = (void*) preferredBase;
2357+
}
23532358
// MAC64 requires we pass MAP_SHARED (or MAP_PRIVATE) flags - otherwise, the call is failed.
23542359
// Refer to mmap documentation at http://www.manpagez.com/man/2/mmap/ for details.
2355-
loadedBase = mmap(NULL, virtualSize, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0);
2360+
loadedBase = mmap(usedBaseAddr, virtualSize, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0);
23562361
}
23572362

23582363
if (MAP_FAILED == loadedBase)

0 commit comments

Comments
 (0)