threading working ,fixed a big in sceKernelMapDirectMemory
This commit is contained in:
parent
3e1386666b
commit
e5f2f91a80
|
@ -5,6 +5,7 @@ namespace HLE::Kernel::Objects {
|
||||||
static u64 AlignUp(u64 pos, u64 align) { return (align != 0 ? (pos + (align - 1)) & ~(align - 1) : pos); }
|
static u64 AlignUp(u64 pos, u64 align) { return (align != 0 ? (pos + (align - 1)) & ~(align - 1) : pos); }
|
||||||
|
|
||||||
bool PhysicalMemory::Alloc(u64 searchStart, u64 searchEnd, u64 len, u64 alignment, u64* physAddrOut, int memoryType) {
|
bool PhysicalMemory::Alloc(u64 searchStart, u64 searchEnd, u64 len, u64 alignment, u64* physAddrOut, int memoryType) {
|
||||||
|
Lib::LockMutexGuard lock(m_mutex);
|
||||||
u64 find_free_pos = 0;
|
u64 find_free_pos = 0;
|
||||||
|
|
||||||
// iterate through allocated blocked and find the next free position
|
// iterate through allocated blocked and find the next free position
|
||||||
|
@ -39,6 +40,7 @@ bool PhysicalMemory::Alloc(u64 searchStart, u64 searchEnd, u64 len, u64 alignmen
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool PhysicalMemory::Map(u64 virtual_addr, u64 phys_addr, u64 len, int prot, VirtualMemory::MemoryMode cpu_mode, GPU::MemoryMode gpu_mode) {
|
bool PhysicalMemory::Map(u64 virtual_addr, u64 phys_addr, u64 len, int prot, VirtualMemory::MemoryMode cpu_mode, GPU::MemoryMode gpu_mode) {
|
||||||
|
Lib::LockMutexGuard lock(m_mutex);
|
||||||
for (auto& b : m_allocatedBlocks) {
|
for (auto& b : m_allocatedBlocks) {
|
||||||
if (phys_addr >= b.start_addr && phys_addr < b.start_addr + b.size) {
|
if (phys_addr >= b.start_addr && phys_addr < b.start_addr + b.size) {
|
||||||
if (b.map_virtual_addr != 0 || b.map_size != 0) {
|
if (b.map_virtual_addr != 0 || b.map_size != 0) {
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <Core/virtual_memory.h>
|
#include <Core/virtual_memory.h>
|
||||||
#include <Core/PS4/GPU/gpu_memory.h>
|
#include <Core/PS4/GPU/gpu_memory.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "Lib/Threads.h"
|
||||||
|
|
||||||
namespace HLE::Kernel::Objects {
|
namespace HLE::Kernel::Objects {
|
||||||
|
|
||||||
|
@ -27,6 +28,7 @@ class PhysicalMemory {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<AllocatedBlock> m_allocatedBlocks;
|
std::vector<AllocatedBlock> m_allocatedBlocks;
|
||||||
|
Lib::Mutex m_mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace HLE::Kernel::Objects
|
} // namespace HLE::Kernel::Objects
|
|
@ -67,22 +67,20 @@ int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u
|
||||||
|
|
||||||
int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int flags, s64 directMemoryStart, u64 alignment) {
|
int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int flags, s64 directMemoryStart, u64 alignment) {
|
||||||
PRINT_FUNCTION_NAME();
|
PRINT_FUNCTION_NAME();
|
||||||
if (len == 0 || !is16KBAligned(len))
|
if (len == 0 || !is16KBAligned(len)) {
|
||||||
{
|
|
||||||
LOG_TRACE_IF(log_file_memory, "sceKernelMapDirectMemory returned SCE_KERNEL_ERROR_EINVAL len invalid\n");
|
LOG_TRACE_IF(log_file_memory, "sceKernelMapDirectMemory returned SCE_KERNEL_ERROR_EINVAL len invalid\n");
|
||||||
return SCE_KERNEL_ERROR_EINVAL;
|
return SCE_KERNEL_ERROR_EINVAL;
|
||||||
}
|
}
|
||||||
if (!is16KBAligned(directMemoryStart))
|
if (!is16KBAligned(directMemoryStart)) {
|
||||||
{
|
|
||||||
LOG_TRACE_IF(log_file_memory, "sceKernelMapDirectMemory returned SCE_KERNEL_ERROR_EINVAL directMemoryStart invalid\n");
|
LOG_TRACE_IF(log_file_memory, "sceKernelMapDirectMemory returned SCE_KERNEL_ERROR_EINVAL directMemoryStart invalid\n");
|
||||||
return SCE_KERNEL_ERROR_EINVAL;
|
return SCE_KERNEL_ERROR_EINVAL;
|
||||||
}
|
}
|
||||||
if (alignment != 0 || (!isPowerOfTwo(alignment) && !is16KBAligned(alignment)))
|
if (alignment != 0) {
|
||||||
{
|
if ((!isPowerOfTwo(alignment) && !is16KBAligned(alignment))){
|
||||||
LOG_TRACE_IF(log_file_memory, "sceKernelMapDirectMemory returned SCE_KERNEL_ERROR_EINVAL alignment invalid\n");
|
LOG_TRACE_IF(log_file_memory, "sceKernelMapDirectMemory returned SCE_KERNEL_ERROR_EINVAL alignment invalid\n");
|
||||||
return SCE_KERNEL_ERROR_EINVAL;
|
return SCE_KERNEL_ERROR_EINVAL;
|
||||||
}
|
}
|
||||||
auto* physical_memory = Singleton<HLE::Kernel::Objects::PhysicalMemory>::Instance();
|
}
|
||||||
|
|
||||||
LOG_INFO_IF(log_file_memory, "len = {}\n", log_hex_full(len));
|
LOG_INFO_IF(log_file_memory, "len = {}\n", log_hex_full(len));
|
||||||
LOG_INFO_IF(log_file_memory, "prot = {}\n", log_hex_full(prot));
|
LOG_INFO_IF(log_file_memory, "prot = {}\n", log_hex_full(prot));
|
||||||
|
@ -94,7 +92,7 @@ int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int fl
|
||||||
GPU::MemoryMode gpu_mode = GPU::MemoryMode::NoAccess;
|
GPU::MemoryMode gpu_mode = GPU::MemoryMode::NoAccess;
|
||||||
|
|
||||||
switch (prot) {
|
switch (prot) {
|
||||||
case 0x33://SCE_KERNEL_PROT_CPU_READ|SCE_KERNEL_PROT_CPU_WRITE|SCE_KERNEL_PROT_GPU_READ|SCE_KERNEL_PROT_GPU_ALL
|
case 0x33: // SCE_KERNEL_PROT_CPU_READ|SCE_KERNEL_PROT_CPU_WRITE|SCE_KERNEL_PROT_GPU_READ|SCE_KERNEL_PROT_GPU_ALL
|
||||||
cpu_mode = VirtualMemory::MemoryMode::ReadWrite;
|
cpu_mode = VirtualMemory::MemoryMode::ReadWrite;
|
||||||
gpu_mode = GPU::MemoryMode::ReadWrite;
|
gpu_mode = GPU::MemoryMode::ReadWrite;
|
||||||
break;
|
break;
|
||||||
|
@ -116,6 +114,7 @@ int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int fl
|
||||||
return SCE_KERNEL_ERROR_ENOMEM;
|
return SCE_KERNEL_ERROR_ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto* physical_memory = Singleton<HLE::Kernel::Objects::PhysicalMemory>::Instance();
|
||||||
if (!physical_memory->Map(out_addr, directMemoryStart, len, prot, cpu_mode, gpu_mode)) {
|
if (!physical_memory->Map(out_addr, directMemoryStart, len, prot, cpu_mode, gpu_mode)) {
|
||||||
BREAKPOINT();
|
BREAKPOINT();
|
||||||
}
|
}
|
||||||
|
@ -123,7 +122,6 @@ int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int fl
|
||||||
if (gpu_mode != GPU::MemoryMode::NoAccess) {
|
if (gpu_mode != GPU::MemoryMode::NoAccess) {
|
||||||
GPU::MemorySetAllocArea(out_addr, len);
|
GPU::MemorySetAllocArea(out_addr, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SCE_OK;
|
return SCE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,6 +70,7 @@ static std::string encodeId(u64 nVal)
|
||||||
}
|
}
|
||||||
Module* Linker::LoadModule(const std::string& elf_name)
|
Module* Linker::LoadModule(const std::string& elf_name)
|
||||||
{
|
{
|
||||||
|
Lib::LockMutexGuard lock(m_mutex);
|
||||||
auto* m = new Module;
|
auto* m = new Module;
|
||||||
m->linker = this;
|
m->linker = this;
|
||||||
m->elf = new Elf;
|
m->elf = new Elf;
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "Loader/Elf.h"
|
#include "Loader/Elf.h"
|
||||||
#include "Loader/SymbolsResolver.h"
|
#include "Loader/SymbolsResolver.h"
|
||||||
|
#include "Lib/Threads.h"
|
||||||
|
|
||||||
struct DynamicModuleInfo;
|
struct DynamicModuleInfo;
|
||||||
class Linker;
|
class Linker;
|
||||||
|
@ -129,4 +130,5 @@ public:
|
||||||
|
|
||||||
std::vector<Module*> m_modules;
|
std::vector<Module*> m_modules;
|
||||||
SymbolsResolver* m_HLEsymbols = nullptr;
|
SymbolsResolver* m_HLEsymbols = nullptr;
|
||||||
|
Lib::Mutex m_mutex;
|
||||||
};
|
};
|
|
@ -121,5 +121,11 @@ class LockMutexGuard {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Mutex& m_mutex;
|
Mutex& m_mutex;
|
||||||
|
|
||||||
|
public:
|
||||||
|
LockMutexGuard(const LockMutexGuard&) = delete;
|
||||||
|
LockMutexGuard& operator=(const LockMutexGuard&) = delete;
|
||||||
|
LockMutexGuard(LockMutexGuard&&) noexcept = delete;
|
||||||
|
LockMutexGuard& operator=(LockMutexGuard&&) noexcept = delete;
|
||||||
};
|
};
|
||||||
} // namespace Lib
|
} // namespace Lib
|
Loading…
Reference in New Issue