summaryrefslogtreecommitdiffstats
path: root/contrib/libs/liburing/src/nolibc.c
diff options
context:
space:
mode:
authorthegeorg <[email protected]>2023-07-26 17:26:21 +0300
committerthegeorg <[email protected]>2023-07-26 17:26:21 +0300
commit3785d5f97965bccf048718d8717904cf50f9f8f9 (patch)
treeb7ce8ae67d7eb7fcf7767c54379f0564c281147f /contrib/libs/liburing/src/nolibc.c
parent1f6b57071583f89299bb5abd3863d594f23c5be5 (diff)
Update contrib/libs/liburing to 2.4
Diffstat (limited to 'contrib/libs/liburing/src/nolibc.c')
-rw-r--r--contrib/libs/liburing/src/nolibc.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/contrib/libs/liburing/src/nolibc.c b/contrib/libs/liburing/src/nolibc.c
new file mode 100644
index 00000000000..22d23ec50df
--- /dev/null
+++ b/contrib/libs/liburing/src/nolibc.c
@@ -0,0 +1,56 @@
+#include "../config-host.h"
+/* SPDX-License-Identifier: MIT */
+
+#ifndef CONFIG_NOLIBC
+#error "This file should only be compiled for no libc build"
+#endif
+
+#include "lib.h"
+#include "syscall.h"
+
+void *__uring_memset(void *s, int c, size_t n)
+{
+ size_t i;
+ unsigned char *p = s;
+
+ for (i = 0; i < n; i++) {
+ p[i] = (unsigned char) c;
+
+ /*
+ * An empty inline ASM to avoid auto-vectorization
+ * because it's too bloated for liburing.
+ */
+ __asm__ volatile ("");
+ }
+
+ return s;
+}
+
+struct uring_heap {
+ size_t len;
+ char user_p[] __attribute__((__aligned__));
+};
+
+void *__uring_malloc(size_t len)
+{
+ struct uring_heap *heap;
+
+ heap = __sys_mmap(NULL, sizeof(*heap) + len, PROT_READ | PROT_WRITE,
+ MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+ if (IS_ERR(heap))
+ return NULL;
+
+ heap->len = sizeof(*heap) + len;
+ return heap->user_p;
+}
+
+void __uring_free(void *p)
+{
+ struct uring_heap *heap;
+
+ if (uring_unlikely(!p))
+ return;
+
+ heap = container_of(p, struct uring_heap, user_p);
+ __sys_munmap(heap, heap->len);
+}