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

Commit 37e7654

Browse files
Rename PCMI->pLast and other cleanup of virtual memory code.
1 parent c1a5ed7 commit 37e7654

File tree

2 files changed

+54
-60
lines changed

2 files changed

+54
-60
lines changed

src/pal/src/include/pal/virtual.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ extern "C"
2828
typedef struct _CMI {
2929

3030
struct _CMI * pNext; /* Link to the next entry. */
31-
struct _CMI * pLast; /* Link to the previous entry. */
31+
struct _CMI * pPrevious; /* Link to the previous entry. */
3232

33-
UINT_PTR startBoundary; /* Starting location of the region. */
34-
SIZE_T memSize; /* Size of the entire region.. */
33+
UINT_PTR startBoundary; /* Starting location of the region. */
34+
SIZE_T memSize; /* Size of the entire region.. */
3535

3636
DWORD accessProtection; /* Initial allocation access protection. */
3737
DWORD allocationType; /* Initial allocation type. */

src/pal/src/map/virtual.cpp

Lines changed: 51 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
99
Module Name:
1010
11-
virtual.c
11+
virtual.cpp
1212
1313
Abstract:
1414
@@ -70,7 +70,7 @@ static LPVOID ReserveVirtualMemory(
7070

7171

7272
// A memory allocator that allocates memory from a pre-reserved region
73-
// of virtual memory that is located near the coreclr library.
73+
// of virtual memory that is located near the CoreCLR library.
7474
static ExecutableMemoryAllocator g_executableMemoryAllocator;
7575

7676
/*++
@@ -226,7 +226,7 @@ static INT VIRTUALGetAllocationType( SIZE_T Index, CONST PCMI pInformation )
226226
* IN BYTE* pBitArray - A pointer the array to be manipulated.
227227
*
228228
* Returns TRUE on success, FALSE otherwise.
229-
* Turn on/off memory staus bits.
229+
* Turn on/off memory status bits.
230230
*
231231
*/
232232
static BOOL VIRTUALSetPageBits ( UINT nStatus, SIZE_T nStartingBit,
@@ -445,20 +445,20 @@ static BOOL VIRTUALReleaseMemory( PCMI pMemoryToBeReleased )
445445
pVirtualMemory = pMemoryToBeReleased->pNext;
446446
if ( pMemoryToBeReleased->pNext )
447447
{
448-
pMemoryToBeReleased->pNext->pLast = NULL;
448+
pMemoryToBeReleased->pNext->pPrevious = NULL;
449449
}
450450
}
451451
else /* Could be anywhere in the list. */
452452
{
453453
/* Delete the entry from the linked list. */
454-
if ( pMemoryToBeReleased->pLast )
454+
if ( pMemoryToBeReleased->pPrevious )
455455
{
456-
pMemoryToBeReleased->pLast->pNext = pMemoryToBeReleased->pNext;
456+
pMemoryToBeReleased->pPrevious->pNext = pMemoryToBeReleased->pNext;
457457
}
458458

459459
if ( pMemoryToBeReleased->pNext )
460460
{
461-
pMemoryToBeReleased->pNext->pLast = pMemoryToBeReleased->pLast;
461+
pMemoryToBeReleased->pNext->pPrevious = pMemoryToBeReleased->pPrevious;
462462
}
463463
}
464464

@@ -594,7 +594,7 @@ static void VIRTUALDisplayList( void )
594594
DBGOUT( "\t accessProtection %d \n", p->accessProtection );
595595
DBGOUT( "\t allocationType %d \n", p->allocationType );
596596
DBGOUT( "\t pNext %p \n", p->pNext );
597-
DBGOUT( "\t pLast %p \n", p->pLast );
597+
DBGOUT( "\t pLast %p \n", p->pPrevious );
598598

599599
count++;
600600
p = p->pNext;
@@ -611,107 +611,101 @@ static void VIRTUALDisplayList( void )
611611
* NOTE: The caller must own the critical section.
612612
*/
613613
static BOOL VIRTUALStoreAllocationInfo(
614-
IN UINT_PTR startBoundary, /* Start of the region. */
615-
IN SIZE_T memSize, /* Size of the region. */
614+
IN UINT_PTR startBoundary, /* Start of the region. */
615+
IN SIZE_T memSize, /* Size of the region. */
616616
IN DWORD flAllocationType, /* Allocation Types. */
617617
IN DWORD flProtection ) /* Protections flags on the memory. */
618618
{
619-
PCMI pNewEntry = NULL;
620-
PCMI pMemInfo = NULL;
621-
BOOL bRetVal = TRUE;
619+
PCMI pNewEntry = nullptr;
620+
PCMI pMemInfo = nullptr;
622621
SIZE_T nBufferSize = 0;
623622

624-
if ( ( memSize & VIRTUAL_PAGE_MASK ) != 0 )
623+
if ((memSize & VIRTUAL_PAGE_MASK) != 0)
625624
{
626-
ERROR( "The memory size was not in multiples of the page size. \n" );
627-
bRetVal = FALSE;
628-
goto done;
625+
ERROR("The memory size was not a multiple of the page size. \n");
626+
return FALSE;
629627
}
630-
631-
if ( !(pNewEntry = ( PCMI )InternalMalloc( sizeof( *pNewEntry )) ) )
628+
629+
if (!(pNewEntry = (PCMI)InternalMalloc(sizeof(*pNewEntry))))
632630
{
633631
ERROR( "Unable to allocate memory for the structure.\n");
634-
bRetVal = FALSE;
635-
goto done;
632+
return FALSE;
636633
}
637-
634+
638635
pNewEntry->startBoundary = startBoundary;
639636
pNewEntry->memSize = memSize;
640637
pNewEntry->allocationType = flAllocationType;
641638
pNewEntry->accessProtection = flProtection;
642-
639+
643640
nBufferSize = memSize / VIRTUAL_PAGE_SIZE / CHAR_BIT;
644-
if ( ( memSize / VIRTUAL_PAGE_SIZE ) % CHAR_BIT != 0 )
641+
if ((memSize / VIRTUAL_PAGE_SIZE) % CHAR_BIT != 0)
645642
{
646643
nBufferSize++;
647644
}
648-
649-
pNewEntry->pAllocState = (BYTE*)InternalMalloc( nBufferSize );
650-
pNewEntry->pProtectionState = (BYTE*)InternalMalloc( (memSize / VIRTUAL_PAGE_SIZE) );
645+
646+
pNewEntry->pAllocState = (BYTE*)InternalMalloc(nBufferSize);
647+
pNewEntry->pProtectionState = (BYTE*)InternalMalloc((memSize / VIRTUAL_PAGE_SIZE));
651648

652649
if (pNewEntry->pAllocState && pNewEntry->pProtectionState)
653650
{
654651
/* Set the intial allocation state, and initial allocation protection. */
655-
VIRTUALSetAllocState( MEM_RESERVE, 0, nBufferSize * CHAR_BIT, pNewEntry );
656-
memset( pNewEntry->pProtectionState,
657-
VIRTUALConvertWinFlags( flProtection ),
658-
memSize / VIRTUAL_PAGE_SIZE );
652+
VIRTUALSetAllocState(MEM_RESERVE, 0, nBufferSize * CHAR_BIT, pNewEntry);
653+
memset(pNewEntry->pProtectionState,
654+
VIRTUALConvertWinFlags(flProtection),
655+
memSize / VIRTUAL_PAGE_SIZE);
659656
}
660657
else
661658
{
662659
ERROR( "Unable to allocate memory for the structure.\n");
663-
bRetVal = FALSE;
664660

665-
if (pNewEntry->pProtectionState) InternalFree( pNewEntry->pProtectionState );
666-
pNewEntry->pProtectionState = NULL;
661+
if (pNewEntry->pProtectionState) InternalFree(pNewEntry->pProtectionState);
662+
pNewEntry->pProtectionState = nullptr;
667663

668-
if (pNewEntry->pAllocState) InternalFree( pNewEntry->pAllocState );
669-
pNewEntry->pAllocState = NULL;
664+
if (pNewEntry->pAllocState) InternalFree(pNewEntry->pAllocState);
665+
pNewEntry->pAllocState = nullptr;
670666

671-
InternalFree( pNewEntry );
672-
pNewEntry = NULL;
673-
674-
goto done;
667+
InternalFree(pNewEntry);
668+
pNewEntry = nullptr;
669+
670+
return FALSE;
675671
}
676672

677673
pMemInfo = pVirtualMemory;
678674

679-
if ( pMemInfo && pMemInfo->startBoundary < startBoundary )
675+
if (pMemInfo && pMemInfo->startBoundary < startBoundary)
680676
{
681677
/* Look for the correct insert point */
682-
TRACE( "Looking for the correct insert location.\n");
683-
while ( pMemInfo->pNext && ( pMemInfo->pNext->startBoundary < startBoundary ) )
678+
TRACE("Looking for the correct insert location.\n");
679+
while (pMemInfo->pNext && (pMemInfo->pNext->startBoundary < startBoundary))
684680
{
685681
pMemInfo = pMemInfo->pNext;
686682
}
687-
683+
688684
pNewEntry->pNext = pMemInfo->pNext;
689-
pNewEntry->pLast = pMemInfo;
690-
691-
if ( pNewEntry->pNext )
685+
pNewEntry->pPrevious = pMemInfo;
686+
687+
if (pNewEntry->pNext)
692688
{
693-
pNewEntry->pNext->pLast = pNewEntry;
689+
pNewEntry->pNext->pPrevious = pNewEntry;
694690
}
695-
691+
696692
pMemInfo->pNext = pNewEntry;
697693
}
698694
else
699695
{
700-
TRACE( "Inserting a new element into the linked list\n" );
701696
/* This is the first entry in the list. */
702697
pNewEntry->pNext = pMemInfo;
703-
pNewEntry->pLast = NULL;
704-
705-
if ( pNewEntry->pNext )
698+
pNewEntry->pPrevious = nullptr;
699+
700+
if (pNewEntry->pNext)
706701
{
707-
pNewEntry->pNext->pLast = pNewEntry;
702+
pNewEntry->pNext->pPrevious = pNewEntry;
708703
}
709704

710705
pVirtualMemory = pNewEntry ;
711706
}
712-
done:
713-
TRACE( "Exiting StoreAllocationInformation. \n" );
714-
return bRetVal;
707+
708+
return TRUE;
715709
}
716710

717711
/******

0 commit comments

Comments
 (0)