-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathmmapfd.h
40 lines (33 loc) · 893 Bytes
/
mmapfd.h
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
34
35
36
37
38
39
40
#ifndef NDNDPDK_CORE_MMAPFD_H
#define NDNDPDK_CORE_MMAPFD_H
/** @file */
#include "common.h"
/** @brief Memory map and file descriptor. */
typedef struct MmapFd {
void* map;
size_t size;
int fd;
} MmapFd;
/**
* @brief Create a file with memory map.
* @param size intended file size.
* @return whether success.
*/
__attribute__((nonnull)) bool
MmapFd_Open(MmapFd* m, const char* filename, size_t size);
/**
* @brief Close a file with memory map.
* @param size truncate to final file size.
* @return whether success.
*/
__attribute__((nonnull)) bool
MmapFd_Close(MmapFd* m, const char* filename, size_t size);
/**
* @brief Access mapped memory region.
* @pre @c MmapFd_Open was successful.
*/
__attribute__((nonnull, returns_nonnull)) __rte_always_inline void*
MmapFd_At(const MmapFd* m, size_t pos) {
return RTE_PTR_ADD(m->map, pos);
}
#endif // NDNDPDK_CORE_MMAPFD_H