From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Jorge <griffin@gmx.es>, git@vger.kernel.org
Subject: [PATCH 1/4] read-cache.c: drop PROT_WRITE from mmap of index
Date: Thu, 28 May 2015 03:54:00 -0400 [thread overview]
Message-ID: <20150528075400.GA23395@peff.net> (raw)
In-Reply-To: <20150528075142.GB3688@peff.net>
Once upon a time, git's in-memory representation of a cache
entry actually pointed to the mmap'd on-disk data. So in
520fc24 (Allow writing to the private index file mapping.,
2005-04-26), we specified PROT_WRITE so that we could tweak
the entries while we run (in our own MAP_PRIVATE copy-on-write
version, of course).
Later, 7a51ed6 (Make on-disk index representation separate
from in-core one, 2008-01-14) stopped doing this; we copy
the data into our in-core representation, and then drop the
mmap immediately. We can therefore drop the PROT_WRITE flag.
It's probably not hurting anything as it is, but it's
potentially confusing.
Note that we could also mark the mapping as "const" to
verify that we never write to it. However, we don't
typically do that for our other maps, as it then requires
casting to munmap() it.
Signed-off-by: Jeff King <peff@peff.net>
---
This one obviously is not necessary for the rest of it, but just
something I noticed while writing my response to you. But read to the
end of the series; there might be a twist ending that brings it back!
read-cache.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/read-cache.c b/read-cache.c
index 723d48d..5dee4e2 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1562,7 +1562,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
if (mmap_size < sizeof(struct cache_header) + 20)
die("index file smaller than expected");
- mmap = xmmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
+ mmap = xmmap(NULL, mmap_size, PROT_READ, MAP_PRIVATE, fd, 0);
if (mmap == MAP_FAILED)
die_errno("unable to map index file");
close(fd);
--
2.4.2.668.gc3b1ade.dirty
next prev parent reply other threads:[~2015-05-28 7:54 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-27 13:29 Bug: .gitconfig folder Jorge
2015-05-27 20:30 ` Junio C Hamano
2015-05-27 22:18 ` Jeff King
2015-05-27 22:24 ` Stefan Beller
2015-05-28 6:13 ` Jeff King
2015-05-27 22:38 ` Junio C Hamano
2015-05-28 7:51 ` Jeff King
2015-05-28 7:54 ` Jeff King [this message]
2015-05-28 7:54 ` [PATCH 2/4] config.c: fix mmap leak when writing config Jeff King
2015-06-30 14:34 ` [PATCH] config.c: fix writing config files on Windows network shares Karsten Blees
2015-06-30 14:46 ` Torsten Bögershausen
2015-06-30 16:01 ` Jeff King
2015-06-30 14:52 ` Johannes Schindelin
2015-06-30 16:00 ` Jeff King
2015-05-28 7:56 ` [PATCH 3/4] config.c: avoid xmmap error messages Jeff King
2015-05-28 8:03 ` [PATCH 4/4] config.c: rewrite ENODEV into EISDIR when mmap fails Jeff King
2015-05-28 17:11 ` Junio C Hamano
2015-05-28 20:44 ` Jeff King
2015-05-28 21:11 ` Junio C Hamano
2015-05-28 17:06 ` Bug: .gitconfig folder Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150528075400.GA23395@peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=griffin@gmx.es \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).