summaryrefslogtreecommitdiff
path: root/src/user
diff options
context:
space:
mode:
authordzwdz2022-08-07 16:58:42 +0200
committerdzwdz2022-08-07 16:58:42 +0200
commitb962cd6062a08c063e6b10afaaa930956ee99e2d (patch)
tree215f5c0f5bf86a94dfc742ee365b8eba145a653f /src/user
parent93ce4f4248999adeb85c6859dc2b5c54d7a8d7b7 (diff)
user/libc: preparation for dlmalloc port
Diffstat (limited to 'src/user')
-rw-r--r--src/user/lib/include/stdlib.h2
-rw-r--r--src/user/lib/include/sys/mman.h18
-rw-r--r--src/user/lib/include/sys/types.h4
-rw-r--r--src/user/lib/mman.c24
-rw-r--r--src/user/lib/stdlib.c4
5 files changed, 52 insertions, 0 deletions
diff --git a/src/user/lib/include/stdlib.h b/src/user/lib/include/stdlib.h
index 5916ebc..de6e550 100644
--- a/src/user/lib/include/stdlib.h
+++ b/src/user/lib/include/stdlib.h
@@ -3,3 +3,5 @@
void *malloc(size_t size);
void free(void *ptr);
+
+_Noreturn void abort(void);
diff --git a/src/user/lib/include/sys/mman.h b/src/user/lib/include/sys/mman.h
new file mode 100644
index 0000000..074ebe2
--- /dev/null
+++ b/src/user/lib/include/sys/mman.h
@@ -0,0 +1,18 @@
+#pragma once
+#include <camellia/flags.h>
+#include <sys/types.h>
+
+#define MMAP_UNSUPPORTED 0xFFFF
+
+#define PROT_EXEC 1
+#define PROT_NONE MMAP_UNSUPPORTED
+#define PROT_READ 1
+#define PROT_WRITE 1
+
+#define MAP_FIXED MMAP_UNSUPPORTED
+#define MAP_PRIVATE 0
+#define MAP_SHARED MMAP_UNSUPPORTED
+#define MAP_ANONYMOUS 1
+
+void *mmap(void *addr, size_t len, int prot, int flags, int fd, off_t off);
+int munmap(void *addr, size_t len);
diff --git a/src/user/lib/include/sys/types.h b/src/user/lib/include/sys/types.h
new file mode 100644
index 0000000..3bc3f7f
--- /dev/null
+++ b/src/user/lib/include/sys/types.h
@@ -0,0 +1,4 @@
+#pragma once
+#include <stddef.h>
+
+typedef long long off_t;
diff --git a/src/user/lib/mman.c b/src/user/lib/mman.c
new file mode 100644
index 0000000..b41b8ff
--- /dev/null
+++ b/src/user/lib/mman.c
@@ -0,0 +1,24 @@
+/* mmap() emulation */
+#include <camellia/syscalls.h>
+#include <errno.h>
+#include <sys/mman.h>
+
+void *mmap(void *addr, size_t len, int prot, int flags, int fd, off_t off) {
+ (void)fd; (void) off;
+ if ((flags & MMAP_UNSUPPORTED) == MMAP_UNSUPPORTED ||
+ (prot & MMAP_UNSUPPORTED) == MMAP_UNSUPPORTED ||
+ !(flags & MAP_ANONYMOUS))
+ {
+ errno = ENOSYS;
+ return NULL;
+ }
+
+ void *p = _syscall_memflag(addr, len, MEMFLAG_FINDFREE | MEMFLAG_PRESENT);
+ if (!p) errno = ENOMEM;
+ return p;
+}
+
+int munmap(void *addr, size_t len) {
+ _syscall_memflag(addr, len, 0);
+ return 0;
+}
diff --git a/src/user/lib/stdlib.c b/src/user/lib/stdlib.c
index 857b40e..94e12d3 100644
--- a/src/user/lib/stdlib.c
+++ b/src/user/lib/stdlib.c
@@ -45,3 +45,7 @@ int execv(const char *path, char *const argv[]) {
errno = EINVAL;
return -1;
}
+
+_Noreturn void abort(void) {
+ _syscall_exit(1);
+}