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
memset(void * s,int c,size_t n)10 void *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 return s;
19 }
20
21 struct uring_heap {
22 size_t len;
23 char user_p[] __attribute__((__aligned__));
24 };
25
__uring_malloc(size_t len)26 void *__uring_malloc(size_t len)
27 {
28 struct uring_heap *heap;
29
30 heap = __sys_mmap(NULL, sizeof(*heap) + len, PROT_READ | PROT_WRITE,
31 MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
32 if (IS_ERR(heap))
33 return NULL;
34
35 heap->len = sizeof(*heap) + len;
36 return heap->user_p;
37 }
38
__uring_free(void * p)39 void __uring_free(void *p)
40 {
41 struct uring_heap *heap;
42
43 if (uring_unlikely(!p))
44 return;
45
46 heap = container_of(p, struct uring_heap, user_p);
47 __sys_munmap(heap, heap->len);
48 }
49