From 43d03eb4a9ae474c4b3a184c212a181d7fc67820 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Mon, 25 May 2026 01:25:43 +0300 Subject: [PATCH] LibC: Add shm_open/shm_unlink These can just open files in /tmp/shm. no need for anything fancier --- userspace/libraries/LibC/sys/mman.cpp | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/userspace/libraries/LibC/sys/mman.cpp b/userspace/libraries/LibC/sys/mman.cpp index e750c299..c306c4be 100644 --- a/userspace/libraries/LibC/sys/mman.cpp +++ b/userspace/libraries/LibC/sys/mman.cpp @@ -1,5 +1,7 @@ +#include #include #include +#include #include #include @@ -43,10 +45,6 @@ int posix_madvise(void* addr, size_t len, int advice) return 0; } -#include -#include -#include - int mlock(const void* addr, size_t len) { (void)addr; @@ -63,18 +61,16 @@ int munlock(const void* addr, size_t len) int shm_open(const char* name, int oflag, mode_t mode) { - (void)name; - (void)oflag; - (void)mode; - dwarnln("TODO: shm_open"); - errno = ENOTSUP; - return -1; + if (mkdir("/tmp/shm", 0777) == -1 && errno != EEXIST) + return -1; + char path[PATH_MAX]; + sprintf(path, "/tmp/shm%s", name); + return open(path, oflag | O_CLOEXEC, mode); } int shm_unlink(const char* name) { - (void)name; - dwarnln("TODO: shm_unlink"); - errno = ENOTSUP; - return -1; + char path[PATH_MAX]; + sprintf(path, "/tmp/shm%s", name); + return unlink(path); }