1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3 
4 #include <stdbool.h>
5 #include <sys/stat.h>
6 
7 /* One context per object type, plus one of the header, plus one "additional" one */
8 #define MMAP_CACHE_MAX_CONTEXTS 9
9 
10 typedef struct MMapCache MMapCache;
11 typedef struct MMapFileDescriptor MMapFileDescriptor;
12 
13 MMapCache* mmap_cache_new(void);
14 MMapCache* mmap_cache_ref(MMapCache *m);
15 MMapCache* mmap_cache_unref(MMapCache *m);
16 DEFINE_TRIVIAL_CLEANUP_FUNC(MMapCache*, mmap_cache_unref);
17 
18 int mmap_cache_fd_get(
19         MMapFileDescriptor *f,
20         unsigned context,
21         bool keep_always,
22         uint64_t offset,
23         size_t size,
24         struct stat *st,
25         void **ret);
26 MMapFileDescriptor* mmap_cache_add_fd(MMapCache *m, int fd, int prot);
27 MMapCache* mmap_cache_fd_cache(MMapFileDescriptor *f);
28 void mmap_cache_fd_free(MMapFileDescriptor *f);
29 
30 void mmap_cache_stats_log_debug(MMapCache *m);
31 
32 bool mmap_cache_fd_got_sigbus(MMapFileDescriptor *f);
33