Skip to content

Why RhAllocateHuntsMapping request execution permission for memory on nativeaot runtime. #112578

Closed
@CeSun

Description

@CeSun

Why does the RhAllocateHuntsMapping function request execution permission for memory on the NativeAOT runtime on Linux?

Did you not consider the situation where the system does not support JIT (the system prohibits mmap from requesting executable anonymous memory)?

// Note: On secure linux systems, we can't add execute permissions to a mapped virtual memory if it was not created
// with execute permissions in the first place. This is why we create the virtual section with RX permissions, then
// reduce it to RW for the data section. For the stubs section we need to increase to RWX to generate the stubs
// instructions. After this we go back to RX for the stubs section before the stubs are used and should not be
// changed anymore.
void * pNewMapping = PalVirtualAlloc(THUNKS_MAP_SIZE * 2, PAGE_EXECUTE_READ);
if (pNewMapping == NULL)
return NULL;

if (!PalVirtualProtect(pDataSection, THUNKS_MAP_SIZE, PAGE_READWRITE) ||
!PalVirtualProtect(pThunksSection, THUNKS_MAP_SIZE, PAGE_EXECUTE_READWRITE))
{
PalVirtualFree(pNewMapping, THUNKS_MAP_SIZE * 2);
return NULL;
}

if (!PalVirtualProtect(pThunksSection, THUNKS_MAP_SIZE, PAGE_EXECUTE_READ))
{
PalVirtualFree(pNewMapping, THUNKS_MAP_SIZE * 2);
return NULL;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions