-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathubpf_memory_pool.h
96 lines (66 loc) · 2.2 KB
/
ubpf_memory_pool.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
// Created by thomas on 12/03/20.
//
#ifndef UBPF_TOOLS_UBPF_MEMORY_POOL_H
#define UBPF_TOOLS_UBPF_MEMORY_POOL_H
#include "uthash.h"
typedef struct element {
void (*clean)(void *); /* used to clean data passed to the pointer if any */
struct element *prev; /* needed for a doubly-linked list only */
struct element *next; /* needed for singly- or doubly-linked lists */
size_t len;
int raw;
uint8_t data[0];
} mp_element_t;
struct mem_node {
UT_hash_handle hh;
uint32_t type;
uint32_t length;
mp_element_t *value;
};
struct mempool_data {
int length;
void *data;
};
// encapsulation for public header
// (hashmap macros should not be visible externally)
struct mem_pool {
struct mem_node *node;
// int list_node; // set to 1 if mem_mode->value is a list
};
struct mem_node_it {
struct mem_node *node;
mp_element_t *curr_element;
};
// end encapsulation
struct mem_pool_it_ {
struct mem_pool *pool; /* main memory pool */
struct mem_node *node; /* current node on which we iterate */
struct mem_node_it *it; /* current memory node iterator */
};
struct mem_pool_it {
struct mem_pool_it_ it;
};
struct mempool_iterator {
struct mem_pool *mp;
};
struct mem_pool *new_mempool(void);
int add_mempool(struct mem_pool *mp, uint32_t type, void (*cleanup)(void *),
uint32_t length, void *val, int raw);
void remove_mempool(struct mem_pool *mp, uint32_t type);
int get_mempool_data(struct mem_pool *mp, uint32_t type, struct mempool_data *data);
void delete_mempool(struct mem_pool *mp);
/**
* Get a "unique" key for the current memory pool
*/
uint32_t jhash_mempool(struct mem_pool *mp);
struct mem_pool_it *new_mempool_iterator(struct mem_pool *mp);
void delete_mempool_iterator(struct mem_pool_it *it);
void *next_mempool_iterator(struct mem_pool_it *it);
void delete_memnode_iterator(struct mem_node_it *it);
void remove_memnode(struct mem_pool *mp, struct mem_node *node);
void *memnode_next_element(struct mem_node_it *it);
int memnode_hasnext(struct mem_node_it *it);
int mempool_hasnext(struct mem_pool_it *it);
struct mem_node_it *new_memnode_iterator(struct mem_node *node);
#endif //UBPF_TOOLS_UBPF_MEMORY_POOL_H