1 /* SPDX-License-Identifier: MIT */
2
3 #ifndef CONFIG_NOLIBC
4 #error "This file should only be compiled for no libc build"
5 #endif
6
7 #include "lib.h"
8 #include "syscall.h"
9
__uring_memset(void * s,int c,size_t n)10 void *__uring_memset(void *s, int c, size_t n)
11 {
12 size_t i;
13 unsigned char *p = s;
14
15 for (i = 0; i < n; i++) {
16 p[i] = (unsigned char) c;
17
18 /*
19 * An empty inline ASM to avoid auto-vectorization
20 * because it's too bloated for liburing.
21 */
22 __asm__ volatile ("");
23 }
24
25 return s;
26 }
27
28 struct uring_heap {
29 size_t len;
30 char user_p[] __attribute__((__aligned__));
31 };
32
__uring_malloc(size_t len)33 void *__uring_malloc(size_t len)
34 {
35 struct uring_heap *heap;
36
37 heap = __sys_mmap(NULL, sizeof(*heap) + len, PROT_READ | PROT_WRITE,
38 MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
39 if (IS_ERR(heap))
40 return NULL;
41
42 heap->len = sizeof(*heap) + len;
43 return heap->user_p;
44 }
45
__uring_free(void * p)46 void __uring_free(void *p)
47 {
48 struct uring_heap *heap;
49
50 if (uring_unlikely(!p))
51 return;
52
53 heap = container_of(p, struct uring_heap, user_p);
54 __sys_munmap(heap, heap->len);
55 }
56