From owner-freebsd-hackers@FreeBSD.ORG Tue Jan 18 19:35:14 2005 Return-Path: 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 6365716A4CE for ; Tue, 18 Jan 2005 19:35:14 +0000 (GMT) Received: from smtpout-2.priv.cc.uic.edu (smtpout-2.cc.uic.edu [128.248.155.233]) by mx1.FreeBSD.org (Postfix) with SMTP id E970A43D5A for ; Tue, 18 Jan 2005 19:35:13 +0000 (GMT) (envelope-from zholla1@uic.edu) Received: (qmail 15140 invoked from network); 18 Jan 2005 13:35:13 -0600 Received: from icarus.cc.uic.edu (128.248.155.80) by smtpout-2.cc.uic.edu with SMTP; 18 Jan 2005 13:35:13 -0600 Date: Tue, 18 Jan 2005 13:35:13 -0600 (CST) From: Zera William Holladay X-X-Sender: zholla1@icarus.cc.uic.edu To: kamalp@acm.org In-Reply-To: <20050118185505.61502.qmail@web52709.mail.yahoo.com> Message-ID: References: <20050118185505.61502.qmail@web52709.mail.yahoo.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: freebsd-hackers@freebsd.org Subject: Re: Kernel mode programming X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Jan 2005 19:35:14 -0000 On Tue, 18 Jan 2005, Kamal R. Prasad wrote: > > --- Zera William Holladay wrote: > > > > > > [snip] > > > > My understanding is that when a system call is made > > from a user process, > > there is a trap into the kernel, the state of the > > user process is saved > > and the address of the system call is determined by > > a looking up the > > address of the system call in vector table. > > > Not exactly. When you execute a system call on the > kernel side, you execute it in the context of the > process. There is a per-process kernel stack -so you > don't save a copy of the process to execute the sys > call. > > > I assume that a kernel module would at least have to > > push the parameters > > of the system call, push some of its registers, jump > > to the address space > > of the system call and return. Further I assume, > > When you call another function from within the kernel, > it is like calling another function within userspace. > The args get pushed onto stack and there is space for > retval etc. > > > the kernel would have to > > copy the parameters of the system call to another > > address, since it is > > possible for the call to be interrupted and some of > > If the syscall is interrupted, it won't affect the > params as they will essentially be local variables in > the syscall. An interrupt handler won't corrupt the > args to the syscall for sure. > > > the parameters to be > > corrupted. > > > It is possible that the userspace may pass a pointer > which gets freed before the kernel is finished with > accessing it. That is why, a system call > implementation does a copyin() on entry and when it > wants to reflect the data to userspace, it does a > copyout(). > > > I am really asking a question out of blind ignorance > > in an attempt to > > learn more about what goes on with the kernel. What > > is the difference > > between a system call made from the kernel and a > > system call made from > > user code? > > > > The differece is that in one, you do a context switch > in one and in another you don't. The function names > change eg:- open() is syscall name, and underlying > function in kernel would be sys_open() -so from within > kernel, you call sys_open() instead of open() as in > userspace. > > regards > -kamal Thanks, that makes sense. -Zera