Drop Handle <-> EmuHandle conversion step
This commit is contained in:
parent
f818e43fc7
commit
16c449ddc7
|
@ -145,7 +145,7 @@ XBSYSAPI EXPORTNUM(187) xbox::ntstatus_xt NTAPI xbox::NtClose
|
|||
if (EmuHandle::IsEmuHandle(Handle))
|
||||
{
|
||||
// delete 'special' handles
|
||||
EmuHandle *iEmuHandle = HandleToEmuHandle(Handle);
|
||||
auto iEmuHandle = (EmuHandle*)Handle;
|
||||
ret = iEmuHandle->NtClose();
|
||||
|
||||
LOG_UNIMPLEMENTED(); // TODO : Base this on the Ob* functions
|
||||
|
@ -683,7 +683,7 @@ XBSYSAPI EXPORTNUM(197) xbox::ntstatus_xt NTAPI xbox::NtDuplicateObject
|
|||
NTSTATUS ret = xbox::status_success;
|
||||
|
||||
if (EmuHandle::IsEmuHandle(SourceHandle)) {
|
||||
EmuHandle* iEmuHandle = HandleToEmuHandle(SourceHandle);
|
||||
auto iEmuHandle = (EmuHandle*)SourceHandle;
|
||||
ret = iEmuHandle->NtDuplicateObject(TargetHandle, Options);
|
||||
/*
|
||||
PVOID Object;
|
||||
|
@ -1377,7 +1377,7 @@ XBSYSAPI EXPORTNUM(215) xbox::ntstatus_xt NTAPI xbox::NtQuerySymbolicLinkObject
|
|||
// Check that we actually got an EmuHandle :
|
||||
ret = STATUS_INVALID_HANDLE;
|
||||
|
||||
EmuHandle* iEmuHandle = HandleToEmuHandle(LinkHandle);
|
||||
auto iEmuHandle = (EmuHandle*)LinkHandle;
|
||||
// Retrieve the NtSymbolicLinkObject and populate the output arguments :
|
||||
ret = xbox::status_success;
|
||||
symbolicLinkObject = (EmuNtSymbolicLinkObject*)iEmuHandle->NtObject;
|
||||
|
|
|
@ -255,7 +255,7 @@ EmuHandle::EmuHandle(EmuNtObject* ntObject)
|
|||
NtObject = ntObject;
|
||||
}
|
||||
|
||||
std::unordered_map<HANDLE, EmuHandle*> EmuHandle::EmuHandleLookup = {};
|
||||
std::unordered_set<EmuHandle*> EmuHandle::EmuHandleLookup = {};
|
||||
std::shared_mutex EmuHandle::EmuHandleLookupLock = {};
|
||||
|
||||
EmuHandle* EmuHandle::CreateEmuHandle(EmuNtObject* ntObject) {
|
||||
|
@ -264,7 +264,7 @@ EmuHandle* EmuHandle::CreateEmuHandle(EmuNtObject* ntObject) {
|
|||
// Register EmuHandle
|
||||
{
|
||||
std::unique_lock scopedLock(EmuHandleLookupLock);
|
||||
EmuHandleLookup.emplace(EmuHandleToHandle(emuHandle), emuHandle);
|
||||
EmuHandleLookup.insert(emuHandle);
|
||||
}
|
||||
|
||||
return emuHandle;
|
||||
|
@ -277,7 +277,7 @@ NTSTATUS EmuHandle::NtClose()
|
|||
// Unregister the handle
|
||||
if (status == STATUS_SUCCESS) {
|
||||
std::unique_lock scopedLock(EmuHandleLookupLock);
|
||||
EmuHandleLookup.erase(EmuHandleToHandle(this));
|
||||
EmuHandleLookup.erase(this);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
@ -286,22 +286,10 @@ NTSTATUS EmuHandle::NtClose()
|
|||
bool EmuHandle::IsEmuHandle(HANDLE Handle)
|
||||
{
|
||||
std::shared_lock scopedLock(EmuHandleLookupLock);
|
||||
auto iter = EmuHandleLookup.find(Handle);
|
||||
auto iter = EmuHandleLookup.find((EmuHandle*) Handle);
|
||||
return !(iter == EmuHandleLookup.end());
|
||||
}
|
||||
|
||||
EmuHandle* HandleToEmuHandle(HANDLE Handle)
|
||||
{
|
||||
return (EmuHandle*)((uint32_t)Handle & 0x7FFFFFFF);
|
||||
}
|
||||
|
||||
HANDLE EmuHandleToHandle(EmuHandle* emuHandle)
|
||||
{
|
||||
// Set the high bit
|
||||
// Avoids collisions with real Xbox handles..?
|
||||
return (HANDLE)((uint32_t)emuHandle | 0x80000000);
|
||||
}
|
||||
|
||||
NTSTATUS EmuHandle::NtDuplicateObject(PHANDLE TargetHandle, DWORD Options)
|
||||
{
|
||||
*TargetHandle = NtObject->NtDuplicateObject(Options)->NewHandle();
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <shared_mutex>
|
||||
|
||||
// ******************************************************************
|
||||
|
@ -175,7 +175,7 @@ private:
|
|||
// We used to rely on the high bit to differentiatean EmuHandles
|
||||
// But titles may attempt to operate on invalid handles with the high bit set
|
||||
// Test case: Amped sets a handle value to 0xFDFDFDFD (coincidentally a VS debugger guard value)
|
||||
static std::unordered_map<HANDLE, EmuHandle*> EmuHandleLookup;
|
||||
static std::unordered_set<EmuHandle*> EmuHandleLookup;
|
||||
static std::shared_mutex EmuHandleLookupLock;
|
||||
};
|
||||
|
||||
|
@ -217,12 +217,6 @@ struct XboxDevice {
|
|||
HANDLE HostRootHandle;
|
||||
};
|
||||
|
||||
// ******************************************************************
|
||||
// * is Handle a 'special' emulated handle?
|
||||
// ******************************************************************
|
||||
EmuHandle* HandleToEmuHandle(HANDLE Handle);
|
||||
HANDLE EmuHandleToHandle(EmuHandle* emuHandle);
|
||||
|
||||
CHAR* NtStatusToString(IN NTSTATUS Status);
|
||||
|
||||
int CxbxRegisterDeviceHostPath(std::string XboxFullPath, std::string HostDevicePath, bool IsFile = false);
|
||||
|
|
Loading…
Reference in New Issue