From owner-freebsd-hackers@FreeBSD.ORG Thu Aug 11 17:50:06 2005 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 27F1D16A41F; Thu, 11 Aug 2005 17:50:06 +0000 (GMT) (envelope-from uvarovsl@mail.pnpi.spb.ru) Received: from mail.lsi.ru (mail.lsi.ru [212.58.192.30]) by mx1.FreeBSD.org (Postfix) with ESMTP id AF12043D46; Thu, 11 Aug 2005 17:50:05 +0000 (GMT) (envelope-from uvarovsl@mail.pnpi.spb.ru) Received: by mail.lsi.ru (Postfix, from userid 426) id 82E41386C84; Thu, 11 Aug 2005 21:50:02 +0400 (MSD) Received: from [10.0.0.10] (unknown [212.58.210.222]) by mail.lsi.ru (Postfix) with ESMTP id C327E386C2B; Thu, 11 Aug 2005 21:50:01 +0400 (MSD) Message-ID: <42FB8FCA.2050803@mail.pnpi.spb.ru> Date: Thu, 11 Aug 2005 21:50:02 +0400 From: Sergey Uvarov User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.10) Gecko/20050719 Fedora/1.7.10-1.5.1 X-Accept-Language: en-us, en MIME-Version: 1.0 To: John Baldwin References: <200508111616.j7BGGZWG055221@sora.hank.home> <200508111329.42154.jhb@FreeBSD.org> In-Reply-To: <200508111329.42154.jhb@FreeBSD.org> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-hackers@freebsd.org, Dirk GOUDERS Subject: Re: preferable way to control kernel module X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Aug 2005 17:50:06 -0000 John Baldwin wrote: > On Thursday 11 August 2005 12:16 pm, Dirk GOUDERS wrote: > >> > > Thank you for advise. But I wonder: what is wrong with syscall >> > > approach (via SYSCALL_MODULE macro)? >> > >> > I just haven't done one personally. I think there's also a lot more >> > potenti al >> > for collisions when trying to pick a syscall number versus picking a >> > string name for a sysctl or /dev entry. >> >>Shouldn't that be no problem if he sets the offset parameter to >>SYSCALL_MODULE to NO_SYSCALL (get the next free offset)? > > > But then you have to communicate the syscall number out to your userland > applications somehow, and the applications have to know how to invoke a > syscall by hand (perhaps they could use the syscall() function, but still). > It is not a big problem. Look at the following piece of code: /* Kernel module portion of code. */ static int my_syscall = NO_SYSCALL; static struct sysent my_sysent = { 2, /* sy_arg */ (sy_call_t *)&my_func /* sy_call */ }; SYSCALL_MODULE(my_syscall_name, &my_syscall, &my_sysent, NULL, NULL); /* User-land portion of code. */ int get_syscall(const char *syscall_name) { struct module_stat stat; int mod_id; int syscall_num; if ((mod_id = modfind(syscall_name)) < 0) return (-1); stat.version = sizeof(stat); if (modstat(mod_id, &stat) < 0) return (-1); return (stat.data.intval); } ... syscall_num = get_syscall("my_syscall_name"); /* Issue a syscall with necessary parameters. */ syscall(syscall_num, ...);