summaryrefslogtreecommitdiff
path: root/src/win32/map.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2016-03-16 19:05:11 +0100
committerCarlos Martín Nieto <cmn@dwim.me>2016-03-16 21:36:25 +0100
commit87c181970dbe629befa98aafeee75b2641dacf63 (patch)
treeaae18c85980ebbe346a30048e6c0bacfe61a3381 /src/win32/map.c
parent77394a27af283b366fa8bb444d29670131bfa104 (diff)
downloadlibgit2-cmn/pool-limit.tar.gz
Split the page size from the mmap alignmentcmn/pool-limit
While often similar, these are not the same on Windows. We want to use the page size on Windows for the pools, but for mmap we need to use the allocation granularity as the alignment. On the other platforms these values remain the same.
Diffstat (limited to 'src/win32/map.c')
-rw-r--r--src/win32/map.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/win32/map.c b/src/win32/map.c
index a99c30f7e..03a3646a6 100644
--- a/src/win32/map.c
+++ b/src/win32/map.c
@@ -17,22 +17,41 @@ static DWORD get_page_size(void)
if (!page_size) {
GetSystemInfo(&sys);
- page_size = sys.dwAllocationGranularity;
+ page_size = sys.dwPageSize;
}
return page_size;
}
+static DWORD get_allocation_granularity(void)
+{
+ static DWORD granularity;
+ SYSTEM_INFO sys;
+
+ if (!granularity) {
+ GetSystemInfo(&sys);
+ granularity = sys.dwAllocationGranularity;
+ }
+
+ return granularity;
+}
+
int git__page_size(size_t *page_size)
{
*page_size = get_page_size();
return 0;
}
+int git__mmap_alignment(size_t *page_size)
+{
+ *page_size = get_allocation_granularity();
+ return 0;
+}
+
int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset)
{
HANDLE fh = (HANDLE)_get_osfhandle(fd);
- DWORD page_size = get_page_size();
+ DWORD alignment = get_allocation_granularity();
DWORD fmap_prot = 0;
DWORD view_prot = 0;
DWORD off_low = 0;
@@ -62,12 +81,12 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs
if (prot & GIT_PROT_READ)
view_prot |= FILE_MAP_READ;
- page_start = (offset / page_size) * page_size;
+ page_start = (offset / alignment) * alignment;
page_offset = offset - page_start;
- if (page_offset != 0) { /* offset must be multiple of page size */
+ if (page_offset != 0) { /* offset must be multiple of the allocation granularity */
errno = EINVAL;
- giterr_set(GITERR_OS, "Failed to mmap. Offset must be multiple of page size");
+ giterr_set(GITERR_OS, "Failed to mmap. Offset must be multiple of allocation granularity");
return -1;
}