• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: MIT */
2 #ifndef LIBURING_LIB_H
3 #define LIBURING_LIB_H
4 
5 #include <stdlib.h>
6 #include <string.h>
7 #include <unistd.h>
8 
9 #if defined(__x86_64__) || defined(__i386__)
10 #include "arch/x86/lib.h"
11 #elif defined(__aarch64__)
12 #include "arch/aarch64/lib.h"
13 #elif defined(__riscv) && __riscv_xlen == 64
14 #include "arch/riscv64/lib.h"
15 #else
16 /*
17  * We don't have nolibc support for this arch. Must use libc!
18  */
19 #ifdef CONFIG_NOLIBC
20 #error "This arch doesn't support building liburing without libc"
21 #endif
22 /* libc wrappers. */
23 #include "arch/generic/lib.h"
24 #endif
25 
26 
27 #ifndef offsetof
28 #define offsetof(TYPE, FIELD) ((size_t) &((TYPE *)0)->FIELD)
29 #endif
30 
31 #ifndef container_of
32 #define container_of(PTR, TYPE, FIELD) ({			\
33 	__typeof__(((TYPE *)0)->FIELD) *__FIELD_PTR = (PTR);	\
34 	(TYPE *)((char *) __FIELD_PTR - offsetof(TYPE, FIELD));	\
35 })
36 #endif
37 
38 #define __maybe_unused		__attribute__((__unused__))
39 #define __hot			__attribute__((__hot__))
40 #define __cold			__attribute__((__cold__))
41 
42 #ifdef CONFIG_NOLIBC
43 void *__uring_memset(void *s, int c, size_t n);
44 void *__uring_malloc(size_t len);
45 void __uring_free(void *p);
46 
47 #define malloc(LEN)		__uring_malloc(LEN)
48 #define free(PTR)		__uring_free(PTR)
49 #define memset(PTR, C, LEN)	__uring_memset(PTR, C, LEN)
50 #endif
51 
52 #endif /* #ifndef LIBURING_LIB_H */
53