mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-06-02 16:53:17 +00:00
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:
parent
989f88837d
commit
914aa10875
15 changed files with 331 additions and 19 deletions
|
@ -11,6 +11,8 @@
|
|||
#include "common/path_util.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "common/ntapi.h"
|
||||
|
||||
#include <io.h>
|
||||
#include <share.h>
|
||||
#include <windows.h>
|
||||
|
@ -221,15 +223,46 @@ void IOFile::Close() {
|
|||
#endif
|
||||
}
|
||||
|
||||
void IOFile::Unlink() {
|
||||
if (!IsOpen()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Mark the file for deletion
|
||||
// TODO: Also remove the file path?
|
||||
#if _WIN64
|
||||
FILE_DISPOSITION_INFORMATION disposition;
|
||||
IO_STATUS_BLOCK iosb;
|
||||
|
||||
const int fd = fileno(file);
|
||||
HANDLE hfile = reinterpret_cast<HANDLE>(_get_osfhandle(fd));
|
||||
|
||||
disposition.DeleteFile = TRUE;
|
||||
NtSetInformationFile(hfile, &iosb, &disposition, sizeof(disposition),
|
||||
FileDispositionInformation);
|
||||
#else
|
||||
UNREACHABLE_MSG("Missing Linux implementation");
|
||||
#endif
|
||||
}
|
||||
|
||||
uintptr_t IOFile::GetFileMapping() {
|
||||
if (file_mapping) {
|
||||
return file_mapping;
|
||||
}
|
||||
#ifdef _WIN64
|
||||
const int fd = fileno(file);
|
||||
|
||||
HANDLE hfile = reinterpret_cast<HANDLE>(_get_osfhandle(fd));
|
||||
HANDLE mapping =
|
||||
CreateFileMapping2(hfile, NULL, FILE_MAP_READ, PAGE_READONLY, SEC_COMMIT, 0, NULL, NULL, 0);
|
||||
HANDLE mapping = nullptr;
|
||||
|
||||
if (file_access_mode == FileAccessMode::ReadWrite) {
|
||||
mapping = CreateFileMapping2(hfile, NULL, FILE_MAP_WRITE, PAGE_READWRITE, SEC_COMMIT, 0,
|
||||
NULL, NULL, 0);
|
||||
} else {
|
||||
mapping = CreateFileMapping2(hfile, NULL, FILE_MAP_READ, PAGE_READONLY, SEC_COMMIT, 0, NULL,
|
||||
NULL, 0);
|
||||
}
|
||||
|
||||
file_mapping = std::bit_cast<uintptr_t>(mapping);
|
||||
ASSERT_MSG(file_mapping, "{}", Common::GetLastErrorMsg());
|
||||
return file_mapping;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue