Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2006-12-24 08:47:23 +0300
committerJunio C Hamano <junkio@cox.net>2006-12-29 22:36:45 +0300
commitc4712e4553f13d87d655325a57538f299402d457 (patch)
treed09717f9d9a811d36ae5572b131a5b40e1dfcdcf /git-compat-util.h
parent97bfeb34df1aa8a1cf232278624a5a5c924ee380 (diff)
Replace mmap with xmmap, better handling MAP_FAILED.
In some cases we did not even bother to check the return value of mmap() and just assume it worked. This is bad, because if we are out of virtual address space the kernel returned MAP_FAILED and we would attempt to dereference that address, segfaulting without any real error output to the user. We are replacing all calls to mmap() with xmmap() and moving all MAP_FAILED checking into that single location. If a mmap call fails we try to release enough least-recently-used pack windows to possibly succeed, then retry the mmap() attempt. If we cannot mmap even after releasing pack memory then we die() as none of our callers have any reasonable recovery strategy for a failed mmap. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'git-compat-util.h')
-rw-r--r--git-compat-util.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/git-compat-util.h b/git-compat-util.h
index 0f856747e5..f243b86d32 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -188,6 +188,19 @@ static inline void *xcalloc(size_t nmemb, size_t size)
return ret;
}
+static inline void *xmmap(void *start, size_t length,
+ int prot, int flags, int fd, off_t offset)
+{
+ void *ret = mmap(start, length, prot, flags, fd, offset);
+ if (ret == MAP_FAILED) {
+ release_pack_memory(length);
+ ret = mmap(start, length, prot, flags, fd, offset);
+ if (ret == MAP_FAILED)
+ die("Out of memory? mmap failed: %s", strerror(errno));
+ }
+ return ret;
+}
+
static inline ssize_t xread(int fd, void *buf, size_t len)
{
ssize_t nr;