mirror of
https://github.com/reactos/reactos.git
synced 2025-08-06 18:12:58 +00:00
[CICERO] Move sdk/lib/cicero to base/ctf/cicero (#8055)
The CTF modules depend on Cicero static library. Cicero should be a component in CTF. This move will improve code readability and grep-ability. JIRA issue: CORE-19361 JIRA issue: CORE-19363 - Move sdk/lib/cicero to base/ctf/cicero. - Adapt CMakeLists.txt to this move. - No code content change except CMakeLists.txt.
This commit is contained in:
parent
543cf1e2fd
commit
e43e639c30
22 changed files with 1 additions and 1 deletions
123
base/ctf/cicero/cicfmap.cpp
Normal file
123
base/ctf/cicero/cicfmap.cpp
Normal file
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* PROJECT: ReactOS Cicero
|
||||
* LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
|
||||
* PURPOSE: Cicero file mapping
|
||||
* COPYRIGHT: Copyright 2023 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
|
||||
*/
|
||||
|
||||
#include "precomp.h"
|
||||
#include "cicfmap.h"
|
||||
|
||||
CicFileMapping::CicFileMapping(LPCTSTR pszName, CicMutex *pMutex)
|
||||
{
|
||||
m_pszName = NULL;
|
||||
m_pView = NULL;
|
||||
m_hMapping = NULL;
|
||||
m_bCreated = FALSE;
|
||||
m_bHasMutex = FALSE;
|
||||
m_pMutex = NULL;
|
||||
Init(pszName, pMutex);
|
||||
}
|
||||
|
||||
void CicFileMappingStatic::Close()
|
||||
{
|
||||
if (m_pView)
|
||||
{
|
||||
::UnmapViewOfFile(m_pView);
|
||||
m_pView = NULL;
|
||||
}
|
||||
|
||||
if (m_hMapping)
|
||||
{
|
||||
::CloseHandle(m_hMapping);
|
||||
m_hMapping = NULL;
|
||||
}
|
||||
|
||||
m_bCreated = FALSE;
|
||||
}
|
||||
|
||||
void CicFileMappingStatic::Init(LPCTSTR pszName, CicMutex *pMutex)
|
||||
{
|
||||
if (pMutex)
|
||||
m_pMutex = pMutex;
|
||||
|
||||
m_bCreated = FALSE;
|
||||
m_pszName = pszName;
|
||||
m_bHasMutex = (pMutex != NULL);
|
||||
}
|
||||
|
||||
LPVOID
|
||||
CicFileMappingStatic::Create(
|
||||
LPSECURITY_ATTRIBUTES pSA,
|
||||
DWORD dwMaximumSizeLow,
|
||||
LPBOOL pbAlreadyExists)
|
||||
{
|
||||
if (!m_pszName)
|
||||
return NULL;
|
||||
|
||||
m_hMapping = ::CreateFileMapping(INVALID_HANDLE_VALUE,
|
||||
pSA,
|
||||
PAGE_READWRITE,
|
||||
0,
|
||||
dwMaximumSizeLow,
|
||||
m_pszName);
|
||||
if (pbAlreadyExists)
|
||||
*pbAlreadyExists = (::GetLastError() == ERROR_ALREADY_EXISTS);
|
||||
if (!m_hMapping)
|
||||
return NULL;
|
||||
|
||||
m_bCreated = TRUE;
|
||||
return _Map();
|
||||
}
|
||||
|
||||
LPVOID CicFileMappingStatic::Open()
|
||||
{
|
||||
if (!m_pszName)
|
||||
return NULL;
|
||||
m_hMapping = ::OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, m_pszName);
|
||||
if (!m_hMapping)
|
||||
return NULL;
|
||||
|
||||
return _Map();
|
||||
}
|
||||
|
||||
LPVOID CicFileMappingStatic::_Map()
|
||||
{
|
||||
m_pView = ::MapViewOfFile(m_hMapping, FILE_MAP_WRITE, 0, 0, 0);
|
||||
if (!m_pView)
|
||||
{
|
||||
Close();
|
||||
return NULL;
|
||||
}
|
||||
return m_pView;
|
||||
}
|
||||
|
||||
BOOL CicFileMappingStatic::Enter()
|
||||
{
|
||||
if (!m_bHasMutex)
|
||||
return TRUE;
|
||||
return m_pMutex->Enter();
|
||||
}
|
||||
|
||||
void CicFileMappingStatic::Leave()
|
||||
{
|
||||
if (!m_bHasMutex)
|
||||
return;
|
||||
m_pMutex->Leave();
|
||||
}
|
||||
|
||||
BOOL CicFileMappingStatic::Flush(SIZE_T dwNumberOfBytesToFlush)
|
||||
{
|
||||
if (!m_pView)
|
||||
return FALSE;
|
||||
return ::FlushViewOfFile(m_pView, dwNumberOfBytesToFlush);
|
||||
}
|
||||
|
||||
void CicFileMappingStatic::Finalize()
|
||||
{
|
||||
if (!m_bHasMutex)
|
||||
return;
|
||||
|
||||
Close();
|
||||
Leave();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue