passing arguments to a syscall KLD with syscall()

看板DFBSD_kernel作者時間21年前 (2004/12/04 09:32), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
This is a multi-part message in MIME format. --Multipart=_Fri__3_Dec_2004_17_10_00_-0800_yGNLKJxwFv9ITVX7 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Hi all, Apologies in advance if this is common knowledge and I missed it. I'm writing a small SYSCALL_MODULE KLD, mainly for my own education. I can load the module and call the syscall absolutely fine, no problems. I'm having problems passing arguments to the syscall, though. The code is attached - when the syscall is called, it doesn't seem to be able to get the things I pass to it in syscall(), it gets something else entirely when it looks at the stuff referenced by the uap pointer. I noticed the following comment in src/sys/i386/i386/trap.c: /* We don't handle the syscall() syscall yet */ I have almost zero familiarity with this code, but if this comment means what it appears to mean, it might explain why this doesn't work...? Anyway, any clarification about what's happening here would be greatly appreciated. Thanks, -Chris --Multipart=_Fri__3_Dec_2004_17_10_00_-0800_yGNLKJxwFv9ITVX7 Content-Type: text/plain; name="mykld.c" Content-Disposition: attachment; filename="mykld.c" Content-Transfer-Encoding: 7bit #include <sys/types.h> #include <sys/param.h> #include <sys/proc.h> #include <sys/module.h> #include <sys/sysent.h> #include <sys/kernel.h> #include <sys/systm.h> struct my_args { int x; }; static int my_syscall(struct my_args *uap) { printf("*** I was passed the integer: %d\n", uap->x); return(0); } static struct sysent my_sysent = { 1, /* sy_narg */ (sy_call_t *)my_syscall, /* sy_call */ NULL /* sy_abort */ }; static int offset = NO_SYSCALL; static int load(struct module *module, int cmd, void *arg) { int error = 0; switch (cmd) { case MOD_LOAD: printf("syscall loaded at %d\n", offset); break; case MOD_UNLOAD: printf("syscall unloaded from %d\n", offset); break; default: error = EINVAL; break; } return(error); } SYSCALL_MODULE(my_syscall, &offset, &my_sysent, load, NULL); --Multipart=_Fri__3_Dec_2004_17_10_00_-0800_yGNLKJxwFv9ITVX7 Content-Type: text/plain; name="userland.c" Content-Disposition: attachment; filename="userland.c" Content-Transfer-Encoding: 7bit #include <sys/types.h> #include <sys/syscall.h> #include <sys/module.h> #include <stdio.h> #include <sysexits.h> int main(int argc, char **argv) { char *end_ptr; int syscall_num, retval; struct module_stat stat; stat.version = sizeof(stat); if (modstat(modfind("my_syscall"), &stat) != 0) { err(EX_UNAVAILABLE, "modstat"); } syscall_num = stat.data.intval; retval = syscall(syscall_num, 100); printf("Return value was: %d\n", retval); exit(0); } --Multipart=_Fri__3_Dec_2004_17_10_00_-0800_yGNLKJxwFv9ITVX7 Content-Type: text/plain; name="Makefile" Content-Disposition: attachment; filename="Makefile" Content-Transfer-Encoding: 7bit SRCS = mykld.c KMOD = mykld KO = ${KMOD}.ko KLDMOD = t ..include <bsd.kmod.mk> --Multipart=_Fri__3_Dec_2004_17_10_00_-0800_yGNLKJxwFv9ITVX7--
文章代碼(AID): #11iHES00 (DFBSD_kernel)