Mark CodeStatic regions that are writable as CodeMutable instead

This is required for applications that attempt to map from the bss.
This commit is contained in:
Billy Laws 2020-07-06 17:23:47 +01:00 committed by ◱ PixelyIon
parent 2f8a217204
commit 1383e17341
2 changed files with 7 additions and 2 deletions

View File

@ -126,6 +126,11 @@ namespace skyline::kernel::type {
throw exception("An error occurred while updating private memory's permissions in child process");
auto chunk = state.os->memory.GetChunk(address);
// If a static code region has been mapped as writable it needs to be changed to mutable
if (chunk->state.value == memory::states::CodeStatic.value && permission.w)
chunk->state = memory::states::CodeMutable;
BlockDescriptor block{
.address = address,
.size = size,

View File

@ -33,10 +33,10 @@ namespace skyline::loader {
process->NewHandle<kernel::type::KPrivateMemory>(base + executable.ro.offset, roSize, memory::Permission{true, false, false}, memory::states::CodeReadOnly); // R--
state.logger->Debug("Successfully mapped section .rodata @ 0x{0:X}, Size = 0x{1:X}", base + executable.ro.offset, roSize);
process->NewHandle<kernel::type::KPrivateMemory>(base + executable.data.offset, dataSize, memory::Permission{true, true, false}, memory::states::CodeStatic); // RW-
process->NewHandle<kernel::type::KPrivateMemory>(base + executable.data.offset, dataSize, memory::Permission{true, true, false}, memory::states::CodeMutable); // RW-
state.logger->Debug("Successfully mapped section .data @ 0x{0:X}, Size = 0x{1:X}", base + executable.data.offset, dataSize);
process->NewHandle<kernel::type::KPrivateMemory>(base + patchOffset, patchSize + padding, memory::Permission{true, true, true}, memory::states::CodeStatic); // RWX
process->NewHandle<kernel::type::KPrivateMemory>(base + patchOffset, patchSize + padding, memory::Permission{true, true, true}, memory::states::CodeMutable); // RWX
state.logger->Debug("Successfully mapped section .patch @ 0x{0:X}, Size = 0x{1:X}", base + patchOffset, patchSize + padding);
process->WriteMemory(executable.text.contents.data(), base + executable.text.offset, textSize);