-
Notifications
You must be signed in to change notification settings - Fork 9
/
helpers.h
71 lines (53 loc) · 1.8 KB
/
helpers.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef HELPERS_H
#define HELPERS_H
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <alloca.h>
#include <stdint.h>
#include <math.h>
#include <linux/bpf.h>
#include <linux/lirc.h>
#include <linux/input.h>
#include <bpf/bpf.h>
#include <bpf/libbpf.h>
#include "db_types.h"
#define SYS_READ_XRP 445
#define NS_PER_SEC 1000000000
#define US_PER_NS 1000
#define aligned_alloca(align, size) (((uintptr_t) alloca((size) + (align) - 1) + ((align) - 1)) & ~ (uintptr_t) ((align) - 1));
long lookup_bpf(int db_fd, int bpf_fd, struct Query *query, ptr__t index_offset);
void checked_pread(int fd, void *buf, size_t size, long offset);
ptr__t nxt_node(unsigned long key, Node *node);
int key_exists(unsigned long key, Node const *node);
int _get_leaf_containing(int database_fd, key__t key, Node *node, ptr__t index_offset, ptr__t *node_offset);
int get_leaf_containing(int database_fd, key__t key, Node *node, ptr__t index_offset);
static inline long strtol_or_exit(char *str, char *fail_msg) {
char *endptr = NULL;
errno = 0;
long result = strtol(str, &endptr, 10);
if ((endptr != NULL && *endptr != '\0') || errno != 0) {
fprintf(stderr, "%s", fail_msg);
exit(1);
}
return result;
}
static inline unsigned long strtoul_or_exit(char *str, char *fail_msg) {
char *endptr = NULL;
errno = 0;
unsigned long result = strtoul(str, &endptr, 10);
if ((endptr != NULL && *endptr != '\0') || errno != 0) {
fprintf(stderr, "%s", fail_msg);
exit(1);
}
return result;
}
int compare_nodes(Node *x, Node *y);
long calculate_max_key(unsigned int layers);
int load_bpf_program(char *path);
#define BUG_ON(condition) \
do { \
if (condition) \
abort(); \
} while (0)
#endif /* HELPERS_H */