From owner-freebsd-questions Wed Feb 7 12:59:50 1996 Return-Path: owner-questions Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id MAA26258 for questions-outgoing; Wed, 7 Feb 1996 12:59:50 -0800 (PST) Received: from phaeton.artisoft.com (phaeton.Artisoft.COM [198.17.250.211]) by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id MAA26253 for ; Wed, 7 Feb 1996 12:59:46 -0800 (PST) Received: (from terry@localhost) by phaeton.artisoft.com (8.6.11/8.6.9) id NAA06368; Wed, 7 Feb 1996 13:57:21 -0700 From: Terry Lambert Message-Id: <199602072057.NAA06368@phaeton.artisoft.com> Subject: Re: your mail To: hunsoo@thebard.kci.co.kr (Hong Hunsoo) Date: Wed, 7 Feb 1996 13:57:21 -0700 (MST) Cc: questions@freebsd.org In-Reply-To: <199602071328.WAA11822@thebard.kci.co.kr> from "Hong Hunsoo" at Feb 7, 96 10:28:37 pm X-Mailer: ELM [version 2.4 PL24] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-questions@freebsd.org Precedence: bulk > I have some questions about kernel source codes. The followings are > my stupid questions. > > 1) Is it possible for me to insert a new system call without resulting > any trouble? That is, I want to know whether it is possible to insert a line > in /usr/src/sys/sys/syscall.h in my pleasure. > > #define SYS_my_new_system_call 8 > /* > * Here I selected 8 by the reason that /usr/src/sys/sys/syscall.h has a > * comment that ... 8 is old creat... > */ > I was always curious about the number, like 8 above, of a system call. I think > the only occurance of the number of a system call was through the syscall(2). > Is there anybody to explain me the significant role of the number?(in the case > of exit, 1; in the case of fork, 2; in the case of read, 3....) The system call "number" is an index into the sysent[] array. The correct way to deal with this is to modify /sys/kern/syscalls.master and config yourself a new kernel. That file is post-processed by the config process to build init_sysent.c, syscalls.c and syscall.h. It is incorrect to modify syscall.h, since it is a machine-generated file. Probably what you want to do instead is to use an LKM to add a vendor private system call. You can then query the /dev/lkm via ioctl to find your system call slot number, and then use the syscall(2) system call with that number and the normal call arguments to make the call to your new call from your vendor-suppied application. Actual modifications to the default system call list in syscalls.master are jealously guarded: they have to be. What you are suggesting is a permananet ABI change for what is, effectively, your personal call that perhaps no one else will ever use. [ ... simple call count statistics ... ] If this is for a profiling facility rather than for a ongoing hysterisis/AI mechanism for auto-tuning system resources, then you probably want to simply enable kernel profiling. Given a sufficiently large bucket size, it will cover all your system calls, as well as give you useful statistics, like "average time in call" and so on. Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers.