2022-08-10 09:50:49 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: ProcessSectionFileMapView.NT.cpp
|
|
|
|
Date: 2022-08-09
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#include <Source/RuntimeInternal.hpp>
|
2022-12-17 20:14:19 +00:00
|
|
|
#include "AuProcessSectionFileMapView.NT.hpp"
|
|
|
|
#include "AuProcessSectionViewReserved.NT.hpp"
|
|
|
|
#include "AuProcessSectionView.NT.hpp"
|
2022-08-10 09:50:49 +00:00
|
|
|
|
|
|
|
namespace Aurora::Process
|
|
|
|
{
|
|
|
|
ProcessSectionFileMapView::~ProcessSectionFileMapView()
|
|
|
|
{
|
|
|
|
Unmap();
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessSectionFileMapView::ProcessSectionFileMapView(AuUInt uAddress, HANDLE hSection) :
|
|
|
|
uAddress(uAddress),
|
|
|
|
hFileSection(hSection)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProcessSectionFileMapView::Unmap()
|
|
|
|
{
|
|
|
|
if (AuExchange(this->bIsDead_, true))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2022-09-30 22:47:18 +00:00
|
|
|
|
2022-08-10 09:50:49 +00:00
|
|
|
if (this->uAddress)
|
|
|
|
{
|
2022-09-30 22:47:18 +00:00
|
|
|
if (this->pSharedSectionHint)
|
|
|
|
{
|
|
|
|
SysAssert(AuStaticCast<ProcessSectionViewReserved>(this->pSharedSectionHint)->ReleaseAndCoaleceAddress(this->uOffset, this->uLength));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
::UnmapViewOfFile((PVOID)this->uAddress);
|
|
|
|
}
|
2022-08-10 09:50:49 +00:00
|
|
|
this->uAddress = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuWin32CloseHandle(this->hFileSection);
|
2022-09-30 22:47:18 +00:00
|
|
|
this->pSharedSectionHint.reset();
|
|
|
|
this->pProcessGlobalHint = nullptr;
|
2022-08-10 09:50:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ProcessSectionFileMapView::Flush(AuUInt offset, AuUInt length)
|
|
|
|
{
|
|
|
|
return ::FlushViewOfFile(this->GetPointer(offset), length);
|
|
|
|
}
|
|
|
|
|
|
|
|
AuUInt ProcessSectionFileMapView::GetBaseAddress()
|
|
|
|
{
|
|
|
|
return this->uAddress;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuUInt ProcessSectionFileMapView::GetAddress(AuUInt offset)
|
|
|
|
{
|
|
|
|
return this->uAddress ? this->uAddress + offset : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuUInt8 *ProcessSectionFileMapView::GetBasePointer()
|
|
|
|
{
|
|
|
|
return AuReinterpretCast<AuUInt8 *>(this->uAddress);
|
|
|
|
}
|
|
|
|
|
|
|
|
AuUInt8 *ProcessSectionFileMapView::GetPointer(AuUInt offset)
|
|
|
|
{
|
|
|
|
return this->uAddress ? AuReinterpretCast<AuUInt8 *>(this->uAddress) + offset : 0;
|
|
|
|
}
|
2023-04-17 14:55:51 +00:00
|
|
|
|
|
|
|
bool ProcessSectionFileMapView::LockSwap()
|
|
|
|
{
|
|
|
|
if (!this->uAddress)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return AuMemory::SwapLock::Lock({ { this->uAddress, this->uLength} });
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ProcessSectionFileMapView::UnlockSwap()
|
|
|
|
{
|
|
|
|
if (!this->uAddress)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return AuMemory::SwapLock::Unlock({ { this->uAddress, this->uLength} });
|
|
|
|
}
|
2022-08-10 09:50:49 +00:00
|
|
|
}
|