line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
/* |
2
|
|
|
|
|
|
|
* Copyright (C) the libgit2 contributors. All rights reserved. |
3
|
|
|
|
|
|
|
* |
4
|
|
|
|
|
|
|
* This file is part of libgit2, distributed under the GNU GPL v2 with |
5
|
|
|
|
|
|
|
* a Linking Exception. For full terms see the included COPYING file. |
6
|
|
|
|
|
|
|
*/ |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#include "git2_util.h" |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#if !defined(GIT_WIN32) && !defined(NO_MMAP) |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
#include "map.h" |
13
|
|
|
|
|
|
|
#include |
14
|
|
|
|
|
|
|
#include |
15
|
|
|
|
|
|
|
#include |
16
|
|
|
|
|
|
|
|
17
|
87
|
|
|
|
|
|
int git__page_size(size_t *page_size) |
18
|
|
|
|
|
|
|
{ |
19
|
87
|
|
|
|
|
|
long sc_page_size = sysconf(_SC_PAGE_SIZE); |
20
|
87
|
50
|
|
|
|
|
if (sc_page_size < 0) { |
21
|
0
|
|
|
|
|
|
git_error_set(GIT_ERROR_OS, "can't determine system page size"); |
22
|
0
|
|
|
|
|
|
return -1; |
23
|
|
|
|
|
|
|
} |
24
|
87
|
|
|
|
|
|
*page_size = (size_t) sc_page_size; |
25
|
87
|
|
|
|
|
|
return 0; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
int git__mmap_alignment(size_t *alignment) |
29
|
|
|
|
|
|
|
{ |
30
|
0
|
|
|
|
|
|
return git__page_size(alignment); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
60
|
|
|
|
|
|
int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, off64_t offset) |
34
|
|
|
|
|
|
|
{ |
35
|
60
|
|
|
|
|
|
int mprot = PROT_READ; |
36
|
60
|
|
|
|
|
|
int mflag = 0; |
37
|
|
|
|
|
|
|
|
38
|
60
|
50
|
|
|
|
|
GIT_MMAP_VALIDATE(out, len, prot, flags); |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
60
|
|
|
|
|
|
out->data = NULL; |
41
|
60
|
|
|
|
|
|
out->len = 0; |
42
|
|
|
|
|
|
|
|
43
|
60
|
50
|
|
|
|
|
if (prot & GIT_PROT_WRITE) |
44
|
0
|
|
|
|
|
|
mprot |= PROT_WRITE; |
45
|
|
|
|
|
|
|
|
46
|
60
|
50
|
|
|
|
|
if ((flags & GIT_MAP_TYPE) == GIT_MAP_SHARED) |
47
|
60
|
|
|
|
|
|
mflag = MAP_SHARED; |
48
|
0
|
0
|
|
|
|
|
else if ((flags & GIT_MAP_TYPE) == GIT_MAP_PRIVATE) |
49
|
0
|
|
|
|
|
|
mflag = MAP_PRIVATE; |
50
|
|
|
|
|
|
|
else |
51
|
0
|
|
|
|
|
|
mflag = MAP_SHARED; |
52
|
|
|
|
|
|
|
|
53
|
60
|
|
|
|
|
|
out->data = mmap(NULL, len, mprot, mflag, fd, offset); |
54
|
|
|
|
|
|
|
|
55
|
60
|
50
|
|
|
|
|
if (!out->data || out->data == MAP_FAILED) { |
|
|
50
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
git_error_set(GIT_ERROR_OS, "failed to mmap. Could not write data"); |
57
|
0
|
|
|
|
|
|
return -1; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
60
|
|
|
|
|
|
out->len = len; |
61
|
|
|
|
|
|
|
|
62
|
60
|
|
|
|
|
|
return 0; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
60
|
|
|
|
|
|
int p_munmap(git_map *map) |
66
|
|
|
|
|
|
|
{ |
67
|
60
|
50
|
|
|
|
|
GIT_ASSERT_ARG(map); |
68
|
60
|
|
|
|
|
|
munmap(map->data, map->len); |
69
|
60
|
|
|
|
|
|
map->data = NULL; |
70
|
60
|
|
|
|
|
|
map->len = 0; |
71
|
|
|
|
|
|
|
|
72
|
60
|
|
|
|
|
|
return 0; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
#endif |
76
|
|
|
|
|
|
|
|