Add __rseq_percpu pointer tagging
[librseq.git] / include / rseq / percpu-alloc.h
1 /* SPDX-License-Identifier: MIT */
2 /* SPDX-FileCopyrightText: 2024 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> */
3
4 #ifndef _RSEQ_PERCPU_ALLOC_H
5 #define _RSEQ_PERCPU_ALLOC_H
6
7 #include <stddef.h>
8 #include <sys/types.h>
9 #include <sys/mman.h>
10
11 /*
12 * rseq/percpu-alloc.h
13 */
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 /*
20 * Tag pointers returned by:
21 * - rseq_percpu_malloc(),
22 * - rseq_percpu_zmalloc(),
23 * - rseq_percpu_pool_set_malloc(),
24 * - rseq_percpu_pool_set_zmalloc().
25 *
26 * with __rseq_percpu for use by static analyzers.
27 */
28 #define __rseq_percpu
29
30 struct rseq_percpu_pool;
31
32 struct rseq_percpu_pool *rseq_percpu_pool_create(size_t item_len,
33 size_t percpu_len, int max_nr_cpus,
34 int mmap_prot, int mmap_flags, int mmap_fd, off_t mmap_offset,
35 int numa_flags);
36 int rseq_percpu_pool_destroy(struct rseq_percpu_pool *pool);
37
38 void __rseq_percpu *rseq_percpu_malloc(struct rseq_percpu_pool *pool);
39 void __rseq_percpu *rseq_percpu_zmalloc(struct rseq_percpu_pool *pool);
40 void rseq_percpu_free(void __rseq_percpu *ptr);
41
42 void *__rseq_percpu_ptr(void __rseq_percpu *ptr, int cpu);
43
44 #define rseq_percpu_ptr(ptr, cpu) ((__typeof__(ptr)) __rseq_percpu_ptr(ptr, cpu))
45
46 struct rseq_percpu_pool_set *rseq_percpu_pool_set_create(void);
47 int rseq_percpu_pool_set_destroy(struct rseq_percpu_pool_set *pool_set);
48 int rseq_percpu_pool_set_add_pool(struct rseq_percpu_pool_set *pool_set,
49 struct rseq_percpu_pool *pool);
50
51 void __rseq_percpu *rseq_percpu_pool_set_malloc(struct rseq_percpu_pool_set *pool_set, size_t len);
52 void __rseq_percpu *rseq_percpu_pool_set_zmalloc(struct rseq_percpu_pool_set *pool_set, size_t len);
53
54 #ifdef __cplusplus
55 }
56 #endif
57
58 #endif /* _RSEQ_PERCPU_ALLOC_H */
This page took 0.031 seconds and 5 git commands to generate.