| 1 | // Licensed to the .NET Foundation under one or more agreements. | 
|---|---|
| 2 | // The .NET Foundation licenses this file to you under the MIT license. | 
| 3 | // See the LICENSE file in the project root for more information. | 
| 4 | |
| 5 | /*============================================================ | 
| 6 | ** | 
| 7 | ** Class: COMMemoryFailPoint | 
| 8 | ** | 
| 9 | ** | 
| 10 | ** Purpose: Native methods for System.Runtime.MemoryFailPoint. | 
| 11 | ** These are to implement memory gates to limit allocations | 
| 12 | ** when progress will likely result in an OOM. | 
| 13 | ** | 
| 14 | ===========================================================*/ | 
| 15 | #include "common.h" | 
| 16 | |
| 17 | #include "frames.h" | 
| 18 | #include "commemoryfailpoint.h" | 
| 19 | |
| 20 | // Need to know the maximum segment size for both the normal GC heap and the | 
| 21 | // large object heap, as well as the top user-accessible address within the | 
| 22 | // address space (ie, theoretically 2^31 - 1 on a 32 bit machine, but a tad | 
| 23 | // lower in practice). This will help out with 32 bit machines running in | 
| 24 | // 3 GB mode. | 
| 25 | FCIMPL2(void, COMMemoryFailPoint::GetMemorySettings, UINT64* pMaxGCSegmentSize, UINT64* pTopOfMemory) | 
| 26 | { | 
| 27 | FCALL_CONTRACT; | 
| 28 | |
| 29 | IGCHeap * pGC = GCHeapUtilities::GetGCHeap(); | 
| 30 | size_t segment_size = pGC->GetValidSegmentSize(false); | 
| 31 | size_t large_segment_size = pGC->GetValidSegmentSize(true); | 
| 32 | _ASSERTE(segment_size < SIZE_T_MAX && large_segment_size < SIZE_T_MAX); | 
| 33 | if (segment_size > large_segment_size) | 
| 34 | *pMaxGCSegmentSize = (UINT64) segment_size; | 
| 35 | else | 
| 36 | *pMaxGCSegmentSize = (UINT64) large_segment_size; | 
| 37 | |
| 38 | // GetTopMemoryAddress returns a void*, which can't be cast | 
| 39 | // directly to a UINT64 without causing an error from GCC. | 
| 40 | void * topOfMem = GetTopMemoryAddress(); | 
| 41 | *pTopOfMemory = (UINT64) (size_t) topOfMem; | 
| 42 | } | 
| 43 | FCIMPLEND | 
| 44 |