Fix edge case of code heap initial request#71213
Conversation
When the requested size passed to the LoaderCodeHeap::CreateCodeHeap is less than 16 bytes smaller than the COLLECTIBLE_CODEHEAP_SIZE, we incorrectly try to use the initially preallocated block. The problem is that besides the requested size, we also allocate JUMP_ALLOCATE_SIZE sized block. In the edge case mentioned above, it doesn't fit and we assert in debug builds of the runtime. In release build, it would throw OOM in such case.
|
@jkotas most of the changes are just because I've made the |
|
|
||
| pBaseAddr = (BYTE *)pInfo->m_pAllocator->GetCodeHeapInitialBlock(loAddr, hiAddr, (DWORD)initialRequestSize, &dwSizeAcquiredFromInitialBlock); | ||
| size_t allocationSize = pCodeHeap->m_LoaderHeap.AllocMem_TotalSize(initialRequestSize); | ||
| #if defined(TARGET_AMD64) || defined(TARGET_ARM64) || defined(TARGET_LOONGARCH64) |
There was a problem hiding this comment.
Can we use #ifdef TARGET_64BIT instead (as done below on line 2600)?
There was a problem hiding this comment.
Sure, I can do that. I've just copied the same ifdef that we have below where we allocate the personality routine. But there are many more places in the code where we have this same compound #if. So maybe it would be worth a separate cleanup instead.
There was a problem hiding this comment.
Btw even the CLRPersonalityRoutine declaration is under this compound ifdef
There was a problem hiding this comment.
Sure. Some of the usage of HOST_64BIT in VM can also be reviewed as part of that work, because it looks like the correct macro for them (in most places) is TARGET_64BIT (but it will require an in-depth analysis: #2256 (comment)).
When the requested size passed to the
LoaderCodeHeap::CreateCodeHeapis lessthan 16 bytes smaller than the
COLLECTIBLE_CODEHEAP_SIZE, we incorrectlytry to use the initially preallocated block. The problem is that besides the
requested size, we also allocate
JUMP_ALLOCATE_SIZEsized block. In theedge case mentioned above, it doesn't fit and we assert in debug builds
of the runtime.
In release build, it would throw OOM in such case.
This issue was found by the Fuzzlyn tool.
Close #71200