Skip to content

Commit

Permalink
Fixing MyICJI::allocMem in superpmi to respect certain CorJitAllocMem…
Browse files Browse the repository at this point in the history
…Flag
  • Loading branch information
tannergooding committed May 8, 2020
1 parent 67f1b1f commit c056b88
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions src/coreclr/src/ToolBox/superpmi/superpmi/icorjitinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1578,6 +1578,18 @@ bool MyICJI::runWithErrorTrap(void (*function)(void*), void* param)
return RunWithErrorTrap(function, param);
}

// Ideally we'd just use the copies of this in standardmacros.h
// however, superpmi is missing various other dependencies as well
static size_t ALIGN_UP_SPMI(size_t val, size_t alignment)
{
return (val + (alignment - 1)) & ~(alignment - 1);
}

static void* ALIGN_UP_SPMI(void* val, size_t alignment)
{
return (void*)ALIGN_UP_SPMI((size_t)val, alignment);
}

// get a block of memory for the code, readonly data, and read-write data
void MyICJI::allocMem(ULONG hotCodeSize, /* IN */
ULONG coldCodeSize, /* IN */
Expand All @@ -1590,13 +1602,45 @@ void MyICJI::allocMem(ULONG hotCodeSize, /* IN */
)
{
jitInstance->mc->cr->AddCall("allocMem");
// TODO-Cleanup: investigate if we need to check roDataBlock as well. Could hot block size be ever 0?

// TODO-Cleanup: Could hot block size be ever 0?
*hotCodeBlock = jitInstance->mc->cr->allocateMemory(hotCodeSize);

if (coldCodeSize > 0)
*coldCodeBlock = jitInstance->mc->cr->allocateMemory(coldCodeSize);
else
*coldCodeBlock = nullptr;
*roDataBlock = jitInstance->mc->cr->allocateMemory(roDataSize);

if (roDataSize > 0)
{
size_t roDataAlignment = sizeof(void*);

if ((flag & CORJIT_ALLOCMEM_FLG_RODATA_32BYTE_ALIGN) != 0)
{
roDataAlignment = 32;
}
else if ((flag & CORJIT_ALLOCMEM_FLG_RODATA_16BYTE_ALIGN) != 0)
{
roDataAlignment = 16;
}
else if (roDataSize >= 8)
{
roDataAlignment = 8;
}

// We need to round the roDataSize up to the alignment size and then
// overallocate by at most alignment - sizeof(void*) to ensure that
// we can offset roDataBlock to be an aligned address and that the
// allocation contains at least the originally requested size after

roDataSize = ALIGN_UP_SPMI(static_cast<size_t>(roDataSize), roDataAlignment);
roDataSize = roDataSize + (roDataAlignment - sizeof(void*));
*roDataBlock = jitInstance->mc->cr->allocateMemory(roDataSize);
*roDataBlock = ALIGN_UP_SPMI(*roDataBlock, roDataAlignment);
}
else
*roDataBlock = nullptr;

jitInstance->mc->cr->recAllocMem(hotCodeSize, coldCodeSize, roDataSize, xcptnsCount, flag, hotCodeBlock,
coldCodeBlock, roDataBlock);
}
Expand Down

0 comments on commit c056b88

Please sign in to comment.