From dbef8d930c3aa6286805b8ea0bc2cf31913e2cbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 14 Dec 2004 17:09:06 +0000 Subject: [PATCH] As suggested by Ingo, the "subsystem" parameter is now a string. That allows modules to use their module name directly. Also introduced a whole range of reserved syscall functions in case we want to add some more. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10458 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/kernel/generic_syscall.h | 9 ++++--- headers/private/kernel/syscalls.h | 2 +- src/kernel/core/syscalls.c | 32 +++++++++++++++++------- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/headers/private/kernel/generic_syscall.h b/headers/private/kernel/generic_syscall.h index ec9b8c8f33..6595c6f0c0 100644 --- a/headers/private/kernel/generic_syscall.h +++ b/headers/private/kernel/generic_syscall.h @@ -13,10 +13,11 @@ * should be moved to KernelExport.h */ -typedef status_t (*syscall_hook)(uint32 subsystem, uint32 function, void *buffer, size_t bufferSize); +typedef status_t (*syscall_hook)(const char *subsystem, uint32 function, void *buffer, size_t bufferSize); /* predefined functions */ -#define B_SYSCALL_INFO ~0UL +#define B_RESERVED_SYSCALL_BASE 0x80000000 +#define B_SYSCALL_INFO (B_RESERVED_SYSCALL_BASE) // gets a minimum version uint32, and fills it with the current version on return /* syscall flags */ @@ -28,9 +29,9 @@ typedef status_t (*syscall_hook)(uint32 subsystem, uint32 function, void *buffer extern "C" { #endif -status_t register_generic_syscall(uint32 subsystem, syscall_hook hook, +status_t register_generic_syscall(const char *subsystem, syscall_hook hook, uint32 version, uint32 flags); -status_t unregister_generic_syscall(uint32 subsystem, uint32 version); +status_t unregister_generic_syscall(const char *subsystem, uint32 version); #ifdef __cplusplus } diff --git a/headers/private/kernel/syscalls.h b/headers/private/kernel/syscalls.h index 72783d70e8..fe058b8a6d 100644 --- a/headers/private/kernel/syscalls.h +++ b/headers/private/kernel/syscalls.h @@ -34,7 +34,7 @@ struct dirent; #endif extern int _kern_null(); -extern status_t _kern_generic_syscall(uint32 subsystem, uint32 function, +extern status_t _kern_generic_syscall(const char *subsystem, uint32 function, void *buffer, size_t bufferSize); extern int _kern_getrlimit(int resource, struct rlimit * rlp); diff --git a/src/kernel/core/syscalls.c b/src/kernel/core/syscalls.c index 4cb859c98f..59f117ec06 100644 --- a/src/kernel/core/syscalls.c +++ b/src/kernel/core/syscalls.c @@ -33,14 +33,16 @@ #include #include #include + #include +#include typedef struct generic_syscall generic_syscall; struct generic_syscall { list_link link; - uint32 subsystem; + char subsystem[B_FILE_NAME_LENGTH]; syscall_hook hook; uint32 version; uint32 flags; @@ -52,14 +54,14 @@ static struct list sGenericSyscalls; static generic_syscall * -find_generic_syscall(uint32 subsystem) +find_generic_syscall(const char *subsystem) { generic_syscall *syscall = NULL; ASSERT_LOCKED_MUTEX(&sGenericSyscallLock); while ((syscall = list_get_next_item(&sGenericSyscalls, syscall)) != NULL) { - if (syscall->subsystem == subsystem) + if (!strcmp(syscall->subsystem, subsystem)) return syscall; } @@ -75,12 +77,18 @@ find_generic_syscall(uint32 subsystem) */ static inline status_t -_user_generic_syscall(uint32 subsystem, uint32 function, void *buffer, size_t bufferSize) +_user_generic_syscall(const char *userSubsystem, uint32 function, + void *buffer, size_t bufferSize) { + char subsystem[B_FILE_NAME_LENGTH]; generic_syscall *syscall; status_t status; - dprintf("generic_syscall(subsystem = %lu, function = %lu)\n", subsystem, function); + if (!IS_USER_ADDRESS(userSubsystem) + || user_strlcpy(subsystem, userSubsystem, sizeof(subsystem)) < B_OK) + return B_BAD_ADDRESS; + + //dprintf("generic_syscall(subsystem = \"%s\", function = %lu)\n", subsystem, function); mutex_lock(&sGenericSyscallLock); @@ -90,7 +98,13 @@ _user_generic_syscall(uint32 subsystem, uint32 function, void *buffer, size_t bu goto out; } - if (function == B_SYSCALL_INFO) { + if (function >= B_RESERVED_SYSCALL_BASE) { + if (function != B_SYSCALL_INFO) { + // this is all we know + status = B_NAME_NOT_FOUND; + goto out; + } + // special info syscall if (bufferSize != sizeof(uint32)) status = B_BAD_VALUE; @@ -197,7 +211,7 @@ generic_syscall_init(void) status_t -register_generic_syscall(uint32 subsystem, syscall_hook hook, +register_generic_syscall(const char *subsystem, syscall_hook hook, uint32 version, uint32 flags) { struct generic_syscall *previous, *syscall; @@ -227,7 +241,7 @@ register_generic_syscall(uint32 subsystem, syscall_hook hook, goto out; } - syscall->subsystem = subsystem; + strlcpy(syscall->subsystem, subsystem, sizeof(syscall->subsystem)); syscall->hook = hook; syscall->version = version; syscall->flags = flags; @@ -246,7 +260,7 @@ out: status_t -unregister_generic_syscall(uint32 subsystem, uint32 version) +unregister_generic_syscall(const char *subsystem, uint32 version) { // ToDo: we should only remove the syscall with the matching version generic_syscall *syscall;