summaryrefslogtreecommitdiff
path: root/src/lib.h
diff options
context:
space:
mode:
authorAmmar Faizi <ammarfaizi2@gnuweeb.org>2022-02-11 22:57:52 +0700
committerJens Axboe <axboe@kernel.dk>2022-02-11 09:36:16 -0700
commitc099b832a97dc1880b89734ef6a5420497a1be0f (patch)
tree678c09c507aa88dd6e5aff6b086739ac76cb103b /src/lib.h
parent8347a3d9553a2f31affddacb7bd9eaa14f2e7ed7 (diff)
downloadliburing-c099b832a97dc1880b89734ef6a5420497a1be0f.tar.gz
liburing-c099b832a97dc1880b89734ef6a5420497a1be0f.tar.bz2
lib.h: Split off lib header for arch specific and generic
1) Clean up #ifdef/#endif for get_page_size(). 2) Always use arch specific code for x86-64 to reduce libc usage. 3) For other archs, we will use src/arch/generic/lib.h header that contains libc wrapper. At this point, on x86-64, we only use libc for memset(), malloc() and free(). Cc: Nugra <richiisei@gmail.com> Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org> Link: https://lore.kernel.org/r/20220211155753.143698-4-ammarfaizi2@gnuweeb.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'src/lib.h')
-rw-r--r--src/lib.h45
1 files changed, 19 insertions, 26 deletions
diff --git a/src/lib.h b/src/lib.h
index bd02805..6672cc5 100644
--- a/src/lib.h
+++ b/src/lib.h
@@ -6,23 +6,31 @@
#include <string.h>
#include <unistd.h>
-#ifdef CONFIG_NOLIBC
-# if defined(__x86_64__) || defined(__i386__)
-# include "arch/x86/lib.h"
-# else
-# error "This arch doesn't support building liburing without libc"
-# endif
+#define __INTERNAL__LIBURING_LIB_H
+#if defined(__x86_64__) || defined(__i386__)
+ #include "arch/x86/lib.h"
+#else
+ /*
+ * We don't have nolibc support for this arch. Must use libc!
+ */
+ #ifdef CONFIG_NOLIBC
+ #error "This arch doesn't support building liburing without libc"
+ #endif
+ /* libc wrappers. */
+ #include "arch/generic/lib.h"
#endif
+#undef __INTERNAL__LIBURING_LIB_H
+
#ifndef offsetof
-# define offsetof(TYPE, FIELD) ((size_t) &((TYPE *)0)->FIELD)
+ #define offsetof(TYPE, FIELD) ((size_t) &((TYPE *)0)->FIELD)
#endif
#ifndef container_of
-# define container_of(PTR, TYPE, FIELD) ({ \
- __typeof__(((TYPE *)0)->FIELD) *__FIELD_PTR = (PTR); \
- (TYPE *)((char *) __FIELD_PTR - offsetof(TYPE, FIELD)); \
-})
+ #define container_of(PTR, TYPE, FIELD) ({ \
+ __typeof__(((TYPE *)0)->FIELD) *__FIELD_PTR = (PTR); \
+ (TYPE *)((char *) __FIELD_PTR - offsetof(TYPE, FIELD)); \
+ })
#endif
void *__uring_malloc(size_t len);
@@ -46,19 +54,4 @@ static inline void uring_free(void *ptr)
#endif
}
-static inline long get_page_size(void)
-{
-#ifdef CONFIG_NOLIBC
- return __arch_impl_get_page_size();
-#else
- long page_size;
-
- page_size = sysconf(_SC_PAGESIZE);
- if (page_size < 0)
- page_size = 4096;
-
- return page_size;
-#endif
-}
-
#endif /* #ifndef LIBURING_LIB_H */