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

[PATCH 1/4] read-cache.c: drop PROT_WRITE from mmap of index

From
Jeff King <peff@peff.net>
Date
May 28, 2015, 07:54 UTC
Message-ID
<20150528075400.GA23395@peff.net>
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
Previous: Jeff KingNext: Jeff King
Message 8 of 20 in “Bug: .gitconfig folder”
  1. JorgeMay 27, 2015
  2. Junio C HamanoMay 27, 2015
  3. Jeff KingMay 27, 2015
  4. Stefan BellerMay 27, 2015
  5. Jeff KingMay 28, 2015
  6. Junio C HamanoMay 27, 2015
  7. Jeff KingMay 28, 2015
  8. 1/4 read-cache.c: drop PROT_WRITE from mmap of indexJeff King, May 28, 2015
  9. 2/4 config.c: fix mmap leak when writing configJeff King, May 28, 2015
  10. config.c: fix writing config files on Windows network sharesKarsten Blees, Jun 30, 2015
  11. Torsten BögershausenJun 30, 2015
  12. Jeff KingJun 30, 2015
  13. Johannes SchindelinJun 30, 2015
  14. Jeff KingJun 30, 2015
  15. 3/4 config.c: avoid xmmap error messagesJeff King, May 28, 2015
  16. 4/4 config.c: rewrite ENODEV into EISDIR when mmap failsJeff King, May 28, 2015
  17. Junio C HamanoMay 28, 2015
  18. Jeff KingMay 28, 2015
  19. Junio C HamanoMay 28, 2015
  20. Junio C HamanoMay 28, 2015

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.