blob: b216a7db857fb51f073fc7bf3e69358c1ed63d2f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
// SPDX-License-Identifier: GPL-2.0
#include <sys/mman.h>
#include <internal/mmap.h>
#include <internal/lib.h>
void perf_mmap__init(struct perf_mmap *map, bool overwrite)
{
map->fd = -1;
map->overwrite = overwrite;
refcount_set(&map->refcnt, 0);
}
size_t perf_mmap__mmap_len(struct perf_mmap *map)
{
return map->mask + 1 + page_size;
}
int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp,
int fd, int cpu)
{
map->prev = 0;
map->mask = mp->mask;
map->base = mmap(NULL, perf_mmap__mmap_len(map), mp->prot,
MAP_SHARED, fd, 0);
if (map->base == MAP_FAILED) {
map->base = NULL;
return -1;
}
map->fd = fd;
map->cpu = cpu;
return 0;
}
|