2010-11-06 16:25:40 +00:00
|
|
|
/* PCSX2 - PS2 Emulator for PCs
|
|
|
|
* Copyright (C) 2002-2010 PCSX2 Dev Team
|
|
|
|
*
|
|
|
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2022-10-12 13:57:53 +00:00
|
|
|
#include "common/Align.h"
|
2021-09-01 20:31:46 +00:00
|
|
|
#include "common/PageFaultSource.h"
|
|
|
|
#include "common/EventSource.inl"
|
|
|
|
#include "common/MemsetFast.inl"
|
2022-05-09 10:11:30 +00:00
|
|
|
#include "common/Console.h"
|
2010-11-17 03:18:36 +00:00
|
|
|
|
2022-05-18 13:27:23 +00:00
|
|
|
#include "fmt/core.h"
|
|
|
|
|
|
|
|
#include <cinttypes>
|
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
template class EventSource<IEventListener_PageFault>;
|
2010-11-06 16:25:40 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
SrcType_PageFault* Source_PageFault = NULL;
|
2022-05-09 10:11:30 +00:00
|
|
|
std::mutex PageFault_Mutex;
|
2010-11-06 16:25:40 +00:00
|
|
|
|
2010-11-15 14:05:02 +00:00
|
|
|
void pxInstallSignalHandler()
|
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
if (!Source_PageFault)
|
|
|
|
{
|
|
|
|
Source_PageFault = new SrcType_PageFault();
|
|
|
|
}
|
2010-11-15 14:05:02 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
_platform_InstallSignalHandler();
|
2010-11-15 14:05:02 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
// NOP on Win32 systems -- we use __try{} __except{} instead.
|
2010-11-15 14:05:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// EventListener_PageFault (implementations)
|
|
|
|
// --------------------------------------------------------------------------------------
|
2010-11-06 16:25:40 +00:00
|
|
|
EventListener_PageFault::EventListener_PageFault()
|
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
pxAssert(Source_PageFault);
|
|
|
|
Source_PageFault->Add(*this);
|
2010-11-06 16:25:40 +00:00
|
|
|
}
|
|
|
|
|
2017-05-06 12:22:00 +00:00
|
|
|
EventListener_PageFault::~EventListener_PageFault()
|
2010-11-06 16:25:40 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
if (Source_PageFault)
|
|
|
|
Source_PageFault->Remove(*this);
|
2010-11-06 16:25:40 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void SrcType_PageFault::Dispatch(const PageFaultInfo& params)
|
2010-11-06 16:25:40 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
m_handled = false;
|
|
|
|
_parent::Dispatch(params);
|
2010-11-06 16:25:40 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void SrcType_PageFault::_DispatchRaw(ListenerIterator iter, const ListenerIterator& iend, const PageFaultInfo& evt)
|
2010-11-06 16:25:40 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
(*iter)->DispatchEvent(evt, m_handled);
|
|
|
|
} while ((++iter != iend) && !m_handled);
|
2010-11-06 16:25:40 +00:00
|
|
|
}
|
|
|
|
|
2020-08-19 08:20:48 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// VirtualMemoryManager (implementations)
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
|
2022-10-12 13:57:53 +00:00
|
|
|
VirtualMemoryManager::VirtualMemoryManager(std::string name, const char* file_mapping_name, uptr base, size_t size, uptr upper_bounds, bool strict)
|
2022-05-18 13:27:23 +00:00
|
|
|
: m_name(std::move(name))
|
2022-10-12 13:57:53 +00:00
|
|
|
, m_file_handle(nullptr)
|
2021-09-06 18:28:26 +00:00
|
|
|
, m_baseptr(0)
|
|
|
|
, m_pageuse(nullptr)
|
|
|
|
, m_pages_reserved(0)
|
2020-08-19 08:20:48 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
if (!size)
|
|
|
|
return;
|
|
|
|
|
2022-10-12 13:57:53 +00:00
|
|
|
size_t reserved_bytes = Common::PageAlign(size);
|
2021-09-06 18:28:26 +00:00
|
|
|
m_pages_reserved = reserved_bytes / __pagesize;
|
|
|
|
|
2022-10-12 13:57:53 +00:00
|
|
|
if (file_mapping_name && file_mapping_name[0])
|
2021-09-06 18:28:26 +00:00
|
|
|
{
|
2022-10-12 13:57:53 +00:00
|
|
|
std::string real_file_mapping_name(HostSys::GetFileMappingName(file_mapping_name));
|
|
|
|
m_file_handle = HostSys::CreateSharedMemory(real_file_mapping_name.c_str(), reserved_bytes);
|
|
|
|
if (!m_file_handle)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_baseptr = static_cast<u8*>(HostSys::MapSharedMemory(m_file_handle, 0, (void*)base, reserved_bytes, PageAccess_ReadWrite()));
|
|
|
|
if (!m_baseptr || (upper_bounds != 0 && (((uptr)m_baseptr + reserved_bytes) > upper_bounds)))
|
|
|
|
{
|
|
|
|
DevCon.Warning("%s: host memory @ 0x%016" PRIXPTR " -> 0x%016" PRIXPTR " is unavailable; attempting to map elsewhere...",
|
|
|
|
m_name.c_str(), base, base + size);
|
2021-09-06 18:28:26 +00:00
|
|
|
|
2022-10-12 13:57:53 +00:00
|
|
|
SafeSysMunmap(m_baseptr, reserved_bytes);
|
|
|
|
|
|
|
|
if (base)
|
|
|
|
{
|
|
|
|
// Let's try again at an OS-picked memory area, and then hope it meets needed
|
|
|
|
// boundschecking criteria below.
|
|
|
|
m_baseptr = static_cast<u8*>(HostSys::MapSharedMemory(m_file_handle, 0, nullptr, reserved_bytes, PageAccess_ReadWrite()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_baseptr = static_cast<u8*>(HostSys::Mmap((void*)base, reserved_bytes, PageAccess_Any()));
|
2021-09-06 18:28:26 +00:00
|
|
|
|
2022-10-12 13:57:53 +00:00
|
|
|
if (!m_baseptr || (upper_bounds != 0 && (((uptr)m_baseptr + reserved_bytes) > upper_bounds)))
|
2021-09-06 18:28:26 +00:00
|
|
|
{
|
2022-10-12 13:57:53 +00:00
|
|
|
DevCon.Warning("%s: host memory @ 0x%016" PRIXPTR " -> 0x%016" PRIXPTR " is unavailable; attempting to map elsewhere...",
|
|
|
|
m_name.c_str(), base, base + size);
|
|
|
|
|
|
|
|
SafeSysMunmap(m_baseptr, reserved_bytes);
|
|
|
|
|
|
|
|
if (base)
|
|
|
|
{
|
|
|
|
// Let's try again at an OS-picked memory area, and then hope it meets needed
|
|
|
|
// boundschecking criteria below.
|
|
|
|
m_baseptr = static_cast<u8*>(HostSys::Mmap(0, reserved_bytes, PageAccess_Any()));
|
|
|
|
}
|
2021-09-06 18:28:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool fulfillsRequirements = true;
|
2022-10-12 13:57:53 +00:00
|
|
|
if (strict && (uptr)m_baseptr != base)
|
2021-09-06 18:28:26 +00:00
|
|
|
fulfillsRequirements = false;
|
2022-10-12 13:57:53 +00:00
|
|
|
if ((upper_bounds != 0) && ((uptr)(m_baseptr + reserved_bytes) > upper_bounds))
|
2021-09-06 18:28:26 +00:00
|
|
|
fulfillsRequirements = false;
|
|
|
|
if (!fulfillsRequirements)
|
|
|
|
{
|
2022-10-12 13:57:53 +00:00
|
|
|
if (m_file_handle)
|
|
|
|
{
|
|
|
|
if (m_baseptr)
|
|
|
|
HostSys::UnmapSharedMemory(m_baseptr, reserved_bytes);
|
|
|
|
m_baseptr = 0;
|
|
|
|
|
|
|
|
HostSys::DestroySharedMemory(m_file_handle);
|
|
|
|
m_file_handle = nullptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SafeSysMunmap(m_baseptr, reserved_bytes);
|
|
|
|
}
|
2021-09-06 18:28:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_baseptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_pageuse = new std::atomic<bool>[m_pages_reserved]();
|
|
|
|
|
2022-05-18 13:27:23 +00:00
|
|
|
std::string mbkb;
|
2021-09-06 18:28:26 +00:00
|
|
|
uint mbytes = reserved_bytes / _1mb;
|
|
|
|
if (mbytes)
|
2022-05-18 13:27:23 +00:00
|
|
|
mbkb = fmt::format("[{}mb]", mbytes);
|
2021-09-06 18:28:26 +00:00
|
|
|
else
|
2022-05-18 13:27:23 +00:00
|
|
|
mbkb = fmt::format("[{}kb]", reserved_bytes / 1024);
|
2021-09-06 18:28:26 +00:00
|
|
|
|
2022-05-18 13:27:23 +00:00
|
|
|
DevCon.WriteLn(Color_Gray, "%-32s @ 0x%016" PRIXPTR " -> 0x%016" PRIXPTR " %s", m_name.c_str(),
|
|
|
|
m_baseptr, (uptr)m_baseptr + reserved_bytes, mbkb.c_str());
|
2020-08-19 08:20:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VirtualMemoryManager::~VirtualMemoryManager()
|
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
if (m_pageuse)
|
|
|
|
delete[] m_pageuse;
|
|
|
|
if (m_baseptr)
|
2022-10-12 13:57:53 +00:00
|
|
|
{
|
|
|
|
if (m_file_handle)
|
|
|
|
HostSys::UnmapSharedMemory((void*)m_baseptr, m_pages_reserved * __pagesize);
|
|
|
|
else
|
|
|
|
HostSys::Munmap(m_baseptr, m_pages_reserved * __pagesize);
|
|
|
|
}
|
|
|
|
if (m_file_handle)
|
|
|
|
HostSys::DestroySharedMemory(m_file_handle);
|
2020-08-19 08:20:48 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
static bool VMMMarkPagesAsInUse(std::atomic<bool>* begin, std::atomic<bool>* end)
|
|
|
|
{
|
|
|
|
for (auto current = begin; current < end; current++)
|
|
|
|
{
|
|
|
|
bool expected = false;
|
|
|
|
if (!current->compare_exchange_strong(expected, true), std::memory_order_relaxed)
|
|
|
|
{
|
|
|
|
// This was already allocated! Undo the things we've set until this point
|
|
|
|
while (--current >= begin)
|
|
|
|
{
|
|
|
|
if (!current->compare_exchange_strong(expected, false, std::memory_order_relaxed))
|
|
|
|
{
|
|
|
|
// In the time we were doing this, someone set one of the things we just set to true back to false
|
|
|
|
// This should never happen, but if it does we'll just stop and hope nothing bad happens
|
|
|
|
pxAssert(0);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2020-08-19 08:20:48 +00:00
|
|
|
}
|
|
|
|
|
2022-10-12 13:57:53 +00:00
|
|
|
u8* VirtualMemoryManager::Alloc(uptr offsetLocation, size_t size) const
|
2020-08-19 08:20:48 +00:00
|
|
|
{
|
2022-10-12 13:57:53 +00:00
|
|
|
size = Common::PageAlign(size);
|
2021-09-06 18:28:26 +00:00
|
|
|
if (!pxAssertDev(offsetLocation % __pagesize == 0, "(VirtualMemoryManager) alloc at unaligned offsetLocation"))
|
|
|
|
return nullptr;
|
|
|
|
if (!pxAssertDev(size + offsetLocation <= m_pages_reserved * __pagesize, "(VirtualMemoryManager) alloc outside reserved area"))
|
|
|
|
return nullptr;
|
|
|
|
if (m_baseptr == 0)
|
|
|
|
return nullptr;
|
|
|
|
auto puStart = &m_pageuse[offsetLocation / __pagesize];
|
|
|
|
auto puEnd = &m_pageuse[(offsetLocation + size) / __pagesize];
|
|
|
|
if (!pxAssertDev(VMMMarkPagesAsInUse(puStart, puEnd), "(VirtualMemoryManager) allocation requests overlapped"))
|
|
|
|
return nullptr;
|
2022-10-12 13:57:53 +00:00
|
|
|
return m_baseptr + offsetLocation;
|
2020-08-19 08:20:48 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void VirtualMemoryManager::Free(void* address, size_t size) const
|
2020-08-19 08:20:48 +00:00
|
|
|
{
|
2022-10-12 13:57:53 +00:00
|
|
|
uptr offsetLocation = (uptr)address - (uptr)m_baseptr;
|
2021-09-06 18:28:26 +00:00
|
|
|
if (!pxAssertDev(offsetLocation % __pagesize == 0, "(VirtualMemoryManager) free at unaligned address"))
|
|
|
|
{
|
2022-10-12 13:57:53 +00:00
|
|
|
uptr newLoc = Common::PageAlign(offsetLocation);
|
2021-09-06 18:28:26 +00:00
|
|
|
size -= (offsetLocation - newLoc);
|
|
|
|
offsetLocation = newLoc;
|
|
|
|
}
|
|
|
|
if (!pxAssertDev(size % __pagesize == 0, "(VirtualMemoryManager) free with unaligned size"))
|
|
|
|
size -= size % __pagesize;
|
|
|
|
if (!pxAssertDev(size + offsetLocation <= m_pages_reserved * __pagesize, "(VirtualMemoryManager) free outside reserved area"))
|
|
|
|
return;
|
|
|
|
auto puStart = &m_pageuse[offsetLocation / __pagesize];
|
|
|
|
auto puEnd = &m_pageuse[(offsetLocation + size) / __pagesize];
|
|
|
|
for (; puStart < puEnd; puStart++)
|
|
|
|
{
|
|
|
|
bool expected = true;
|
|
|
|
if (!puStart->compare_exchange_strong(expected, false, std::memory_order_relaxed))
|
|
|
|
{
|
|
|
|
pxAssertDev(0, "(VirtaulMemoryManager) double-free");
|
|
|
|
}
|
|
|
|
}
|
2020-08-19 08:20:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// VirtualMemoryBumpAllocator (implementations)
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
VirtualMemoryBumpAllocator::VirtualMemoryBumpAllocator(VirtualMemoryManagerPtr allocator, uptr offsetLocation, size_t size)
|
2021-09-06 18:28:26 +00:00
|
|
|
: m_allocator(std::move(allocator))
|
2022-10-12 13:57:53 +00:00
|
|
|
, m_baseptr(m_allocator->Alloc(offsetLocation, size))
|
2021-09-06 18:28:26 +00:00
|
|
|
, m_endptr(m_baseptr + size)
|
2020-08-19 08:20:48 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
if (m_baseptr.load() == 0)
|
|
|
|
pxAssertDev(0, "(VirtualMemoryBumpAllocator) tried to construct from bad VirtualMemoryManager");
|
2020-08-19 08:20:48 +00:00
|
|
|
}
|
|
|
|
|
2022-10-12 13:57:53 +00:00
|
|
|
u8* VirtualMemoryBumpAllocator::Alloc(size_t size)
|
2020-08-19 08:20:48 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
if (m_baseptr.load() == 0) // True if constructed from bad VirtualMemoryManager (assertion was on initialization)
|
|
|
|
return nullptr;
|
2020-08-19 08:20:48 +00:00
|
|
|
|
2022-10-12 13:57:53 +00:00
|
|
|
size_t reservedSize = Common::PageAlign(size);
|
2020-08-19 08:20:48 +00:00
|
|
|
|
2022-10-12 13:57:53 +00:00
|
|
|
u8* out = m_baseptr.fetch_add(reservedSize, std::memory_order_relaxed);
|
2020-08-19 08:20:48 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
if (!pxAssertDev(out - reservedSize + size <= m_endptr, "(VirtualMemoryBumpAllocator) ran out of memory"))
|
|
|
|
return nullptr;
|
2020-08-19 08:20:48 +00:00
|
|
|
|
2022-10-12 13:57:53 +00:00
|
|
|
return out;
|
2020-08-19 08:20:48 +00:00
|
|
|
}
|
|
|
|
|
2010-11-06 16:25:40 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
2010-11-15 14:05:02 +00:00
|
|
|
// VirtualMemoryReserve (implementations)
|
2010-11-06 16:25:40 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
2022-10-12 13:57:53 +00:00
|
|
|
VirtualMemoryReserve::VirtualMemoryReserve(std::string name)
|
2022-05-18 13:27:23 +00:00
|
|
|
: m_name(std::move(name))
|
2010-11-06 16:25:40 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-10-12 13:57:53 +00:00
|
|
|
VirtualMemoryReserve::~VirtualMemoryReserve()
|
2010-11-15 14:05:02 +00:00
|
|
|
{
|
2022-10-12 13:57:53 +00:00
|
|
|
pxAssertRel(!m_baseptr, "VirtualMemoryReserve has not been released.");
|
2010-11-15 14:05:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Notes:
|
|
|
|
// * This method should be called if the object is already in an released (unreserved) state.
|
|
|
|
// Subsequent calls will be ignored, and the existing reserve will be returned.
|
|
|
|
//
|
2010-11-06 16:25:40 +00:00
|
|
|
// Parameters:
|
2020-08-19 08:20:48 +00:00
|
|
|
// baseptr - the new base pointer that's about to be assigned
|
|
|
|
// size - size of the region pointed to by baseptr
|
2010-11-15 14:05:02 +00:00
|
|
|
//
|
2022-10-12 13:57:53 +00:00
|
|
|
void VirtualMemoryReserve::Assign(VirtualMemoryManagerPtr allocator, u8* baseptr, size_t size)
|
2010-11-06 16:25:40 +00:00
|
|
|
{
|
2022-10-12 13:57:53 +00:00
|
|
|
pxAssertRel(size > 0 && Common::IsAlignedPow2(size, __pagesize), "VM allocation is not page aligned");
|
|
|
|
pxAssertRel(!m_baseptr, "Virtual memory reserve has already been assigned");
|
2010-11-15 14:05:02 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
m_allocator = std::move(allocator);
|
|
|
|
m_baseptr = baseptr;
|
2022-10-12 13:57:53 +00:00
|
|
|
m_size = size;
|
2010-11-16 15:58:42 +00:00
|
|
|
|
2022-05-18 13:27:23 +00:00
|
|
|
std::string mbkb;
|
2022-10-12 13:57:53 +00:00
|
|
|
uint mbytes = size / _1mb;
|
2021-09-06 18:28:26 +00:00
|
|
|
if (mbytes)
|
2022-05-18 13:27:23 +00:00
|
|
|
mbkb = fmt::format("[{}mb]", mbytes);
|
2021-09-06 18:28:26 +00:00
|
|
|
else
|
2022-10-12 13:57:53 +00:00
|
|
|
mbkb = fmt::format("[{}kb]", size / 1024);
|
2010-11-16 15:58:42 +00:00
|
|
|
|
2022-05-18 13:27:23 +00:00
|
|
|
DevCon.WriteLn(Color_Gray, "%-32s @ 0x%016" PRIXPTR " -> 0x%016" PRIXPTR " %s", m_name.c_str(),
|
2022-10-12 13:57:53 +00:00
|
|
|
m_baseptr, (uptr)m_baseptr + size, mbkb.c_str());
|
2010-12-30 06:21:07 +00:00
|
|
|
}
|
|
|
|
|
2022-10-12 13:57:53 +00:00
|
|
|
u8* VirtualMemoryReserve::BumpAllocate(VirtualMemoryBumpAllocator& allocator, size_t size)
|
2010-11-06 16:25:40 +00:00
|
|
|
{
|
2022-10-12 13:57:53 +00:00
|
|
|
u8* base = allocator.Alloc(size);
|
|
|
|
if (base)
|
|
|
|
Assign(allocator.GetAllocator(), base, size);
|
2010-11-15 14:05:02 +00:00
|
|
|
|
2022-10-12 13:57:53 +00:00
|
|
|
return base;
|
2010-11-15 14:05:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VirtualMemoryReserve::Release()
|
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
if (!m_baseptr)
|
|
|
|
return;
|
2010-11-06 16:25:40 +00:00
|
|
|
|
2022-10-12 13:57:53 +00:00
|
|
|
m_allocator->Free(m_baseptr, m_size);
|
|
|
|
m_baseptr = nullptr;
|
|
|
|
m_size = 0;
|
2010-11-06 16:25:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// PageProtectionMode (implementations)
|
|
|
|
// --------------------------------------------------------------------------------------
|
2022-05-18 13:27:23 +00:00
|
|
|
std::string PageProtectionMode::ToString() const
|
2010-11-06 16:25:40 +00:00
|
|
|
{
|
2022-05-18 13:27:23 +00:00
|
|
|
std::string modeStr;
|
2010-11-06 16:25:40 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
if (m_read)
|
2022-05-18 13:27:23 +00:00
|
|
|
modeStr += "Read";
|
2021-09-06 18:28:26 +00:00
|
|
|
if (m_write)
|
2022-05-18 13:27:23 +00:00
|
|
|
modeStr += "Write";
|
2021-09-06 18:28:26 +00:00
|
|
|
if (m_exec)
|
2022-05-18 13:27:23 +00:00
|
|
|
modeStr += "Exec";
|
2010-11-06 16:25:40 +00:00
|
|
|
|
2022-05-18 13:27:23 +00:00
|
|
|
if (modeStr.empty())
|
|
|
|
return "NoAccess";
|
|
|
|
if (modeStr.length() <= 5)
|
|
|
|
modeStr += "Only";
|
2010-11-06 16:25:40 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
return modeStr;
|
2010-11-06 16:25:40 +00:00
|
|
|
}
|