8
8
9
9
Module Name:
10
10
11
- virtual.c
11
+ virtual.cpp
12
12
13
13
Abstract:
14
14
@@ -70,7 +70,7 @@ static LPVOID ReserveVirtualMemory(
70
70
71
71
72
72
// 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.
74
74
static ExecutableMemoryAllocator g_executableMemoryAllocator;
75
75
76
76
/* ++
@@ -226,7 +226,7 @@ static INT VIRTUALGetAllocationType( SIZE_T Index, CONST PCMI pInformation )
226
226
* IN BYTE* pBitArray - A pointer the array to be manipulated.
227
227
*
228
228
* Returns TRUE on success, FALSE otherwise.
229
- * Turn on/off memory staus bits.
229
+ * Turn on/off memory status bits.
230
230
*
231
231
*/
232
232
static BOOL VIRTUALSetPageBits ( UINT nStatus, SIZE_T nStartingBit,
@@ -445,20 +445,20 @@ static BOOL VIRTUALReleaseMemory( PCMI pMemoryToBeReleased )
445
445
pVirtualMemory = pMemoryToBeReleased->pNext ;
446
446
if ( pMemoryToBeReleased->pNext )
447
447
{
448
- pMemoryToBeReleased->pNext ->pLast = NULL ;
448
+ pMemoryToBeReleased->pNext ->pPrevious = NULL ;
449
449
}
450
450
}
451
451
else /* Could be anywhere in the list. */
452
452
{
453
453
/* Delete the entry from the linked list. */
454
- if ( pMemoryToBeReleased->pLast )
454
+ if ( pMemoryToBeReleased->pPrevious )
455
455
{
456
- pMemoryToBeReleased->pLast ->pNext = pMemoryToBeReleased->pNext ;
456
+ pMemoryToBeReleased->pPrevious ->pNext = pMemoryToBeReleased->pNext ;
457
457
}
458
458
459
459
if ( pMemoryToBeReleased->pNext )
460
460
{
461
- pMemoryToBeReleased->pNext ->pLast = pMemoryToBeReleased->pLast ;
461
+ pMemoryToBeReleased->pNext ->pPrevious = pMemoryToBeReleased->pPrevious ;
462
462
}
463
463
}
464
464
@@ -594,7 +594,7 @@ static void VIRTUALDisplayList( void )
594
594
DBGOUT ( " \t accessProtection %d \n " , p->accessProtection );
595
595
DBGOUT ( " \t allocationType %d \n " , p->allocationType );
596
596
DBGOUT ( " \t pNext %p \n " , p->pNext );
597
- DBGOUT ( " \t pLast %p \n " , p->pLast );
597
+ DBGOUT ( " \t pLast %p \n " , p->pPrevious );
598
598
599
599
count++;
600
600
p = p->pNext ;
@@ -611,107 +611,101 @@ static void VIRTUALDisplayList( void )
611
611
* NOTE: The caller must own the critical section.
612
612
*/
613
613
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. */
616
616
IN DWORD flAllocationType, /* Allocation Types. */
617
617
IN DWORD flProtection ) /* Protections flags on the memory. */
618
618
{
619
- PCMI pNewEntry = NULL ;
620
- PCMI pMemInfo = NULL ;
621
- BOOL bRetVal = TRUE ;
619
+ PCMI pNewEntry = nullptr ;
620
+ PCMI pMemInfo = nullptr ;
622
621
SIZE_T nBufferSize = 0 ;
623
622
624
- if ( ( memSize & VIRTUAL_PAGE_MASK ) != 0 )
623
+ if (( memSize & VIRTUAL_PAGE_MASK) != 0 )
625
624
{
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 ;
629
627
}
630
-
631
- if ( !(pNewEntry = ( PCMI )InternalMalloc ( sizeof ( *pNewEntry )) ) )
628
+
629
+ if (!(pNewEntry = (PCMI)InternalMalloc (sizeof (*pNewEntry))) )
632
630
{
633
631
ERROR ( " Unable to allocate memory for the structure.\n " );
634
- bRetVal = FALSE ;
635
- goto done;
632
+ return FALSE ;
636
633
}
637
-
634
+
638
635
pNewEntry->startBoundary = startBoundary;
639
636
pNewEntry->memSize = memSize;
640
637
pNewEntry->allocationType = flAllocationType;
641
638
pNewEntry->accessProtection = flProtection;
642
-
639
+
643
640
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 )
645
642
{
646
643
nBufferSize++;
647
644
}
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));
651
648
652
649
if (pNewEntry->pAllocState && pNewEntry->pProtectionState )
653
650
{
654
651
/* 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);
659
656
}
660
657
else
661
658
{
662
659
ERROR ( " Unable to allocate memory for the structure.\n " );
663
- bRetVal = FALSE ;
664
660
665
- if (pNewEntry->pProtectionState ) InternalFree ( pNewEntry->pProtectionState );
666
- pNewEntry->pProtectionState = NULL ;
661
+ if (pNewEntry->pProtectionState ) InternalFree (pNewEntry->pProtectionState );
662
+ pNewEntry->pProtectionState = nullptr ;
667
663
668
- if (pNewEntry->pAllocState ) InternalFree ( pNewEntry->pAllocState );
669
- pNewEntry->pAllocState = NULL ;
664
+ if (pNewEntry->pAllocState ) InternalFree (pNewEntry->pAllocState );
665
+ pNewEntry->pAllocState = nullptr ;
670
666
671
- InternalFree ( pNewEntry );
672
- pNewEntry = NULL ;
673
-
674
- goto done ;
667
+ InternalFree (pNewEntry);
668
+ pNewEntry = nullptr ;
669
+
670
+ return FALSE ;
675
671
}
676
672
677
673
pMemInfo = pVirtualMemory;
678
674
679
- if ( pMemInfo && pMemInfo->startBoundary < startBoundary )
675
+ if (pMemInfo && pMemInfo->startBoundary < startBoundary)
680
676
{
681
677
/* 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))
684
680
{
685
681
pMemInfo = pMemInfo->pNext ;
686
682
}
687
-
683
+
688
684
pNewEntry->pNext = pMemInfo->pNext ;
689
- pNewEntry->pLast = pMemInfo;
690
-
691
- if ( pNewEntry->pNext )
685
+ pNewEntry->pPrevious = pMemInfo;
686
+
687
+ if (pNewEntry->pNext )
692
688
{
693
- pNewEntry->pNext ->pLast = pNewEntry;
689
+ pNewEntry->pNext ->pPrevious = pNewEntry;
694
690
}
695
-
691
+
696
692
pMemInfo->pNext = pNewEntry;
697
693
}
698
694
else
699
695
{
700
- TRACE ( " Inserting a new element into the linked list\n " );
701
696
/* This is the first entry in the list. */
702
697
pNewEntry->pNext = pMemInfo;
703
- pNewEntry->pLast = NULL ;
704
-
705
- if ( pNewEntry->pNext )
698
+ pNewEntry->pPrevious = nullptr ;
699
+
700
+ if (pNewEntry->pNext )
706
701
{
707
- pNewEntry->pNext ->pLast = pNewEntry;
702
+ pNewEntry->pNext ->pPrevious = pNewEntry;
708
703
}
709
704
710
705
pVirtualMemory = pNewEntry ;
711
706
}
712
- done:
713
- TRACE ( " Exiting StoreAllocationInformation. \n " );
714
- return bRetVal;
707
+
708
+ return TRUE ;
715
709
}
716
710
717
711
/* *****
0 commit comments