[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r432 - GNUnet/src/util/win
From: |
durner |
Subject: |
[GNUnet-SVN] r432 - GNUnet/src/util/win |
Date: |
Sun, 13 Mar 2005 12:36:29 -0800 (PST) |
Author: durner
Date: 2005-03-13 12:36:27 -0800 (Sun, 13 Mar 2005)
New Revision: 432
Modified:
GNUnet/src/util/win/winproc.c
Log:
Close mmap()ed files under Windows
Modified: GNUnet/src/util/win/winproc.c
===================================================================
--- GNUnet/src/util/win/winproc.c 2005-03-13 20:34:12 UTC (rev 431)
+++ GNUnet/src/util/win/winproc.c 2005-03-13 20:36:27 UTC (rev 432)
@@ -41,6 +41,11 @@
"Unknown resolver error" /* errno > 4 */
};
+typedef struct {
+ char *pStart;
+ HANDLE hMapping;
+} TMapping;
+
static char szRootDir[_MAX_PATH + 1];
static long lRootDirLen;
static char szHomeDir[_MAX_PATH + 2];
@@ -51,6 +56,9 @@
Winsock *pSocks;
HANDLE hSocksLock;
static char __langinfo[251];
+static unsigned int uiMappingsCount = 0;
+static TMapping *pMappings;
+HANDLE hMappingsLock;
static HINSTANCE hNTDLL, hIphlpapi, hAdvapi;
TNtQuerySystemInformation GNNtQuerySystemInformation;
@@ -550,6 +558,11 @@
pSocks[0].s = -1;
hSocksLock = CreateMutex(NULL, FALSE, NULL);
+ /* To keep track of mapped files */
+ pMappings = (TMapping *) malloc(sizeof(TMapping));
+ pMappings[0].pStart = NULL;
+ hMappingsLock = CreateMutex(NULL, FALSE, NULL);
+
/* Open files in binary mode */
_fmode = _O_BINARY;
@@ -632,6 +645,9 @@
free(pSocks);
CloseHandle(hSocksLock);
+ free(pMappings);
+ CloseHandle(hMappingsLock);
+
FreeLibrary(hNTDLL);
FreeLibrary(hIphlpapi);
FreeLibrary(hAdvapi);
@@ -1883,6 +1899,8 @@
HANDLE h, hFile;
SECURITY_ATTRIBUTES sec_none;
void *base;
+ BOOL bFound = FALSE;
+ unsigned int uiIndex;
errno = 0;
@@ -1938,6 +1956,42 @@
return (void *) -1;
}
+ /* Save mapping handle */
+ WaitForSingleObject(hMappingsLock, INFINITE);
+
+ for(uiIndex = 0; uiIndex <= uiMappingsCount; uiIndex++)
+ {
+ if (pMappings[uiIndex].pStart == base)
+ {
+ bFound = 1;
+ break;
+ }
+ }
+
+ if (! bFound)
+ {
+ uiIndex = 0;
+
+ while(TRUE)
+ {
+ if (pMappings[uiIndex].pStart == NULL)
+ {
+ pMappings[uiIndex].pStart = base;
+ pMappings[uiIndex].hMapping = h;
+ }
+ if (uiIndex == uiMappingsCount)
+ {
+ uiMappingsCount++;
+ pMappings = (TMapping *) realloc(pMappings, (uiMappingsCount + 1) *
sizeof(TMapping));
+ pMappings[uiMappingsCount].pStart = NULL;
+
+ break;
+ }
+ uiIndex++;
+ }
+ }
+ ReleaseMutex(hMappingsLock);
+
return base;
}
@@ -1948,9 +2002,31 @@
*/
int _win_munmap(void *start, size_t length)
{
+ unsigned uiIndex;
BOOL success = UnmapViewOfFile(start);
SetErrnoFromWinError(GetLastError());
+ if (success)
+ {
+ /* Release mapping handle */
+ WaitForSingleObject(hMappingsLock, INFINITE);
+
+ for(uiIndex = 0; uiIndex <= uiMappingsCount; uiIndex++)
+ {
+ if (pMappings[uiIndex].pStart == start)
+ {
+ success = CloseHandle(pMappings[uiIndex].hMapping);
+ SetErrnoFromWinError(GetLastError());
+ pMappings[uiIndex].pStart = NULL;
+ pMappings[uiIndex].hMapping = NULL;
+
+ break;
+ }
+ }
+
+ ReleaseMutex(hMappingsLock);
+ }
+
return success ? 0 : -1;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r432 - GNUnet/src/util/win,
durner <=