From 99f3cc26c3e69b0ad7f104cd20189cd6fd4c3cf1 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 8 Apr 2019 23:44:12 +0200 Subject: [PATCH] Kernel+LibC: Add stubs for POSIX shared memory API. Specifically shm_open() and shm_unlink(). This patch just adds stubs. --- Kernel/Process.cpp | 14 ++++++++++++++ Kernel/Process.h | 2 ++ Kernel/Syscall.cpp | 4 ++++ Kernel/Syscall.h | 2 ++ LibC/mman.cpp | 12 ++++++++++++ LibC/mman.h | 2 ++ 6 files changed, 36 insertions(+) diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 9638f6399b4..9c7612ed4db 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -2454,3 +2454,17 @@ int Process::sys$rename(const char* oldpath, const char* newpath) return -EFAULT; return VFS::the().rename(String(oldpath), String(newpath), cwd_inode()); } + +int Process::sys$shm_open(const char* name, int flags, mode_t mode) +{ + if (!validate_read_str(name)) + return -EFAULT; + return -ENOTIMPL; +} + +int Process::sys$shm_unlink(const char* name) +{ + if (!validate_read_str(name)) + return -EFAULT; + return -ENOTIMPL; +} diff --git a/Kernel/Process.h b/Kernel/Process.h index 14b5328cdc5..135fa7edcb5 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -99,6 +99,8 @@ public: int sys$gettid(); int sys$donate(int tid); + int sys$shm_open(const char* name, int flags, mode_t); + int sys$shm_unlink(const char* name); pid_t sys$setsid(); pid_t sys$getsid(pid_t); int sys$setpgid(pid_t pid, pid_t pgid); diff --git a/Kernel/Syscall.cpp b/Kernel/Syscall.cpp index cbba530e9b8..812cc7d8288 100644 --- a/Kernel/Syscall.cpp +++ b/Kernel/Syscall.cpp @@ -243,6 +243,10 @@ static dword handle(RegisterDump& regs, dword function, dword arg1, dword arg2, return current->process().sys$create_thread((int(*)(void*))arg1, (void*)arg2); case Syscall::SC_rename: return current->process().sys$rename((const char*)arg1, (const char*)arg2); + case Syscall::SC_shm_open: + return current->process().sys$shm_open((const char*)arg1, (int)arg2, (mode_t)arg3); + case Syscall::SC_shm_close: + return current->process().sys$shm_unlink((const char*)arg1); default: kprintf("<%u> int0x82: Unknown function %u requested {%x, %x, %x}\n", current->process().pid(), function, arg1, arg2, arg3); break; diff --git a/Kernel/Syscall.h b/Kernel/Syscall.h index f609e165532..b11a079d1e9 100644 --- a/Kernel/Syscall.h +++ b/Kernel/Syscall.h @@ -96,6 +96,8 @@ __ENUMERATE_SYSCALL(gettid) \ __ENUMERATE_SYSCALL(donate) \ __ENUMERATE_SYSCALL(rename) \ + __ENUMERATE_SYSCALL(shm_open) \ + __ENUMERATE_SYSCALL(shm_close) \ namespace Syscall { diff --git a/LibC/mman.cpp b/LibC/mman.cpp index 8cba6f83af7..174643712ba 100644 --- a/LibC/mman.cpp +++ b/LibC/mman.cpp @@ -28,4 +28,16 @@ int set_mmap_name(void* addr, size_t size, const char* name) __RETURN_WITH_ERRNO(rc, rc, -1); } +int shm_open(const char* name, int flags, mode_t mode) +{ + int rc = syscall(SC_shm_open, name, flags, mode); + __RETURN_WITH_ERRNO(rc, rc, -1); +} + +int shm_unlink(const char* name) +{ + int rc = syscall(SC_unlink, name); + __RETURN_WITH_ERRNO(rc, rc, -1); +} + } diff --git a/LibC/mman.h b/LibC/mman.h index a2a6ca372c6..0defe16763b 100644 --- a/LibC/mman.h +++ b/LibC/mman.h @@ -21,6 +21,8 @@ __BEGIN_DECLS void* mmap(void* addr, size_t, int prot, int flags, int fd, off_t); int munmap(void*, size_t); int set_mmap_name(void*, size_t, const char*); +int shm_open(const char* name, int flags, mode_t); +int shm_unlink(const char* name); __END_DECLS