From 9f561827ed260a6056780b25aed36de73b235ef0 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Wed, 18 Dec 2019 18:24:13 +0900 Subject: [PATCH] Add assembly stubs, definitions, and prototypes for mmap() and munmap() syscalls --- include/corax/syscall.h | 2 ++ include/sys/mman.h | 16 ++++++++++++++++ kernel/klibc/posixcall.S | 30 ++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 include/sys/mman.h diff --git a/include/corax/syscall.h b/include/corax/syscall.h index ba39618..ca456c2 100644 --- a/include/corax/syscall.h +++ b/include/corax/syscall.h @@ -24,6 +24,8 @@ #define SYS_SETSID 6 #define SYS_SLEEP 7 #define SYS_SBRK 8 +#define SYS_MMAP 9 +#define SYS_MUNMAP 10 /* Corax-specific variations of POSIX syscalls */ #define SYS_EXECFVE 128 diff --git a/include/sys/mman.h b/include/sys/mman.h new file mode 100644 index 0000000..fc27a03 --- /dev/null +++ b/include/sys/mman.h @@ -0,0 +1,16 @@ +#ifndef _SYS_MMAN_H +#define _SYS_MMAN_H + +#include + +#define PROT_READ (1 << 2) +#define PROT_WRITE (1 << 1) +#define PROT_EXEC (1 << 0) +#define PROT_NONE (0) + +#define MAP_PHYS (1 << 31) + +extern void* mmap(void*, size_t, int, int, int, size_t); +extern int munmap(void*, size_t); + +#endif /* _SYS_MMAN_H */ diff --git a/kernel/klibc/posixcall.S b/kernel/klibc/posixcall.S index f54608b..faa10f7 100644 --- a/kernel/klibc/posixcall.S +++ b/kernel/klibc/posixcall.S @@ -11,6 +11,8 @@ .global execfve .global brk .global sbrk + .global mmap + .global munmap fork: pushl %ebx @@ -61,4 +63,32 @@ sbrk: popl %ebx ret +mmap: + pushl %ebx + pushl %ebp + + movl $SYS_MMAP, %eax + movl 12(%esp), %ebx + movl 16(%esp), %ecx + movl 20(%esp), %edx + movl 24(%esp), %esi + movl 28(%esp), %edi + movl 32(%esp), %ebp + int $SYSCALL_POSIX + + popl %ebp + popl %ebx + ret + +munmap: + pushl %ebx + + movl $SYS_MUNMAP, %eax + movl 8(%esp), %ebx + movl 12(%esp), %ecx + int $SYSCALL_POSIX + + popl %ebx + ret + #endif /* FEATURE(POSIX) */ -- 2.47.3