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 "common.h" |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#include "git2/common.h" |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
#if !defined(GIT_WIN32) && !defined(NO_MMAP) |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
#include "map.h" |
15
|
|
|
|
|
|
|
#include |
16
|
|
|
|
|
|
|
#include |
17
|
|
|
|
|
|
|
#include |
18
|
|
|
|
|
|
|
|
19
|
209
|
|
|
|
|
|
int git__page_size(size_t *page_size) |
20
|
|
|
|
|
|
|
{ |
21
|
209
|
|
|
|
|
|
long sc_page_size = sysconf(_SC_PAGE_SIZE); |
22
|
209
|
50
|
|
|
|
|
if (sc_page_size < 0) { |
23
|
0
|
|
|
|
|
|
git_error_set(GIT_ERROR_OS, "can't determine system page size"); |
24
|
0
|
|
|
|
|
|
return -1; |
25
|
|
|
|
|
|
|
} |
26
|
209
|
|
|
|
|
|
*page_size = (size_t) sc_page_size; |
27
|
209
|
|
|
|
|
|
return 0; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
182
|
|
|
|
|
|
int git__mmap_alignment(size_t *alignment) |
31
|
|
|
|
|
|
|
{ |
32
|
182
|
|
|
|
|
|
return git__page_size(alignment); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
151
|
|
|
|
|
|
int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, off64_t offset) |
36
|
|
|
|
|
|
|
{ |
37
|
151
|
|
|
|
|
|
int mprot = PROT_READ; |
38
|
151
|
|
|
|
|
|
int mflag = 0; |
39
|
|
|
|
|
|
|
|
40
|
151
|
50
|
|
|
|
|
GIT_MMAP_VALIDATE(out, len, prot, flags); |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
151
|
|
|
|
|
|
out->data = NULL; |
43
|
151
|
|
|
|
|
|
out->len = 0; |
44
|
|
|
|
|
|
|
|
45
|
151
|
100
|
|
|
|
|
if (prot & GIT_PROT_WRITE) |
46
|
91
|
|
|
|
|
|
mprot |= PROT_WRITE; |
47
|
|
|
|
|
|
|
|
48
|
151
|
50
|
|
|
|
|
if ((flags & GIT_MAP_TYPE) == GIT_MAP_SHARED) |
49
|
151
|
|
|
|
|
|
mflag = MAP_SHARED; |
50
|
0
|
0
|
|
|
|
|
else if ((flags & GIT_MAP_TYPE) == GIT_MAP_PRIVATE) |
51
|
0
|
|
|
|
|
|
mflag = MAP_PRIVATE; |
52
|
|
|
|
|
|
|
else |
53
|
0
|
|
|
|
|
|
mflag = MAP_SHARED; |
54
|
|
|
|
|
|
|
|
55
|
151
|
|
|
|
|
|
out->data = mmap(NULL, len, mprot, mflag, fd, offset); |
56
|
|
|
|
|
|
|
|
57
|
151
|
50
|
|
|
|
|
if (!out->data || out->data == MAP_FAILED) { |
|
|
50
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
git_error_set(GIT_ERROR_OS, "failed to mmap. Could not write data"); |
59
|
0
|
|
|
|
|
|
return -1; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
151
|
|
|
|
|
|
out->len = len; |
63
|
|
|
|
|
|
|
|
64
|
151
|
|
|
|
|
|
return 0; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
151
|
|
|
|
|
|
int p_munmap(git_map *map) |
68
|
|
|
|
|
|
|
{ |
69
|
151
|
50
|
|
|
|
|
assert(map != NULL); |
70
|
151
|
|
|
|
|
|
munmap(map->data, map->len); |
71
|
|
|
|
|
|
|
|
72
|
151
|
|
|
|
|
|
return 0; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
#endif |
76
|
|
|
|
|
|
|
|