diff options
author | George Hazan <george.hazan@gmail.com> | 2014-01-26 15:43:57 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-01-26 15:43:57 +0000 |
commit | 232b5ed16b5c0eb5a26fe530eed45f01e909129a (patch) | |
tree | 141d0779d734d2ea2828e24df69d5f18443184fa | |
parent | d0580040b51b6c4803e0f61863bd985c382370e9 (diff) |
more accurate control of mmap modes/access
git-svn-id: http://svn.miranda-ng.org/main/trunk@7907 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | plugins/Db3x_mmap/src/dbcache.cpp | 29 | ||||
-rw-r--r-- | plugins/Db3x_mmap/src/dbintf.cpp | 7 | ||||
-rw-r--r-- | plugins/Db3x_mmap/src/init.cpp | 8 |
3 files changed, 27 insertions, 17 deletions
diff --git a/plugins/Db3x_mmap/src/dbcache.cpp b/plugins/Db3x_mmap/src/dbcache.cpp index f047af0a1b..b91362bf3b 100644 --- a/plugins/Db3x_mmap/src/dbcache.cpp +++ b/plugins/Db3x_mmap/src/dbcache.cpp @@ -25,9 +25,17 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. void CDb3Base::Map()
{
- m_hMap = CreateFileMapping(m_hDbFile, NULL, (m_bReadOnly) ? PAGE_WRITECOPY : PAGE_READWRITE, 0, m_dwFileSize, NULL);
+ DWORD dwProtectMode, dwAccess;
+ if (cb && cb->bAggressive)
+ dwProtectMode = PAGE_WRITECOPY, dwAccess = FILE_MAP_COPY;
+ else if (m_bReadOnly)
+ dwProtectMode = PAGE_READONLY, dwAccess = FILE_MAP_READ;
+ else
+ dwProtectMode = PAGE_READWRITE, dwAccess = FILE_MAP_ALL_ACCESS;
+
+ m_hMap = CreateFileMapping(m_hDbFile, NULL, dwProtectMode, 0, m_dwFileSize, NULL);
if (m_hMap) {
- m_pDbCache = (PBYTE)MapViewOfFile(m_hMap, (m_bReadOnly) ? FILE_MAP_COPY : FILE_MAP_ALL_ACCESS, 0, 0, 0);
+ m_pDbCache = (PBYTE)MapViewOfFile(m_hMap, dwAccess, 0, 0, 0);
if (!m_pDbCache)
DatabaseCorruption( _T("%s (MapViewOfFile failed. Code: %d)"));
}
@@ -40,17 +48,18 @@ void CDb3Base::ReMap(DWORD needed) log3("remapping %d + %d (file end: %d)",m_dwFileSize,needed,m_dbHeader.ofsFileEnd);
- if (needed > m_ChunkSize) {
- if (needed + m_dwFileSize > m_dbHeader.ofsFileEnd + m_ChunkSize)
- DatabaseCorruption( _T("%s (Too large increment)"));
- else {
- DWORD x = m_dbHeader.ofsFileEnd/m_ChunkSize;
- m_dwFileSize = (x+1)*m_ChunkSize;
+ if (needed > 0) {
+ if (needed > m_ChunkSize) {
+ if (needed + m_dwFileSize > m_dbHeader.ofsFileEnd + m_ChunkSize)
+ DatabaseCorruption(_T("%s (Too large increment)"));
+ else {
+ DWORD x = m_dbHeader.ofsFileEnd/m_ChunkSize;
+ m_dwFileSize = (x+1)*m_ChunkSize;
+ }
}
+ else m_dwFileSize += m_ChunkSize;
}
- else m_dwFileSize += m_ChunkSize;
-// FlushViewOfFile(m_pDbCache, 0);
UnmapViewOfFile(m_pDbCache);
m_pDbCache = NULL;
CloseHandle(m_hMap);
diff --git a/plugins/Db3x_mmap/src/dbintf.cpp b/plugins/Db3x_mmap/src/dbintf.cpp index a3fbb8a62e..a6b579fc0d 100644 --- a/plugins/Db3x_mmap/src/dbintf.cpp +++ b/plugins/Db3x_mmap/src/dbintf.cpp @@ -122,11 +122,11 @@ int CDb3Base::Load(bool bSkipInit) }
if (!bSkipInit) {
- if (InitCache()) return 1;
- if (InitModuleNames()) return 1;
-
m_bReadOnly = false;
+ if (InitCache()) return 1;
+ if (InitModuleNames()) return 1;
+
// we don't need events in the service mode
if (ServiceExists(MS_DB_SETSAFETYMODE)) {
hContactDeletedEvent = CreateHookableEvent(ME_DB_CONTACT_DELETED);
@@ -207,6 +207,7 @@ int CDb3Mmap::PrepareCheck() int CDb3Base::Start(DBCHeckCallback *callback)
{
cb = callback;
+ ReMap(0);
return ERROR_SUCCESS;
}
diff --git a/plugins/Db3x_mmap/src/init.cpp b/plugins/Db3x_mmap/src/init.cpp index e9810fabe4..8b1664d5aa 100644 --- a/plugins/Db3x_mmap/src/init.cpp +++ b/plugins/Db3x_mmap/src/init.cpp @@ -49,7 +49,7 @@ LIST<CDb3Mmap> g_Dbs(1, HandleKeySortT); // returns 0 if the profile is created, EMKPRF*
static int makeDatabase(const TCHAR *profile)
{
- std::auto_ptr<CDb3Mmap> db( new CDb3Mmap(profile));
+ std::auto_ptr<CDb3Mmap> db(new CDb3Mmap(profile));
if (db->Create() != ERROR_SUCCESS)
return EMKPRF_CREATEFAILED;
@@ -59,7 +59,7 @@ static int makeDatabase(const TCHAR *profile) // returns 0 if the given profile has a valid header
static int grokHeader(const TCHAR *profile)
{
- std::auto_ptr<CDb3Mmap> db( new CDb3Mmap(profile));
+ std::auto_ptr<CDb3Mmap> db(new CDb3Mmap(profile));
if (db->Load(true) != ERROR_SUCCESS)
return EGROKPRF_CANTREAD;
@@ -70,7 +70,7 @@ static int grokHeader(const TCHAR *profile) static MIDatabase* LoadDatabase(const TCHAR *profile)
{
// set the memory, lists & UTF8 manager
- mir_getLP( &pluginInfo );
+ mir_getLP(&pluginInfo);
std::auto_ptr<CDb3Mmap> db(new CDb3Mmap(profile));
if (db->Load(false) != ERROR_SUCCESS)
@@ -120,7 +120,7 @@ extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD miranda return &pluginInfo;
}
-extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = {MIID_DATABASE, MIID_LAST};
+extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_DATABASE, MIID_LAST };
extern "C" __declspec(dllexport) int Load(void)
{
|