Misc implementations and fixes. (#250)

* Implement `sceKernelFtruncate` and `sceKernelUnlink`.

* Remove unused variable.

* Implement `sceKernelReserveVirtualRange`, misc fixes

* Fix `sceKernelReserveVirtualRange`.

* Add TODO on reserve

* Replace comment with assert.

* Add missing copyright header

* Add `UNREACHABLE` for `IOFile::Unlink`.

* Move NT API initialization out of the header

* Fix bug where files were always mapped as read only.

* `clang-format`
This commit is contained in:
Daniel R 2024-07-11 14:35:58 +02:00 committed by GitHub
parent 989f88837d
commit 914aa10875
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 331 additions and 19 deletions

View file

@ -6,6 +6,7 @@
#include "common/error.h"
#include "core/address_space.h"
#include "core/libraries/kernel/memory_management.h"
#include "core/memory.h"
#ifdef _WIN32
#include <windows.h>
@ -18,6 +19,18 @@ namespace Core {
static constexpr size_t BackingSize = SCE_KERNEL_MAIN_DMEM_SIZE;
[[nodiscard]] constexpr u64 ToWindowsProt(Core::MemoryProt prot) {
switch (prot) {
case Core::MemoryProt::NoAccess:
default:
return PAGE_NOACCESS;
case Core::MemoryProt::CpuRead:
return PAGE_READONLY;
case Core::MemoryProt::CpuReadWrite:
return PAGE_READWRITE;
}
}
#ifdef _WIN32
struct AddressSpace::Impl {
Impl() : process{GetCurrentProcess()} {
@ -325,8 +338,10 @@ void* AddressSpace::Map(VAddr virtual_addr, size_t size, u64 alignment, PAddr ph
is_exec ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE);
}
void* AddressSpace::MapFile(VAddr virtual_addr, size_t size, size_t offset, uintptr_t fd) {
return impl->Map(virtual_addr, offset, size, fd ? PAGE_READONLY : PAGE_READWRITE, fd);
void* AddressSpace::MapFile(VAddr virtual_addr, size_t size, size_t offset, u32 prot,
uintptr_t fd) {
return impl->Map(virtual_addr, offset, size,
ToWindowsProt(std::bit_cast<Core::MemoryProt>(prot)), fd);
}
void AddressSpace::Unmap(VAddr virtual_addr, size_t size, bool has_backing) {