73 lines
1.8 KiB
C++
Executable File
73 lines
1.8 KiB
C++
Executable File
/***
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: ProcessSectionFileMapView.Unix.cpp
|
|
Date: 2022-08-09
|
|
Author: Reece
|
|
***/
|
|
#include <Source/RuntimeInternal.hpp>
|
|
#include "ProcessSectionFileMapView.Unix.hpp"
|
|
#include "ProcessSectionView.Unix.hpp"
|
|
#include <sys/mman.h>
|
|
|
|
namespace Aurora::Process
|
|
{
|
|
ProcessSectionFileMapView::ProcessSectionFileMapView(AuUInt uAddress, AuUInt uLength, bool bShouldUnmap, int optFd) :
|
|
uAddress(uAddress),
|
|
uLength_(uLength),
|
|
bShouldUnmap_(bShouldUnmap),
|
|
optFd_(optFd)
|
|
{
|
|
|
|
}
|
|
|
|
ProcessSectionFileMapView::~ProcessSectionFileMapView()
|
|
{
|
|
Unmap();
|
|
}
|
|
|
|
void ProcessSectionFileMapView::Unmap()
|
|
{
|
|
if (AuExchange(this->bIsDead_, true))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (this->uAddress && this->bShouldUnmap_)
|
|
{
|
|
::munmap(this->GetBasePointer(), this->uLength_);
|
|
this->uAddress = 0;
|
|
}
|
|
|
|
int fd {-1};
|
|
if ((fd = AuExchange(this->optFd_, -1)) != -1)
|
|
{
|
|
::close(fd);
|
|
}
|
|
}
|
|
|
|
bool ProcessSectionFileMapView::Flush(AuUInt offset, AuUInt length)
|
|
{
|
|
return ::msync(this->GetPointer(offset), length, MS_SYNC) == 0;
|
|
}
|
|
|
|
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;
|
|
}
|
|
} |