[*] Updated AuProcess mapping API to use file handles

This commit is contained in:
Reece Wilson 2023-07-29 09:02:55 +01:00
parent 4ad2a54ccf
commit 9f78555693
5 changed files with 58 additions and 24 deletions

View File

@ -39,14 +39,14 @@ namespace Aurora::Process
Aurora::IO::FS::EFileOpenMode mode,
Aurora::IO::FS::EFileAdvisoryLockLevel processLockLevel) = 0;
virtual AuSPtr<IProcessSectionMapView> MapFileByObject(const AuSPtr<Aurora::IO::FS::IFileStream> &pStream,
virtual AuSPtr<IProcessSectionMapView> MapFileByObject(const AuSPtr<IO::IIOHandle> &pIOHandle,
AuUInt64 uOffset,
AuUInt uLength,
Aurora::IO::FS::EFileOpenMode mode,
Aurora::IO::FS::EFileAdvisoryLockLevel processLockLevel) = 0;
virtual AuSPtr<IProcessSectionMapView> MapFileByObjectEx(AuUInt uViewOffset,
const AuSPtr<Aurora::IO::FS::IFileStream> &pStream,
const AuSPtr<IO::IIOHandle> &pIOHandle,
AuUInt64 uOffset,
AuUInt uLength,
Aurora::IO::FS::EFileOpenMode mode,

View File

@ -40,11 +40,29 @@ namespace Aurora::Process
AuFS::EFileOpenMode mode,
AuFS::EFileAdvisoryLockLevel sectionLock)
{
auto file = AuFS::OpenShared(str, mode, AuFS::EFileAdvisoryLockLevel::eNoSafety);
return file ? this->MapFileByObject(file, uOffset, uLength, mode, sectionLock) : AuSPtr<IProcessSectionMapView> {};
auto pHandle = AuIO::IOHandleShared();
if (!pHandle)
{
SysPushErrorMemory();
return nullptr;
}
AuIO::IIOHandle::HandleCreate createhandle(str);
createhandle.eAdvisoryLevel = AuFS::EFileAdvisoryLockLevel::eNoSafety;
createhandle.eMode = mode;
createhandle.bFailIfNonEmptyFile = false;
createhandle.bDirectIOMode = false;
createhandle.bAsyncHandle = false;
if (!pHandle->InitFromPath(createhandle))
{
return nullptr;
}
return this->MapFileByObject(pHandle, uOffset, uLength, mode, sectionLock);
}
AuSPtr<IProcessSectionMapView> ProcessSectionView::MapFileByObject(const AuSPtr<AuFS::IFileStream> &pStream,
AuSPtr<IProcessSectionMapView> ProcessSectionView::MapFileByObject(const AuSPtr<IO::IIOHandle> &pIOHandle,
AuUInt64 uOffset,
AuUInt uLength,
AuFS::EFileOpenMode mode,
@ -53,7 +71,7 @@ namespace Aurora::Process
HANDLE hFileMap;
ULONG desiredAccess {}, pageAttributes {};
if (!pStream)
if (!pIOHandle)
{
SysPushErrorArg();
return {};
@ -65,7 +83,6 @@ namespace Aurora::Process
return {};
}
auto pFileStream = AuStaticCast<AuFS::WinFileStream>(pStream);
if (processLockLevel != AuFS::EFileAdvisoryLockLevel::eNoSafety)
{
DWORD dwFlags {};
@ -81,7 +98,7 @@ namespace Aurora::Process
overlapped.Offset = AuBitsToLower(uOffset);
overlapped.OffsetHigh = AuBitsToHigher(uOffset);
if (!::LockFileEx(pFileStream->GetHandle(),
if (!::LockFileEx((HANDLE)pIOHandle->GetOSHandle(),
dwFlags,
0,
AuBitsToLower(uLength),
@ -113,7 +130,7 @@ namespace Aurora::Process
return {};
};
hFileMap = ::CreateFileMappingA(pFileStream->GetHandle(),
hFileMap = ::CreateFileMappingA((HANDLE)pIOHandle->GetOSHandle(),
nullptr,
pageAttributes,
#if defined(AURORA_IS_64BIT)
@ -369,7 +386,7 @@ namespace Aurora::Process
}
AuSPtr<IProcessSectionMapView> ProcessSectionView::MapFileByObjectEx(AuUInt viewOffset,
const AuSPtr<Aurora::IO::FS::IFileStream> &pStream,
const AuSPtr<IO::IIOHandle> &pIOHandle,
AuUInt64 uOffset,
AuUInt uLength,
Aurora::IO::FS::EFileOpenMode mode,
@ -378,7 +395,7 @@ namespace Aurora::Process
SysAssert(this->bPanicOnEx, "Windows 7/8 called a Windows 10 RS4 memory management routine. "
"Applications requiring explicit and pre-reserved memory maps cannot run on unmodified unsupported versions of Windows."
"We lied about reserving a region of bytes with a ProcessSectionView. Unable to gurantee uOffset.");
return this->MapFileByObject(pStream, uOffset, uLength, mode, processLockLevel);
return this->MapFileByObject(pIOHandle, uOffset, uLength, mode, processLockLevel);
}
AuSPtr<IProcessSectionMapView> ProcessSectionView::MapIPCMemoryEx(AuUInt viewOffset,

View File

@ -29,7 +29,7 @@ namespace Aurora::Process
AuFS::EFileOpenMode mode,
AuFS::EFileAdvisoryLockLevel sectionLock) override;
AuSPtr<IProcessSectionMapView> MapFileByObject(const AuSPtr<Aurora::IO::FS::IFileStream> &pStream,
AuSPtr<IProcessSectionMapView> MapFileByObject(const AuSPtr<IO::IIOHandle> &pIOHandle,
AuUInt64 uOffset,
AuUInt uLength,
Aurora::IO::FS::EFileOpenMode mode,
@ -52,7 +52,7 @@ namespace Aurora::Process
Aurora::IO::FS::EFileAdvisoryLockLevel processLockLevel) override;
AuSPtr<IProcessSectionMapView> MapFileByObjectEx(AuUInt viewOffset,
const AuSPtr<Aurora::IO::FS::IFileStream> &pStream,
const AuSPtr<IO::IIOHandle> &pIOHandle,
AuUInt64 uOffset,
AuUInt uLength,
Aurora::IO::FS::EFileOpenMode mode,

View File

@ -186,13 +186,13 @@ namespace Aurora::Process
return this->MapFileByPathEx(-1, str, uOffset, uLength, mode, sectionLock);
}
AuSPtr<IProcessSectionMapView> ProcessSectionViewReserved::MapFileByObject(const AuSPtr<AuFS::IFileStream> &pStream,
AuSPtr<IProcessSectionMapView> ProcessSectionViewReserved::MapFileByObject(const AuSPtr<IO::IIOHandle> &pIOHandle,
AuUInt64 uOffset,
AuUInt uLength,
AuFS::EFileOpenMode mode,
AuFS::EFileAdvisoryLockLevel processLockLevel)
{
return this->MapFileByObjectEx(-1, pStream, uOffset, uLength, mode, processLockLevel);
return this->MapFileByObjectEx(-1, pIOHandle, uOffset, uLength, mode, processLockLevel);
}
AuSPtr<IProcessSectionMapView> ProcessSectionViewReserved::MapIPCMemory(const AuString &handleString,
@ -305,12 +305,30 @@ namespace Aurora::Process
Aurora::IO::FS::EFileOpenMode mode,
Aurora::IO::FS::EFileAdvisoryLockLevel sectionLock)
{
auto file = AuFS::OpenShared(str, mode, AuFS::EFileAdvisoryLockLevel::eNoSafety);
return file ? this->MapFileByObjectEx(viewOffset, file, uOffset, uLength, mode, sectionLock) : AuSPtr<IProcessSectionMapView> {};
auto pHandle = AuIO::IOHandleShared();
if (!pHandle)
{
SysPushErrorMemory();
return nullptr;
}
AuIO::IIOHandle::HandleCreate createhandle(str);
createhandle.eAdvisoryLevel = AuFS::EFileAdvisoryLockLevel::eNoSafety;
createhandle.eMode = mode;
createhandle.bFailIfNonEmptyFile = false;
createhandle.bDirectIOMode = false;
createhandle.bAsyncHandle = false;
if (!pHandle->InitFromPath(createhandle))
{
return nullptr;
}
return this->MapFileByObjectEx(viewOffset, pHandle, uOffset, uLength, mode, sectionLock);
}
AuSPtr<IProcessSectionMapView> ProcessSectionViewReserved::MapFileByObjectEx(AuUInt viewOffset,
const AuSPtr<Aurora::IO::FS::IFileStream> &pStream,
const AuSPtr<IO::IIOHandle> &pIOHandle,
AuUInt64 uOffset,
AuUInt uLength,
Aurora::IO::FS::EFileOpenMode mode,
@ -320,7 +338,7 @@ namespace Aurora::Process
ULONG desiredAccess {}, pageAttributes {};
AuUInt uAddressOut;
if (!pStream)
if (!pIOHandle)
{
SysPushErrorArg();
return {};
@ -337,7 +355,6 @@ namespace Aurora::Process
return {};
}
auto pFileStream = AuStaticCast<AuFS::WinFileStream>(pStream);
if (processLockLevel != AuFS::EFileAdvisoryLockLevel::eNoSafety)
{
DWORD dwFlags {};
@ -353,7 +370,7 @@ namespace Aurora::Process
overlapped.Offset = AuBitsToLower(uOffset);
overlapped.OffsetHigh = AuBitsToHigher(uOffset);
if (!::LockFileEx(pFileStream->GetHandle(),
if (!::LockFileEx((HANDLE)pIOHandle->GetOSHandle(),
dwFlags,
0,
AuBitsToLower(uLength),
@ -385,7 +402,7 @@ namespace Aurora::Process
return {};
};
hFileMap = ::CreateFileMappingA(pFileStream->GetHandle(),
hFileMap = ::CreateFileMappingA((HANDLE)pIOHandle->GetOSHandle(),
nullptr,
pageAttributes,
#if defined(AURORA_IS_64BIT)

View File

@ -32,7 +32,7 @@ namespace Aurora::Process
AuFS::EFileOpenMode mode,
AuFS::EFileAdvisoryLockLevel sectionLock) override;
AuSPtr<IProcessSectionMapView> MapFileByObject(const AuSPtr<Aurora::IO::FS::IFileStream> &pStream,
AuSPtr<IProcessSectionMapView> MapFileByObject(const AuSPtr<IO::IIOHandle> &pIOHandle,
AuUInt64 uOffset,
AuUInt uLength,
Aurora::IO::FS::EFileOpenMode mode,
@ -59,7 +59,7 @@ namespace Aurora::Process
Aurora::IO::FS::EFileAdvisoryLockLevel processLockLevel) override;
AuSPtr<IProcessSectionMapView> MapFileByObjectEx(AuUInt viewOffset,
const AuSPtr<Aurora::IO::FS::IFileStream> &stream,
const AuSPtr<IO::IIOHandle> &pIOHandle,
AuUInt64 uOffset,
AuUInt uLength,
Aurora::IO::FS::EFileOpenMode mode,