vendor/libgit2/src/win32/map.c in rugged-0.24.0 vs vendor/libgit2/src/win32/map.c in rugged-0.24.5
- old
+ new
@@ -15,26 +15,45 @@
static DWORD page_size;
SYSTEM_INFO sys;
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;
DWORD off_hi = 0;
git_off_t page_start;
@@ -60,15 +79,15 @@
if (prot & GIT_PROT_WRITE)
view_prot |= FILE_MAP_WRITE;
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;
}
out->fmh = CreateFileMapping(fh, NULL, fmap_prot, 0, 0, NULL);
if (!out->fmh || out->fmh == INVALID_HANDLE_VALUE) {