2022-09-30 22:47:18 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
2022-12-17 20:14:19 +00:00
|
|
|
File: AuProcessSectionViewReserved.NT.cpp
|
2022-09-30 22:47:18 +00:00
|
|
|
Date: 2022-9-30
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#include <Source/RuntimeInternal.hpp>
|
2022-12-17 20:14:19 +00:00
|
|
|
#include "AuProcessSectionViewReserved.NT.hpp"
|
2022-09-30 22:47:18 +00:00
|
|
|
#include "Process.hpp"
|
|
|
|
#include <Source/IO/FS/FileStream.NT.hpp>
|
2022-12-17 20:14:19 +00:00
|
|
|
#include "AuProcessSectionFileMapView.NT.hpp"
|
|
|
|
#include "AuProcessSectionView.NT.hpp"
|
2022-12-14 07:12:43 +00:00
|
|
|
#include <Source/IO/IPC/AuIPCHandle.hpp>
|
2022-09-30 22:47:18 +00:00
|
|
|
#include <Windows.h>
|
|
|
|
|
|
|
|
namespace Aurora::Process
|
|
|
|
{
|
|
|
|
|
2022-12-17 20:14:19 +00:00
|
|
|
AuUInt ProcessSectionViewReserved::GetStart()
|
|
|
|
{
|
|
|
|
return (AuUInt)this->pBaseAddress;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuUInt ProcessSectionViewReserved::GetEnd()
|
|
|
|
{
|
|
|
|
return this->GetStart() + this->uMaxLength;
|
|
|
|
}
|
|
|
|
|
2022-09-30 22:47:18 +00:00
|
|
|
bool ProcessSectionViewReserved::Init(AuUInt uLength)
|
|
|
|
{
|
|
|
|
this->uMaxLength = uLength;
|
|
|
|
|
2023-02-16 16:01:21 +00:00
|
|
|
this->pBaseAddress = AuReinterpretCast<decltype(this->pBaseAddress)>(pVirtualAlloc2(
|
2022-09-30 22:47:18 +00:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
this->uMaxLength,
|
|
|
|
MEM_RESERVE | MEM_RESERVE_PLACEHOLDER,
|
|
|
|
PAGE_NOACCESS,
|
|
|
|
nullptr,
|
|
|
|
0));
|
|
|
|
|
|
|
|
return bool(this->pBaseAddress);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ProcessSectionViewReserved::AllocateAddress(AuUInt uOffset,
|
|
|
|
AuUInt uLength,
|
|
|
|
AuUInt &uAddressOut)
|
|
|
|
{
|
|
|
|
bool bCompleteBlock {};
|
|
|
|
AuUInt uFoundOffset {};
|
|
|
|
|
|
|
|
uAddressOut = 0;
|
|
|
|
|
|
|
|
if (!this->GetAddress(uOffset, uLength, uFoundOffset, bCompleteBlock))
|
|
|
|
{
|
|
|
|
SysPushErrorMemory("Reserved address space has no available space");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bCompleteBlock)
|
|
|
|
{
|
|
|
|
uAddressOut = uFoundOffset;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!::VirtualFree(this->pBaseAddress + uFoundOffset,
|
|
|
|
uLength,
|
|
|
|
MEM_RELEASE | MEM_PRESERVE_PLACEHOLDER))
|
|
|
|
{
|
|
|
|
SysPushErrorMemory("System refused to split desired region");
|
|
|
|
ReleaseAddress(uFoundOffset);
|
|
|
|
uAddressOut = uFoundOffset;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ProcessSectionViewReserved::ReleaseAndCoaleceAddress(AuUInt uOffset, AuUInt uLength)
|
|
|
|
{
|
|
|
|
AU_LOCK_GUARD(this->spinlock);
|
|
|
|
bool bSuccess {};
|
|
|
|
|
|
|
|
for (AuUInt i = 0; i < this->allocations.size(); i++)
|
|
|
|
{
|
|
|
|
auto &a = this->allocations[i];
|
|
|
|
if (a.first != uOffset)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uLength != a.second)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuUInt uPrevFree {};
|
|
|
|
AuUInt uNextFree {};
|
|
|
|
|
|
|
|
{
|
|
|
|
if (i != 0)
|
|
|
|
{
|
|
|
|
auto eh = this->allocations[i - 1];
|
|
|
|
uPrevFree = eh.first + eh.second;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uPrevFree = uOffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
AuUInt uStart {};
|
|
|
|
if (i != this->allocations.size() - 1)
|
|
|
|
{
|
|
|
|
uNextFree = this->allocations[i + 1].first;
|
|
|
|
}
|
|
|
|
else if (this->allocations.size() == 1)
|
|
|
|
{
|
|
|
|
uNextFree = this->uMaxLength;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uNextFree = uOffset + uLength;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-16 16:01:21 +00:00
|
|
|
if (!pUnmapViewOfFile2(INVALID_HANDLE_VALUE,
|
|
|
|
this->pBaseAddress + uOffset,
|
|
|
|
MEM_PRESERVE_PLACEHOLDER))
|
2022-09-30 22:47:18 +00:00
|
|
|
{
|
|
|
|
SysPushErrorMemory("System refused to restore placeholder: {}", GetLastError());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
if (!::VirtualFree(this->pBaseAddress + uOffset,
|
|
|
|
0,
|
|
|
|
MEM_RELEASE | MEM_PRESERVE_PLACEHOLDER))
|
|
|
|
{
|
|
|
|
SysPushErrorMemory("System refused to restore placeholder: {}", GetLastError());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
auto uFreeRange = uNextFree - uPrevFree;
|
|
|
|
if (uFreeRange != uLength)
|
|
|
|
{
|
|
|
|
if (!::VirtualFree(this->pBaseAddress + uPrevFree,
|
|
|
|
uFreeRange,
|
|
|
|
MEM_RELEASE | MEM_COALESCE_PLACEHOLDERS))
|
|
|
|
{
|
|
|
|
SysPushErrorMemory("System refused to coalece memory segments");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bSuccess = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bSuccess)
|
|
|
|
{
|
|
|
|
AuTryRemoveByTupleN<0>(this->allocations, uOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuSPtr<IProcessSectionMapView> ProcessSectionViewReserved::Allocate(AuUInt uLength)
|
|
|
|
{
|
|
|
|
PageTable table {};
|
|
|
|
table.NX = true;
|
|
|
|
table.readable = true;
|
|
|
|
table.writable = true;
|
|
|
|
return this->AllocateEx2(uLength, -1, table);
|
|
|
|
}
|
|
|
|
|
|
|
|
AuSPtr<IProcessSectionMapView> ProcessSectionViewReserved::MapFileByPath(const AuString &str,
|
|
|
|
AuUInt64 uOffset,
|
|
|
|
AuUInt uLength,
|
|
|
|
AuFS::EFileOpenMode mode,
|
|
|
|
AuFS::EFileAdvisoryLockLevel sectionLock)
|
|
|
|
{
|
|
|
|
return this->MapFileByPathEx(-1, str, uOffset, uLength, mode, sectionLock);
|
|
|
|
}
|
|
|
|
|
2023-07-29 08:02:55 +00:00
|
|
|
AuSPtr<IProcessSectionMapView> ProcessSectionViewReserved::MapFileByObject(const AuSPtr<IO::IIOHandle> &pIOHandle,
|
2022-09-30 22:47:18 +00:00
|
|
|
AuUInt64 uOffset,
|
|
|
|
AuUInt uLength,
|
|
|
|
AuFS::EFileOpenMode mode,
|
|
|
|
AuFS::EFileAdvisoryLockLevel processLockLevel)
|
|
|
|
{
|
2023-07-29 08:02:55 +00:00
|
|
|
return this->MapFileByObjectEx(-1, pIOHandle, uOffset, uLength, mode, processLockLevel);
|
2022-09-30 22:47:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AuSPtr<IProcessSectionMapView> ProcessSectionViewReserved::MapIPCMemory(const AuString &handleString,
|
|
|
|
AuUInt64 uOffset,
|
|
|
|
AuUInt uLength,
|
|
|
|
AuFS::EFileOpenMode mode)
|
|
|
|
{
|
|
|
|
return this->MapIPCMemoryEx(-1, handleString, uOffset, uLength, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
AuSPtr<IProcessSectionMapView> ProcessSectionViewReserved::AllocateEx(AuUInt uLength,
|
|
|
|
AuUInt uOffset)
|
|
|
|
{
|
|
|
|
PageTable table {};
|
|
|
|
table.NX = true;
|
|
|
|
table.readable = true;
|
|
|
|
table.writable = true;
|
|
|
|
return this->AllocateEx2(uLength, uOffset, table);
|
|
|
|
}
|
|
|
|
|
|
|
|
AuSPtr<IProcessSectionMapView> ProcessSectionViewReserved::AllocateEx2(AuUInt uLength,
|
|
|
|
AuUInt uOffset,
|
|
|
|
PageTable permissions)
|
|
|
|
{
|
|
|
|
HANDLE hFileMap;
|
|
|
|
DWORD uPageFlags {};
|
|
|
|
AuUInt uAddressOut;
|
|
|
|
|
|
|
|
if (!uLength)
|
|
|
|
{
|
|
|
|
SysPushErrorArg("invalid uLength");
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (permissions.writable && permissions.NX)
|
|
|
|
{
|
|
|
|
uPageFlags = PAGE_READWRITE;
|
|
|
|
}
|
|
|
|
else if (permissions.readable && permissions.NX)
|
|
|
|
{
|
|
|
|
uPageFlags = PAGE_READONLY;
|
|
|
|
}
|
|
|
|
else if (permissions.writable)
|
|
|
|
{
|
|
|
|
uPageFlags = PAGE_EXECUTE_READWRITE;
|
|
|
|
}
|
|
|
|
else if (permissions.readable)
|
|
|
|
{
|
|
|
|
uPageFlags = PAGE_EXECUTE_READ;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this->AllocateAddress(uOffset, uLength, uAddressOut))
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
hFileMap = ::CreateFileMappingA(INVALID_HANDLE_VALUE,
|
|
|
|
nullptr,
|
|
|
|
uPageFlags,
|
|
|
|
#if defined(AURORA_IS_64BIT)
|
|
|
|
AuBitsToHigher(uLength),
|
|
|
|
AuBitsToLower(uLength),
|
|
|
|
#else
|
|
|
|
0,
|
|
|
|
uLength,
|
|
|
|
#endif
|
|
|
|
nullptr);
|
|
|
|
if ((hFileMap == INVALID_HANDLE_VALUE) ||
|
|
|
|
(!hFileMap))
|
|
|
|
{
|
|
|
|
SysPushErrorIO("Couldn't create file map");
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2023-02-16 16:01:21 +00:00
|
|
|
auto map = pMapViewOfFile3(hFileMap,
|
|
|
|
INVALID_HANDLE_VALUE,
|
|
|
|
this->pBaseAddress + uAddressOut,
|
|
|
|
0,
|
|
|
|
uLength,
|
|
|
|
MEM_REPLACE_PLACEHOLDER,
|
|
|
|
uPageFlags,
|
|
|
|
nullptr,
|
|
|
|
0);
|
2022-09-30 22:47:18 +00:00
|
|
|
if (!map)
|
|
|
|
{
|
|
|
|
SysPushErrorIO("Couldn't create allocation of section");
|
|
|
|
AuWin32CloseHandle(hFileMap);
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
auto pNewObject = AuMakeShared<ProcessSectionFileMapView>(AuUInt(map), hFileMap);
|
|
|
|
if (!pNewObject)
|
|
|
|
{
|
|
|
|
SysPushErrorMem();
|
|
|
|
AuWin32CloseHandle(hFileMap);
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
pNewObject->pSharedSectionHint = AuSharedFromThis();
|
|
|
|
pNewObject->uOffset = uAddressOut;
|
|
|
|
pNewObject->uLength = uLength;
|
|
|
|
|
|
|
|
return pNewObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuSPtr<IProcessSectionMapView> ProcessSectionViewReserved::MapFileByPathEx(AuUInt viewOffset,
|
|
|
|
const AuString &str,
|
|
|
|
AuUInt64 uOffset,
|
|
|
|
AuUInt uLength,
|
|
|
|
Aurora::IO::FS::EFileOpenMode mode,
|
|
|
|
Aurora::IO::FS::EFileAdvisoryLockLevel sectionLock)
|
|
|
|
{
|
2023-07-29 08:02:55 +00:00
|
|
|
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);
|
2022-09-30 22:47:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AuSPtr<IProcessSectionMapView> ProcessSectionViewReserved::MapFileByObjectEx(AuUInt viewOffset,
|
2023-07-29 08:02:55 +00:00
|
|
|
const AuSPtr<IO::IIOHandle> &pIOHandle,
|
2022-09-30 22:47:18 +00:00
|
|
|
AuUInt64 uOffset,
|
|
|
|
AuUInt uLength,
|
|
|
|
Aurora::IO::FS::EFileOpenMode mode,
|
|
|
|
Aurora::IO::FS::EFileAdvisoryLockLevel processLockLevel)
|
|
|
|
{
|
|
|
|
HANDLE hFileMap;
|
|
|
|
ULONG desiredAccess {}, pageAttributes {};
|
|
|
|
AuUInt uAddressOut;
|
|
|
|
|
2023-07-29 08:02:55 +00:00
|
|
|
if (!pIOHandle)
|
2022-09-30 22:47:18 +00:00
|
|
|
{
|
|
|
|
SysPushErrorArg();
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!uLength)
|
|
|
|
{
|
|
|
|
SysPushErrorArg("invalid uLength");
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this->AllocateAddress(viewOffset, uLength, uAddressOut))
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (processLockLevel != AuFS::EFileAdvisoryLockLevel::eNoSafety)
|
|
|
|
{
|
|
|
|
DWORD dwFlags {};
|
|
|
|
OVERLAPPED overlapped {};
|
|
|
|
|
|
|
|
if (processLockLevel == AuFS::EFileAdvisoryLockLevel::eBlockReadWrite)
|
|
|
|
{
|
|
|
|
dwFlags |= LOCKFILE_EXCLUSIVE_LOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
dwFlags |= LOCKFILE_FAIL_IMMEDIATELY;
|
|
|
|
|
|
|
|
overlapped.Offset = AuBitsToLower(uOffset);
|
|
|
|
overlapped.OffsetHigh = AuBitsToHigher(uOffset);
|
|
|
|
|
2023-07-29 08:02:55 +00:00
|
|
|
if (!::LockFileEx((HANDLE)pIOHandle->GetOSHandle(),
|
2022-09-30 22:47:18 +00:00
|
|
|
dwFlags,
|
|
|
|
0,
|
|
|
|
AuBitsToLower(uLength),
|
|
|
|
AuBitsToHigher(uLength),
|
|
|
|
&overlapped))
|
|
|
|
{
|
|
|
|
SysPushErrorIO("No Lock");
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case AuFS::EFileOpenMode::eRead:
|
|
|
|
{
|
|
|
|
desiredAccess = SECTION_MAP_READ;
|
|
|
|
pageAttributes = PAGE_READONLY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AuFS::EFileOpenMode::eWrite:
|
|
|
|
case AuFS::EFileOpenMode::eReadWrite:
|
|
|
|
{
|
|
|
|
desiredAccess = SECTION_MAP_READ | SECTION_MAP_WRITE;
|
|
|
|
pageAttributes = PAGE_READWRITE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
SysPushErrorGeneric();
|
|
|
|
return {};
|
|
|
|
};
|
|
|
|
|
2023-07-29 08:02:55 +00:00
|
|
|
hFileMap = ::CreateFileMappingA((HANDLE)pIOHandle->GetOSHandle(),
|
2022-09-30 22:47:18 +00:00
|
|
|
nullptr,
|
|
|
|
pageAttributes,
|
|
|
|
#if defined(AURORA_IS_64BIT)
|
|
|
|
AuBitsToHigher(uLength),
|
|
|
|
AuBitsToLower(uLength),
|
|
|
|
#else
|
|
|
|
0,
|
|
|
|
uLength,
|
|
|
|
#endif
|
|
|
|
nullptr);
|
|
|
|
if ((hFileMap == INVALID_HANDLE_VALUE) ||
|
|
|
|
(!hFileMap))
|
|
|
|
{
|
|
|
|
SysPushErrorIO("Couldn't create file map. Is the requeted access mode too high for the given object?");
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2023-02-16 16:01:21 +00:00
|
|
|
auto map = pMapViewOfFile3(hFileMap,
|
|
|
|
INVALID_HANDLE_VALUE,
|
|
|
|
this->pBaseAddress + uAddressOut,
|
|
|
|
uOffset,
|
|
|
|
uLength,
|
|
|
|
MEM_REPLACE_PLACEHOLDER,
|
|
|
|
pageAttributes,
|
|
|
|
nullptr,
|
|
|
|
0);
|
2022-09-30 22:47:18 +00:00
|
|
|
if (!map)
|
|
|
|
{
|
|
|
|
SysPushErrorIO("Couldn't create map of section: {}", GetLastError());
|
|
|
|
AuWin32CloseHandle(hFileMap);
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
auto pNewObject = AuMakeShared<ProcessSectionFileMapView>(AuUInt(map), hFileMap);
|
|
|
|
if (!pNewObject)
|
|
|
|
{
|
|
|
|
SysPushErrorMem();
|
|
|
|
AuWin32CloseHandle(hFileMap);
|
|
|
|
::UnmapViewOfFile(map);
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
pNewObject->pSharedSectionHint = AuSharedFromThis();
|
|
|
|
pNewObject->uOffset = uAddressOut;
|
|
|
|
pNewObject->uLength = uLength;
|
|
|
|
|
|
|
|
return pNewObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuSPtr<IProcessSectionMapView> ProcessSectionViewReserved::MapIPCMemoryEx(AuUInt viewOffset,
|
|
|
|
const AuString &handleString,
|
|
|
|
AuUInt64 uOffset,
|
|
|
|
AuUInt uLength,
|
|
|
|
Aurora::IO::FS::EFileOpenMode mode)
|
|
|
|
{
|
|
|
|
AuIPC::IPCHandle handle;
|
|
|
|
HANDLE hFileMap;
|
|
|
|
ULONG desiredAccess {}, pageAttributes {};
|
|
|
|
AuUInt uAddressOut;
|
|
|
|
|
|
|
|
if (!uLength)
|
|
|
|
{
|
|
|
|
SysPushErrorArg("invalid uLength");
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!handle.FromString(handleString))
|
|
|
|
{
|
|
|
|
SysPushErrorParseError("{}", handleString);
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
auto token = handle.GetToken(AuIPC::EIPCHandleType::eIPCMemory, 0);
|
|
|
|
if (!token)
|
|
|
|
{
|
|
|
|
SysPushErrorParseError();
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
auto actualLength = token->token.word;
|
|
|
|
auto path = token->token.ToNTPath();
|
|
|
|
|
|
|
|
if (actualLength < uOffset + uLength)
|
|
|
|
{
|
|
|
|
SysPushErrorIO("Out of range");
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case AuFS::EFileOpenMode::eRead:
|
|
|
|
{
|
|
|
|
desiredAccess = SECTION_MAP_READ;
|
|
|
|
pageAttributes = PAGE_READONLY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AuFS::EFileOpenMode::eWrite:
|
|
|
|
case AuFS::EFileOpenMode::eReadWrite:
|
|
|
|
{
|
|
|
|
pageAttributes = PAGE_READWRITE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
SysPushErrorGeneric();
|
|
|
|
return {};
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!this->AllocateAddress(viewOffset, uLength, uAddressOut))
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
hFileMap = ::OpenFileMappingA(desiredAccess,
|
|
|
|
FALSE,
|
|
|
|
path.c_str());
|
|
|
|
if ((hFileMap == INVALID_HANDLE_VALUE) ||
|
|
|
|
(!hFileMap))
|
|
|
|
{
|
|
|
|
SysPushErrorIO("Couldn't create IPC map (handle: {})", handleString);
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2023-02-16 16:01:21 +00:00
|
|
|
auto map = pMapViewOfFile3(hFileMap,
|
|
|
|
INVALID_HANDLE_VALUE,
|
|
|
|
this->pBaseAddress + uAddressOut,
|
|
|
|
uOffset,
|
|
|
|
uLength,
|
|
|
|
MEM_REPLACE_PLACEHOLDER,
|
|
|
|
pageAttributes,
|
|
|
|
nullptr,
|
|
|
|
0);
|
2022-09-30 22:47:18 +00:00
|
|
|
if (!map)
|
|
|
|
{
|
|
|
|
SysPushErrorIO("Couldn't create map of IPC section (handle: {})", handleString);
|
|
|
|
AuWin32CloseHandle(hFileMap);
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
auto pNewObject = AuMakeShared<ProcessSectionFileMapView>(AuUInt(map), hFileMap);
|
|
|
|
if (!pNewObject)
|
|
|
|
{
|
|
|
|
SysPushErrorMem();
|
|
|
|
AuWin32CloseHandle(hFileMap);
|
|
|
|
::UnmapViewOfFile(map);
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
pNewObject->pSharedSectionHint = AuSharedFromThis();
|
|
|
|
pNewObject->uOffset = uAddressOut;
|
|
|
|
pNewObject->uLength = uLength;
|
|
|
|
|
|
|
|
return pNewObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuList<AuPair<AuUInt, AuUInt>> ProcessSectionViewReserved::GetAllocations()
|
|
|
|
{
|
|
|
|
AU_LOCK_GUARD(this->spinlock);
|
|
|
|
return this->allocations;
|
|
|
|
}
|
|
|
|
|
|
|
|
AUKN_SYM AuSPtr<IProcessSectionView> ReserveAddressSpace(AuUInt uLength)
|
|
|
|
{
|
|
|
|
auto &platform = AuSwInfo::GetPlatformInfo();
|
|
|
|
|
2023-02-16 16:01:21 +00:00
|
|
|
#if 0
|
2022-09-30 22:47:18 +00:00
|
|
|
if (!AuSwInfo::IsWindows10OrGreater() || // < win10 or
|
|
|
|
((platform.uKernelMajor == 10) && (platform.uKernelPatch < 1803)) ||
|
|
|
|
!VirtualAlloc2_f ||
|
|
|
|
!MapViewOfFile3_f) // < RS4
|
2023-02-16 16:01:21 +00:00
|
|
|
#else
|
|
|
|
if (!pVirtualAlloc2) // allow modified windows runtimes
|
|
|
|
#endif
|
2022-09-30 22:47:18 +00:00
|
|
|
{
|
|
|
|
static ProcessSectionView gSingleton;
|
2023-06-08 08:52:53 +00:00
|
|
|
gSingleton.DoVanillaDriverlessExtesionWin7Test();
|
2022-09-30 22:47:18 +00:00
|
|
|
return AuUnsafeRaiiToShared(&gSingleton);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto pSectionView = AuMakeShared<ProcessSectionViewReserved>();
|
|
|
|
if (!pSectionView)
|
|
|
|
{
|
|
|
|
SysPushErrorMemory();
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pSectionView->Init(uLength))
|
|
|
|
{
|
|
|
|
SysPushErrorMemory();
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
return pSectionView;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoadProcessSectionViewSymbol()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|