diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2014-10-27 10:39:45 +0100 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2014-10-27 10:39:45 +0100 |
commit | 177a29d8321ac2574973c2d63d77754abc85ede8 (patch) | |
tree | 1331c4c93be4983d2f99c900da3eb225ad7e5e39 | |
parent | aabe1e5a44301d33d4114a6bb370d79575864536 (diff) | |
parent | 62e562f92b45b6a9b124452f7de6b9e86a179224 (diff) | |
download | libgit2-177a29d8321ac2574973c2d63d77754abc85ede8.tar.gz |
Merge commit 'refs/pull/2366/head' of github.com:libgit2/libgit2
-rw-r--r-- | src/indexer.c | 12 | ||||
-rw-r--r-- | src/map.h | 1 | ||||
-rw-r--r-- | src/pool.c | 16 | ||||
-rw-r--r-- | src/pool.h | 2 | ||||
-rw-r--r-- | src/posix.c | 5 | ||||
-rw-r--r-- | src/posix.h | 2 | ||||
-rw-r--r-- | src/unix/map.c | 10 | ||||
-rw-r--r-- | src/win32/map.c | 5 |
8 files changed, 29 insertions, 24 deletions
diff --git a/src/indexer.c b/src/indexer.c index 010de329b..620e8186b 100644 --- a/src/indexer.c +++ b/src/indexer.c @@ -429,17 +429,21 @@ static void hash_partially(git_indexer *idx, const uint8_t *data, size_t size) static int write_at(git_indexer *idx, const void *data, git_off_t offset, size_t size) { git_file fd = idx->pack->mwf.fd; - long page_size = git__page_size(); - git_off_t page_start, page_offset; + size_t page_size; + size_t page_offset; + git_off_t page_start; unsigned char *map_data; git_map map; int error; assert(data && size); + if ((error = git__page_size(&page_size)) < 0) + return error; + /* the offset needs to be at the beginning of the a page boundary */ - page_start = (offset / page_size) * page_size; - page_offset = offset - page_start; + page_offset = offset % page_size; + page_start = offset - page_offset; if ((error = p_mmap(&map, page_offset + size, GIT_PROT_WRITE, GIT_MAP_SHARED, fd, page_start)) < 0) return error; @@ -42,6 +42,5 @@ typedef struct { /* memory mapped buffer */ extern int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset); extern int p_munmap(git_map *map); -extern long git__page_size(void); #endif /* INCLUDE_map_h__ */ diff --git a/src/pool.c b/src/pool.c index 30555273e..180643ca7 100644 --- a/src/pool.c +++ b/src/pool.c @@ -1,4 +1,5 @@ #include "pool.h" +#include "posix.h" #ifndef GIT_WIN32 #include <unistd.h> #endif @@ -305,17 +306,10 @@ uint32_t git_pool__system_page_size(void) static uint32_t size = 0; if (!size) { -#ifdef GIT_WIN32 - SYSTEM_INFO info; - GetSystemInfo(&info); - size = (uint32_t)info.dwPageSize; -#elif defined(__amigaos4__) - size = (uint32_t)4096; /* 4K as there is no global value we can query */ -#else - size = (uint32_t)sysconf(_SC_PAGE_SIZE); -#endif - - size -= 2 * sizeof(void *); /* allow space for malloc overhead */ + size_t page_size; + if (git__page_size(&page_size) < 0) + page_size = 4096; + size = page_size - 2 * sizeof(void *); /* allow space for malloc overhead */ } return size; diff --git a/src/pool.h b/src/pool.h index 5ac9b764f..b0007f315 100644 --- a/src/pool.h +++ b/src/pool.h @@ -143,8 +143,6 @@ extern uint32_t git_pool__full_pages(git_pool *pool); extern bool git_pool__ptr_in_pool(git_pool *pool, void *ptr); -extern uint32_t git_pool__system_page_size(void); - extern uint32_t git_pool__suggest_items_per_page(uint32_t item_size); #endif diff --git a/src/posix.c b/src/posix.c index 21b049e1b..d5e6875b5 100644 --- a/src/posix.c +++ b/src/posix.c @@ -206,10 +206,11 @@ int p_write(git_file fd, const void *buf, size_t cnt) #include "map.h" -long git__page_size(void) +int git__page_size(size_t *page_size) { /* dummy; here we don't need any alignment anyway */ - return 4096; + *page_size = 4096; + return 0; } diff --git a/src/posix.h b/src/posix.h index 71c403c2f..22f472c90 100644 --- a/src/posix.h +++ b/src/posix.h @@ -108,6 +108,8 @@ extern int p_creat(const char *path, mode_t mode); extern int p_getcwd(char *buffer_out, size_t size); extern int p_rename(const char *from, const char *to); +extern int git__page_size(size_t *page_size); + /** * Platform-dependent methods */ diff --git a/src/unix/map.c b/src/unix/map.c index 3d0cbbaf8..0a235d5a1 100644 --- a/src/unix/map.c +++ b/src/unix/map.c @@ -13,9 +13,15 @@ #include <unistd.h> #include <errno.h> -long git__page_size(void) +int git__page_size(size_t *page_size) { - return sysconf(_SC_PAGE_SIZE); + long sc_page_size = sysconf(_SC_PAGE_SIZE); + if (sc_page_size < 0) { + giterr_set_str(GITERR_OS, "Can't determine system page size"); + return -1; + } + *page_size = (size_t) sc_page_size; + return 0; } int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset) diff --git a/src/win32/map.c b/src/win32/map.c index ef83f882e..a99c30f7e 100644 --- a/src/win32/map.c +++ b/src/win32/map.c @@ -23,9 +23,10 @@ static DWORD get_page_size(void) return page_size; } -long git__page_size(void) +int git__page_size(size_t *page_size) { - return (long)get_page_size(); + *page_size = get_page_size(); + return 0; } int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset) |