git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] mmap implementation for mingw.

From
Vasyl Vavrychuk <vvavrychuk@gmail.com>
Date
Nov 21, 2008, 02:50 UTC
Message-ID
<loom.20081121T024302-370@post.gmane.org>

Here is simple and restricted implementation of mmap using CreateFileMapping, MapViewOfFile.

---
 compat/mingw.c    |   27 +++++++++++++++++++++++++++
 compat/mingw.h    |    6 ++++++
 git-compat-util.h |    2 ++
 3 files changed, 35 insertions(+), 0 deletions(-)
diff --git a/compat/mingw.c b/compat/mingw.c
index b534a8a..a6a5081 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -994,3 +994,30 @@ void mingw_open_html(const char *unixpath)
 	printf("Launching default browser to display HTML ...\n");
 	ShellExecute(NULL, "open", htmlpath, NULL, "\\", 0);
 }
+
+void *mingw_mmap(void *start, size_t length, int prot, int flags, int fd, 
off_t offset)
+{
+	HANDLE handle;
+
+	if (start != NULL || !(flags & MAP_PRIVATE))
+		die("Invalid usage of mingw_mmap");
+
+	if (offset % getpagesize() != 0)
+		die("Offset does not match the memory allocation granularity");
+
+	handle = CreateFileMapping((HANDLE)_get_osfhandle(fd), NULL, 
PAGE_WRITECOPY,
+			0, 0, NULL);
+
+	if (handle != NULL) {
+		start = MapViewOfFile(handle, FILE_MAP_COPY, 0, offset, 
length);
+		CloseHandle(handle);
+	}
+
+	return start;
+}
+
+int mingw_munmap(void *start, size_t length)
+{
+	UnmapViewOfFile(start);
+	return 0;
+}
diff --git a/compat/mingw.h b/compat/mingw.h
index 4f275cb..1b2a098 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -183,6 +183,12 @@ static inline unsigned int git_ntohl(unsigned int x)
 sig_handler_t mingw_signal(int sig, sig_handler_t handler);
 #define signal mingw_signal
 
+void *mingw_mmap(void *start, size_t length, int prot, int flags, int fd, 
off_t offset);
+#define mmap mingw_mmap
+
+int mingw_munmap(void *start, size_t length);
+#define munmap mingw_munmap
+
 /*
  * ANSI emulation wrappers
  */
diff --git a/git-compat-util.h b/git-compat-util.h
index e20b1e8..8f3d070 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -175,10 +175,12 @@ static inline const char *skip_prefix(const char *str, 
const char *prefix)
 #define MAP_FAILED ((void*)-1)
 #endif
 
+#ifndef __MINGW32__
 #define mmap git_mmap
 #define munmap git_munmap
 extern void *git_mmap(void *start, size_t length, int prot, int flags, int fd, 
off_t offset);
 extern int git_munmap(void *start, size_t length);
+#endif
 
 /* This value must be multiple of (pagesize * 2) */
 #define DEFAULT_PACKED_GIT_WINDOW_SIZE (1 * 1024 * 1024)
-- 
1.5.6.1.1071.g76fb
Next: Johannes Sixt
Message 1 of 7 in “mmap implementation for mingw.”
  1. mmap implementation for mingw.Vasyl Vavrychuk, Nov 21, 2008
  2. Johannes SixtNov 21, 2008
  3. Vasyl' VavrychukNov 21, 2008
  4. Johannes SixtNov 21, 2008
  5. Johannes SchindelinNov 21, 2008
  6. Bryan DonlanNov 21, 2008
  7. Johannes SchindelinNov 21, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.