aboutsummaryrefslogtreecommitdiff
path: root/src/lib.h
diff options
context:
space:
mode:
authorGil Cukierman <cukie@google.com>2022-10-31 14:08:03 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-10-31 14:08:03 +0000
commitdae12c7b40c255ad7c6612591e2908a266f2cfd5 (patch)
treeebe9c872e416346e4b333e5062da32401c8e0a73 /src/lib.h
parentd53db6851ea17b2d219d084e1afc683b8b62b105 (diff)
parentd0a2042580f3ed180db5e2b53029296a8b555115 (diff)
downloadliburing-dae12c7b40c255ad7c6612591e2908a266f2cfd5.tar.gz
Update liburing to version 2.2 am: d0a2042580main-16k-with-phones
Original change: https://android-review.googlesource.com/c/platform/external/liburing/+/2276974 Change-Id: I0ac5dbb2b0dadb76713528e6ab0110ec071bad63 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'src/lib.h')
-rw-r--r--src/lib.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/lib.h b/src/lib.h
new file mode 100644
index 0000000..6672cc5
--- /dev/null
+++ b/src/lib.h
@@ -0,0 +1,57 @@
+/* SPDX-License-Identifier: MIT */
+#ifndef LIBURING_LIB_H
+#define LIBURING_LIB_H
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#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)
+#endif
+
+#ifndef container_of
+ #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);
+void __uring_free(void *p);
+
+static inline void *uring_malloc(size_t len)
+{
+#ifdef CONFIG_NOLIBC
+ return __uring_malloc(len);
+#else
+ return malloc(len);
+#endif
+}
+
+static inline void uring_free(void *ptr)
+{
+#ifdef CONFIG_NOLIBC
+ __uring_free(ptr);
+#else
+ free(ptr);
+#endif
+}
+
+#endif /* #ifndef LIBURING_LIB_H */