login
Header Space

 
 

Re: First cut at git port to Cygwin

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Junio C Hamano <junkio@...>
Cc: <git@...>, Linus Torvalds <torvalds@...>
Date: Saturday, October 8, 2005 - 6:06 pm

Hi,

On Sat, 8 Oct 2005, Junio C Hamano wrote:


How about this, then?

[PATCH] If NO_MMAP is defined, fake mmap() and munmap()

Since some platforms do not support mmap() at all, and others do only just so,
this patch introduces the option to fake mmap() and munmap() by malloc()ing the
region explicitely.

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>

---

 Makefile      |    6 ++++++
 cache.h       |   16 ++++++++++++++++
 compat/mmap.c |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 mailsplit.c   |    1 -
 4 files changed, 73 insertions(+), 1 deletions(-)
 create mode 100644 compat/mmap.c

applies-to: 274542bcbc891cca353c2728ac4075df3d1d2c0d
ed334e3e2276fe9d41ed78917544ef6a3fa87eb7
diff --git a/Makefile b/Makefile
index 1bdf4de..7ca77cf 100644
--- a/Makefile
+++ b/Makefile
@@ -27,6 +27,8 @@
 # Define NEEDS_SOCKET if linking with libc is not enough (SunOS,
 # Patrick Mauritz).
 #
+# Define NO_MMAP if you want to avoid mmap.
+#
 # Define WITH_OWN_SUBPROCESS_PY if you want to use with python 2.3.
 #
 # Define NO_IPV6 if you lack IPv6 support and getaddrinfo().
@@ -258,6 +260,10 @@ ifdef NO_STRCASESTR
 	DEFINES += -Dstrcasestr=gitstrcasestr
 	LIB_OBJS += compat/strcasestr.o
 endif
+ifdef NO_MMAP
+	DEFINES += -Dmmap=gitfakemmap -Dmunmap=gitfakemunmap -DNO_MMAP
+	LIB_OBJS += compat/mmap.o
+endif
 ifdef NO_IPV6
 	DEFINES += -DNO_IPV6 -Dsockaddr_storage=sockaddr_in
 endif
diff --git a/cache.h b/cache.h
index 514adb8..5987d4c 100644
--- a/cache.h
+++ b/cache.h
@@ -11,7 +11,9 @@
 #include <string.h>
 #include <errno.h>
 #include <limits.h>
+#ifndef NO_MMAP
 #include <sys/mman.h>
+#endif
 #include <sys/param.h>
 #include <netinet/in.h>
 #include <sys/types.h>
