diff --git a/include/syscalls.h b/include/syscalls.h index 6ff5b4d0f..b4c1a066d 100644 --- a/include/syscalls.h +++ b/include/syscalls.h @@ -47,7 +47,8 @@ ID(interrupt) \ ID(portCreate) \ ID(portDestroy) \ - ID(portRegister) \ + ID(sys_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..973b47e32 100644 --- a/syscalls.c +++ b/syscalls.c @@ -758,27 +758,48 @@ 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); } +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;