mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-07-26 20:15:03 +00:00
Move NT API initialization out of the header
This commit is contained in:
parent
bc8e95dd6d
commit
c417a833f6
@ -271,6 +271,7 @@ set(COMMON src/common/logging/backend.cpp
|
||||
src/common/uint128.h
|
||||
src/common/version.h
|
||||
src/common/ntapi.h
|
||||
src/common/ntapi.cpp
|
||||
)
|
||||
|
||||
set(CORE src/core/aerolib/stubs.cpp
|
||||
|
20
src/common/ntapi.cpp
Normal file
20
src/common/ntapi.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "ntapi.h"
|
||||
|
||||
NtDelayExecution_t NtDelayExecution = nullptr;
|
||||
NtSetInformationFile_t NtSetInformationFile = nullptr;
|
||||
|
||||
namespace Common::NtApi {
|
||||
|
||||
void Initialize() {
|
||||
HMODULE nt_handle = GetModuleHandleA("ntdll.dll");
|
||||
|
||||
// http://stackoverflow.com/a/31411628/4725495
|
||||
NtDelayExecution = (NtDelayExecution_t)GetProcAddress(nt_handle, "NtDelayExecution");
|
||||
NtSetInformationFile =
|
||||
(NtSetInformationFile_t)GetProcAddress(nt_handle, "NtSetInformationFile");
|
||||
}
|
||||
|
||||
} // namespace Common::NtApi
|
@ -5,9 +5,8 @@
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include "common/types.h"
|
||||
|
||||
#include <windows.h>
|
||||
#include "common/types.h"
|
||||
|
||||
typedef enum _FILE_INFORMATION_CLASS {
|
||||
FileDirectoryInformation = 1,
|
||||
@ -109,15 +108,17 @@ typedef struct _FILE_DISPOSITION_INFORMATION {
|
||||
BOOLEAN DeleteFile;
|
||||
} FILE_DISPOSITION_INFORMATION, *PFILE_DISPOSITION_INFORMATION;
|
||||
|
||||
// http://stackoverflow.com/a/31411628/4725495
|
||||
static u32(__stdcall* NtDelayExecution)(BOOL Alertable, PLARGE_INTEGER DelayInterval) =
|
||||
(u32(__stdcall*)(BOOL, PLARGE_INTEGER))GetProcAddress(GetModuleHandleA("ntdll.dll"),
|
||||
"NtDelayExecution");
|
||||
typedef u32(__stdcall* NtDelayExecution_t)(BOOL Alertable, PLARGE_INTEGER DelayInterval);
|
||||
|
||||
static u32(__stdcall* NtSetInformationFile)(HANDLE FileHandle, PIO_STATUS_BLOCK IoStatusBlock,
|
||||
typedef u32(__stdcall* NtSetInformationFile_t)(HANDLE FileHandle, PIO_STATUS_BLOCK IoStatusBlock,
|
||||
PVOID FileInformation, ULONG Length,
|
||||
FILE_INFORMATION_CLASS FileInformationClass) =
|
||||
(u32(__stdcall*)(HANDLE, PIO_STATUS_BLOCK, PVOID, ULONG, FILE_INFORMATION_CLASS))
|
||||
GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtSetInformationFile");
|
||||
FILE_INFORMATION_CLASS FileInformationClass);
|
||||
|
||||
extern NtDelayExecution_t NtDelayExecution;
|
||||
extern NtSetInformationFile_t NtSetInformationFile;
|
||||
|
||||
namespace Common::NtApi {
|
||||
void Initialize();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "common/config.h"
|
||||
#include "common/debug.h"
|
||||
#include "common/logging/backend.h"
|
||||
#include "common/ntapi.h"
|
||||
#include "common/path_util.h"
|
||||
#include "common/singleton.h"
|
||||
#include "common/version.h"
|
||||
@ -38,6 +39,9 @@ Emulator::Emulator()
|
||||
const auto config_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir);
|
||||
Config::load(config_dir / "config.toml");
|
||||
|
||||
// Initialize NT API functions
|
||||
Common::NtApi::Initialize();
|
||||
|
||||
// Start logger.
|
||||
Common::Log::Initialize();
|
||||
Common::Log::Start();
|
||||
|
Loading…
Reference in New Issue
Block a user