@@ -356,4 +358,18 @@ extern void packed_object_info_detail(st
 /* Dumb servers support */
 extern int update_server_info(int);
 
+#ifdef NO_MMAP
+
+#ifndef PROT_READ
+#define PROT_READ 1
+#define PROT_WRITE 2
+#define MAP_PRIVATE 1
+#define MAP_FAILED ((void*)-1)
+#endif
+
+extern void *gitfakemmap(void *start, size_t length, int prot , int flags, int fd, off_t offset);
+extern int gitfakemunmap(void *start, size_t length);
+
+#endif
+
 #endif /* CACHE_H */
diff --git a/compat/mmap.c b/compat/mmap.c
new file mode 100644
index 0000000..3f035a0
--- /dev/null
+++ b/compat/mmap.c
@@ -0,0 +1,51 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include "../cache.h"
+
+void *gitfakemmap(void *start, size_t length, int prot , int flags, int fd, off_t offset)
+{
+	int n = 0;
+
+	if(start != NULL || !(flags & MAP_PRIVATE))
+		die("Invalid usage of gitfakemmap.");
+
+	if(lseek(fd, offset, SEEK_SET)<0) {
+		errno = EINVAL;
+		return MAP_FAILED;
+	}
+
+	start = xmalloc(length);
+	if(start == NULL) {
+		errno = ENOMEM;
+		return MAP_FAILED;
+	}
+
+	while(n < length) {
+		int count = read(fd, start+n, length-n);
+
+		if(count == 0) {
+			memset(start+n, 0, length-n);
+			break;
+		}
+
+		if(count < 0) {
+			free(start);
+			errno = EACCES;
+			return MAP_FAILED;
+		}
+
+		n += count;
+	}
+
+	return start;
+}
+
+int gitfakemunmap(void *start, size_t length)
+{
+	free(start);
+
+	return 0;
+}
+
diff --git a/mailsplit.c b/mailsplit.c
index 7981f87..0f8100d 100644
--- a/mailsplit.c
+++ b/mailsplit.c
@@ -9,7 +9,6 @@
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/mman.h>
 #include <string.h>
 #include <stdio.h>
 #include <ctype.h>
---
0.99.8.GIT
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
First cut at git port to Cygwin, H. Peter Anvin, (Wed Sep 28, 8:53 pm)
Re: First cut at git port to Cygwin, Jonas Fonseca, (Wed Oct 5, 9:16 am)
Re: First cut at git port to Cygwin, Johannes Schindelin, (Wed Oct 5, 9:58 am)
[PATCH] Fix symbolic ref validation, Jonas Fonseca, (Wed Oct 5, 11:52 am)
Re: [PATCH] Fix symbolic ref validation, Junio C Hamano, (Wed Oct 5, 12:54 pm)
Re: First cut at git port to Cygwin, Alex Riesen, (Tue Oct 4, 8:31 am)
Re: First cut at git port to Cygwin, H. Peter Anvin, (Tue Oct 4, 11:03 am)
Re: First cut at git port to Cygwin, Alex Riesen, (Wed Oct 5, 7:24 am)
Re: First cut at git port to Cygwin, Alex Riesen, (Wed Oct 5, 11:46 am)
Re: First cut at git port to Cygwin, Christopher Faylor, (Wed Oct 5, 11:54 am)
Re: First cut at git port to Cygwin, Alex Riesen, (Wed Oct 5, 3:17 pm)
Re: First cut at git port to Cygwin, Christopher Faylor, (Wed Oct 5, 4:29 pm)
Re: First cut at git port to Cygwin, Alex Riesen, (Thu Oct 6, 5:05 am)
Re: First cut at git port to Cygwin, Alex Riesen, (Thu Oct 6, 6:07 am)
Re: First cut at git port to Cygwin, Alex Riesen, (Fri Oct 7, 8:44 am)
Re: First cut at git port to Cygwin, Linus Torvalds, (Fri Oct 7, 11:34 am)
Re: First cut at git port to Cygwin, Alex Riesen, (Fri Oct 7, 4:54 pm)
Re: First cut at git port to Cygwin, Alex Riesen, (Fri Oct 7, 5:22 pm)
Re: First cut at git port to Cygwin, Chuck Lever, (Fri Oct 7, 5:29 pm)
Re: First cut at git port to Cygwin, Alex Riesen, (Fri Oct 7, 5:39 pm)
Re: First cut at git port to Cygwin, Linus Torvalds, (Sat Oct 8, 12:11 pm)
Re: First cut at git port to Cygwin, Johannes Schindelin, (Sat Oct 8, 2:27 pm)
Re: First cut at git port to Cygwin, Alex Riesen, (Sat Oct 8, 2:49 pm)
Re: First cut at git port to Cygwin, Junio C Hamano, (Sat Oct 8, 2:44 pm)
Re: First cut at git port to Cygwin, H. Peter Anvin, (Mon Oct 10, 2:43 pm)
Re: First cut at git port to Cygwin, Johannes Schindelin, (Mon Oct 10, 3:01 pm)
Re: First cut at git port to Cygwin, Daniel Barkalow, (Mon Oct 10, 4:27 pm)
Re: First cut at git port to Cygwin, H. Peter Anvin, (Mon Oct 10, 3:26 pm)
Re: First cut at git port to Cygwin, Junio C Hamano, (Mon Oct 10, 4:34 pm)
Re: First cut at git port to Cygwin, H. Peter Anvin, (Mon Oct 10, 4:52 pm)
Re: First cut at git port to Cygwin, Junio C Hamano, (Mon Oct 10, 4:21 pm)
Re: First cut at git port to Cygwin, Johannes Schindelin, (Mon Oct 10, 3:42 pm)
Re: First cut at git port to Cygwin, Johannes Schindelin, (Sat Oct 8, 3:04 pm)
Re: First cut at git port to Cygwin, Junio C Hamano, (Sat Oct 8, 5:10 pm)
Re: First cut at git port to Cygwin, Johannes Schindelin, (Sat Oct 8, 6:06 pm)
Re: First cut at git port to Cygwin, Elfyn McBratney, (Sat Oct 8, 1:43 pm)
Re: First cut at git port to Cygwin, Elfyn McBratney, (Sat Oct 8, 1:38 pm)
Re: First cut at git port to Cygwin, Davide Libenzi, (Wed Oct 5, 12:09 pm)
Re: First cut at git port to Cygwin, Christopher Faylor, (Wed Oct 5, 12:15 pm)
Re: First cut at git port to Cygwin, Davide Libenzi, (Wed Oct 5, 1:29 pm)
Re: First cut at git port to Cygwin, H. Peter Anvin, (Wed Oct 5, 12:23 pm)
Re: First cut at git port to Cygwin, Christopher Faylor, (Wed Oct 5, 12:28 pm)
Re: First cut at git port to Cygwin, Christopher Faylor, (Tue Oct 4, 11:16 pm)
Re: First cut at git port to Cygwin, H. Peter Anvin, (Wed Oct 5, 1:25 am)
Re: First cut at git port to Cygwin, H. Peter Anvin, (Tue Oct 4, 10:06 am)
Re: First cut at git port to Cygwin, Christopher Faylor, (Tue Oct 4, 11:15 pm)
Re: First cut at git port to Cygwin, Alex Riesen, (Tue Oct 4, 9:06 am)
Re: First cut at git port to Cygwin, Johannes Schindelin, (Thu Sep 29, 4:46 am)
Re: First cut at git port to Cygwin, H. Peter Anvin, (Thu Sep 29, 1:25 pm)
Re: First cut at git port to Cygwin, H. Peter Anvin, (Thu Sep 29, 12:11 pm)
Re: First cut at git port to Cygwin, Martin Langhoff, (Thu Sep 29, 12:46 am)
Re: First cut at git port to Cygwin, H. Peter Anvin, (Thu Sep 29, 2:19 am)
Re: First cut at git port to Cygwin, Junio C Hamano, (Thu Sep 29, 1:13 am)
Re: First cut at git port to Cygwin, Junio C Hamano, (Thu Sep 29, 12:30 am)
Re: First cut at git port to Cygwin, H. Peter Anvin, (Thu Sep 29, 1:07 am)
speck-geostationary