mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-05-29 14:53:18 +00:00
Implemented sceKernelMTypeProtect and sceKernelMProtect (#387)
* Fixed ORBIS_KERNEL_MAP_OP_TYPE_PROTECT for batchmap2
* Fix merge
* Changed 4 to ORBIS_KERNEL_MAP_OP_TYPE_PROTECT
* Removed MProtect from AddressSpace
* Added Mtyprotect and moved Mprotect to ORBIS_KERNEL_MAP_OP_PROTECT
* Changed Protect for Windows
* reverted the previous function
* Fixed Mtypeprotect and MProtect
* ''
* ''
* Took out logs stopping build
* clang-format issues
* Fixed the order of mtypeprotect and mprotect in batchmap2
* ''
* update branch
* ''
* Fixed nits
* ''
* Update submodules to latest commits
* ''
* reverted ffmpeg
* ''
* Fixed the nits
* ''
* ''
* ''
* ''
* ''
* Fix clang formatting, DEBUG_ASSERT, and extra spacing
* Fix build issues
* Revert "Fix build issues"
This reverts commit 9185f96ec9
.
* ''
* ''
* ''
* Changes for MemoryProt Format
* ''
* ''
* ''
This commit is contained in:
parent
0dd6e257c5
commit
b9c6093717
6 changed files with 202 additions and 25 deletions
|
@ -454,6 +454,8 @@ void LibKernel_Register(Core::Loader::SymbolsResolver* sym) {
|
|||
LIB_FUNCTION("F6e0kwo4cnk", "libkernel", 1, "libkernel", 1, 1, sceKernelTriggerUserEvent);
|
||||
LIB_FUNCTION("LJDwdSNTnDg", "libkernel", 1, "libkernel", 1, 1, sceKernelDeleteUserEvent);
|
||||
LIB_FUNCTION("mJ7aghmgvfc", "libkernel", 1, "libkernel", 1, 1, sceKernelGetEventId);
|
||||
LIB_FUNCTION("9bfdLIyuwCY", "libkernel", 1, "libkernel", 1, 1, sceKernelMTypeProtect);
|
||||
LIB_FUNCTION("vSMAm3cxYTY", "libkernel", 1, "libkernel", 1, 1, sceKernelMProtect);
|
||||
LIB_FUNCTION("23CPPI1tyBY", "libkernel", 1, "libkernel", 1, 1, sceKernelGetEventFilter);
|
||||
|
||||
// misc
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "common/assert.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "common/singleton.h"
|
||||
#include "core/address_space.h"
|
||||
#include "core/libraries/error_codes.h"
|
||||
#include "core/libraries/kernel/memory_management.h"
|
||||
#include "core/linker.h"
|
||||
|
@ -218,6 +219,19 @@ int PS4_SYSV_ABI sceKernelQueryMemoryProtection(void* addr, void** start, void**
|
|||
return memory->QueryProtection(std::bit_cast<VAddr>(addr), start, end, prot);
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI sceKernelMProtect(const void* addr, size_t size, int prot) {
|
||||
Core::MemoryManager* memory_manager = Core::Memory::Instance();
|
||||
Core::MemoryProt protection_flags = static_cast<Core::MemoryProt>(prot);
|
||||
return memory_manager->Protect(std::bit_cast<VAddr>(addr), size, protection_flags);
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI sceKernelMTypeProtect(const void* addr, size_t size, int mtype, int prot) {
|
||||
Core::MemoryManager* memory_manager = Core::Memory::Instance();
|
||||
Core::MemoryProt protection_flags = static_cast<Core::MemoryProt>(prot);
|
||||
return memory_manager->MTypeProtect(std::bit_cast<VAddr>(addr), size,
|
||||
static_cast<Core::VMAType>(mtype), protection_flags);
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI sceKernelDirectMemoryQuery(u64 offset, int flags, OrbisQueryInfo* query_info,
|
||||
size_t infoSize) {
|
||||
LOG_WARNING(Kernel_Vmm, "called offset = {:#x}, flags = {:#x}", offset, flags);
|
||||
|
@ -258,7 +272,7 @@ s32 PS4_SYSV_ABI sceKernelBatchMap2(OrbisKernelBatchMapEntry* entries, int numEn
|
|||
int* numEntriesOut, int flags) {
|
||||
int result = ORBIS_OK;
|
||||
int processed = 0;
|
||||
for (int i = 0; i < numEntries; i++, processed++) {
|
||||
for (int i = 0; i < numEntries; i++) {
|
||||
if (entries == nullptr || entries[i].length == 0 || entries[i].operation > 4) {
|
||||
result = ORBIS_KERNEL_ERROR_EINVAL;
|
||||
break; // break and assign a value to numEntriesOut.
|
||||
|
@ -278,10 +292,41 @@ s32 PS4_SYSV_ABI sceKernelBatchMap2(OrbisKernelBatchMapEntry* entries, int numEn
|
|||
}
|
||||
case MemoryOpTypes::ORBIS_KERNEL_MAP_OP_UNMAP: {
|
||||
result = sceKernelMunmap(entries[i].start, entries[i].length);
|
||||
LOG_INFO(Kernel_Vmm, "entry = {}, operation = {}, len = {:#x}, result = {}", i,
|
||||
entries[i].operation, entries[i].length, result);
|
||||
LOG_INFO(Kernel_Vmm, "BatchMap: entry = {}, operation = {}, len = {:#x}, result = {}",
|
||||
i, entries[i].operation, entries[i].length, result);
|
||||
|
||||
if (result == 0)
|
||||
processed++;
|
||||
}
|
||||
case MemoryOpTypes::ORBIS_KERNEL_MAP_OP_PROTECT: {
|
||||
result = sceKernelMProtect(entries[i].start, entries[i].length, entries[i].protection);
|
||||
LOG_INFO(Kernel_Vmm, "BatchMap: entry = {}, operation = {}, len = {:#x}, result = {}",
|
||||
i, entries[i].operation, entries[i].length, result);
|
||||
if (result != ORBIS_OK) {
|
||||
LOG_ERROR(Kernel_Vmm, "BatchMap: MProtect failed on entry {} with result {}", i,
|
||||
result);
|
||||
}
|
||||
if (result == 0) {
|
||||
processed++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case MemoryOpTypes::ORBIS_KERNEL_MAP_OP_TYPE_PROTECT: {
|
||||
result = sceKernelMTypeProtect(entries[i].start, entries[i].length, entries[i].type,
|
||||
entries[i].protection);
|
||||
LOG_INFO(Kernel_Vmm, "BatchMap: entry = {}, operation = {}, len = {:#x}, result = {}",
|
||||
i, entries[i].operation, entries[i].length, result);
|
||||
if (result != ORBIS_OK) {
|
||||
LOG_ERROR(Kernel_Vmm, "BatchMap: MProtect failed on entry {} with result {}", i,
|
||||
result);
|
||||
}
|
||||
if (result == 0) {
|
||||
processed++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case MemoryOpTypes::ORBIS_KERNEL_MAP_OP_MAP_FLEXIBLE: {
|
||||
result = sceKernelMapNamedFlexibleMemory(&entries[i].start, entries[i].length,
|
||||
entries[i].protection, flags, "");
|
||||
|
@ -291,14 +336,7 @@ s32 PS4_SYSV_ABI sceKernelBatchMap2(OrbisKernelBatchMapEntry* entries, int numEn
|
|||
i, entries[i].operation, entries[i].length, (u8)entries[i].type, result);
|
||||
break;
|
||||
}
|
||||
case MemoryOpTypes::ORBIS_KERNEL_MAP_OP_TYPE_PROTECT: {
|
||||
// By now, ignore protection and log it instead
|
||||
LOG_WARNING(Kernel_Vmm,
|
||||
"entry = {}, operation = {}, len = {:#x}, type = {} "
|
||||
"is UNSUPPORTED and skipped",
|
||||
i, entries[i].operation, entries[i].length, (u8)entries[i].type);
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
@ -308,6 +346,8 @@ s32 PS4_SYSV_ABI sceKernelBatchMap2(OrbisKernelBatchMapEntry* entries, int numEn
|
|||
break;
|
||||
}
|
||||
}
|
||||
LOG_INFO(Kernel_Vmm, "sceKernelBatchMap2 finished: processed = {}, result = {}", processed,
|
||||
result);
|
||||
if (numEntriesOut != NULL) { // can be zero. do not return an error code.
|
||||
*numEntriesOut = processed;
|
||||
}
|
||||
|
|
|
@ -95,6 +95,10 @@ s32 PS4_SYSV_ABI sceKernelMapFlexibleMemory(void** addr_in_out, std::size_t len,
|
|||
int flags);
|
||||
int PS4_SYSV_ABI sceKernelQueryMemoryProtection(void* addr, void** start, void** end, u32* prot);
|
||||
|
||||
int PS4_SYSV_ABI sceKernelMProtect(const void* addr, size_t size, int prot);
|
||||
|
||||
int PS4_SYSV_ABI sceKernelMTypeProtect(const void* addr, size_t size, int mtype, int prot);
|
||||
|
||||
int PS4_SYSV_ABI sceKernelDirectMemoryQuery(u64 offset, int flags, OrbisQueryInfo* query_info,
|
||||
size_t infoSize);
|
||||
s32 PS4_SYSV_ABI sceKernelAvailableFlexibleMemorySize(size_t* sizeOut);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue