From 1d356923da6203766da1a8f82ec4cf337a0ecb09 Mon Sep 17 00:00:00 2001 From: julianuziemblo Date: Tue, 17 Mar 2026 11:32:22 +0100 Subject: [PATCH 1/2] !syscalls: add sys_portUnregister syscall The functionality is there, but was previously unused. It can now be useful wit new `remove_dev()` userspace function that will cal it if there's no filesystem. YT: RTOS-1254 --- include/syscalls.h | 1 + proc/name.c | 8 +++++--- proc/name.h | 2 +- syscalls.c | 17 +++++++++++++++++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/include/syscalls.h b/include/syscalls.h index 6ff5b4d0f..c44ebae5d 100644 --- a/include/syscalls.h +++ b/include/syscalls.h @@ -48,6 +48,7 @@ ID(portCreate) \ ID(portDestroy) \ ID(portRegister) \ + ID(sys_portUnregister) \ ID(msgSend) \ ID(msgRecv) \ ID(msgRespond) \ diff --git a/proc/name.c b/proc/name.c index 1ce40ab12..2da60b3bf 100644 --- a/proc/name.c +++ b/proc/name.c @@ -113,7 +113,7 @@ int proc_portRegister(unsigned int port, const char *name, oid_t *oid) } -void proc_portUnregister(const char *name) +int proc_portUnregister(const char *name) { dcache_entry_t *entry, *prev = NULL; unsigned int hash = dcache_strHash(name); @@ -130,18 +130,20 @@ void proc_portUnregister(const char *name) if (entry == NULL) { /* There is no such entry, nothing to do */ (void)proc_lockClear(&name_common.dcache_lock); - return; + return -ENOENT; } if (prev != NULL) { prev->next = entry->next; } else { - name_common.dcache[hash] = NULL; + name_common.dcache[hash] = entry->next; } (void)proc_lockClear(&name_common.dcache_lock); vm_kfree(entry); + + return EOK; } diff --git a/proc/name.h b/proc/name.h index a89084ded..18cf2650f 100644 --- a/proc/name.h +++ b/proc/name.h @@ -22,7 +22,7 @@ int proc_portRegister(u32 port, const char *name, oid_t *oid); -void proc_portUnregister(const char *name); +int proc_portUnregister(const char *name); int proc_portLookup(const char *name, oid_t *file, oid_t *dev); diff --git a/syscalls.c b/syscalls.c index f609af5cc..05eb4b329 100644 --- a/syscalls.c +++ b/syscalls.c @@ -779,6 +779,23 @@ int syscalls_portRegister(u8 *ustack) } +int syscalls_sys_portUnregister(u8 *ustack) +{ + process_t *proc = proc_current()->process; + const char *name; + size_t len; + + GETFROMSTACK(ustack, const char *, name, 0U); + GETFROMSTACK(ustack, size_t, len, 1U); + + if (vm_mapBelongs(proc, name, len) < 0) { + return -EFAULT; + } + + return proc_portUnregister(name); +} + + int syscalls_msgSend(u8 *ustack) { process_t *proc = proc_current()->process; From d575864c914169611e8f9ce58ae791f3cf8cbdcb Mon Sep 17 00:00:00 2001 From: julianuziemblo Date: Tue, 17 Mar 2026 11:34:44 +0100 Subject: [PATCH 2/2] !syscalls/portRegister: pass string len from userspace YT: RTOS-1254 --- include/syscalls.h | 2 +- syscalls.c | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/include/syscalls.h b/include/syscalls.h index c44ebae5d..b4c1a066d 100644 --- a/include/syscalls.h +++ b/include/syscalls.h @@ -47,7 +47,7 @@ ID(interrupt) \ ID(portCreate) \ ID(portDestroy) \ - ID(portRegister) \ + ID(sys_portRegister) \ ID(sys_portUnregister) \ ID(msgSend) \ ID(msgRecv) \ diff --git a/syscalls.c b/syscalls.c index 05eb4b329..973b47e32 100644 --- a/syscalls.c +++ b/syscalls.c @@ -758,23 +758,27 @@ void syscalls_portDestroy(u8 *ustack) } -int syscalls_portRegister(u8 *ustack) +int syscalls_sys_portRegister(u8 *ustack) { process_t *proc = proc_current()->process; - unsigned int port; - char *name; + u32 port; + const char *name; + size_t len; oid_t *oid; - GETFROMSTACK(ustack, unsigned int, port, 0U); - GETFROMSTACK(ustack, char *, name, 1U); - GETFROMSTACK(ustack, oid_t *, oid, 2U); - - /* FIXME: Pass strlen(name) from userspace */ + GETFROMSTACK(ustack, u32, port, 0U); + GETFROMSTACK(ustack, const char *, name, 1U); + GETFROMSTACK(ustack, size_t, len, 2U); + GETFROMSTACK(ustack, oid_t *, oid, 3U); if (vm_mapBelongs(proc, oid, sizeof(*oid)) < 0) { return -EFAULT; } + if (vm_mapBelongs(proc, name, len) < 0) { + return -EFAULT; + } + return proc_portRegister(port, name, oid); }