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 #define __INTERNAL__LIBURING_LIB_H 10 #if defined(__x86_64__) || defined(__i386__) 11 #include "arch/x86/lib.h" 12 #else 13 /* 14 * We don't have nolibc support for this arch. Must use libc! 15 */ 16 #ifdef CONFIG_NOLIBC 17 #error "This arch doesn't support building liburing without libc" 18 #endif 19 /* libc wrappers. */ 20 #include "arch/generic/lib.h" 21 #endif 22 #undef __INTERNAL__LIBURING_LIB_H 23 24 25 #ifndef offsetof 26 #define offsetof(TYPE, FIELD) ((size_t) &((TYPE *)0)->FIELD) 27 #endif 28 29 #ifndef container_of 30 #define container_of(PTR, TYPE, FIELD) ({ \ 31 __typeof__(((TYPE *)0)->FIELD) *__FIELD_PTR = (PTR); \ 32 (TYPE *)((char *) __FIELD_PTR - offsetof(TYPE, FIELD)); \ 33 }) 34 #endif 35 36 void *__uring_malloc(size_t len); 37 void __uring_free(void *p); 38 uring_malloc(size_t len)39static inline void *uring_malloc(size_t len) 40 { 41 #ifdef CONFIG_NOLIBC 42 return __uring_malloc(len); 43 #else 44 return malloc(len); 45 #endif 46 } 47 uring_free(void * ptr)48static inline void uring_free(void *ptr) 49 { 50 #ifdef CONFIG_NOLIBC 51 __uring_free(ptr); 52 #else 53 free(ptr); 54 #endif 55 } 56 57 #endif /* #ifndef LIBURING_LIB_H */ 58