From owner-freebsd-hackers@FreeBSD.ORG Tue Jan 18 18:55:06 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 2F7F216A4CE for ; Tue, 18 Jan 2005 18:55:06 +0000 (GMT) Received: from web52709.mail.yahoo.com (web52709.mail.yahoo.com [206.190.39.160]) by mx1.FreeBSD.org (Postfix) with SMTP id B171243D66 for ; Tue, 18 Jan 2005 18:55:05 +0000 (GMT) (envelope-from kamalpr@yahoo.com) Received: (qmail 61504 invoked by uid 60001); 18 Jan 2005 18:55:05 -0000 Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; b=Wz93Uceo+6ytOQIzvbortQRi0kIMfD8ODMnzbNUUFESmWqJ292zpaqKECTIZ1HXfyS+6bzMIsLjPwP69h0KeW5vLLuFtuUmSZ18hs0GR01hwJqcdANfn/zxUYMZziBFwzZi2S1J8jOMlAU0KVnN3ATzdbIdChNflVtQfsHeQ4Ps= ; Message-ID: <20050118185505.61502.qmail@web52709.mail.yahoo.com> Received: from [203.195.199.244] by web52709.mail.yahoo.com via HTTP; Tue, 18 Jan 2005 10:55:05 PST Date: Tue, 18 Jan 2005 10:55:05 -0800 (PST) From: "Kamal R. Prasad" To: Zera William Holladay , freebsd-hackers@freebsd.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: Re: Kernel mode programming X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: kamalp@acm.org 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 18:55:06 -0000 --- 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, Zera > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to > "freebsd-hackers-unsubscribe@freebsd.org" > __________________________________ Do you Yahoo!? Yahoo! Mail - Helps protect you from nasty viruses. http://promotions.yahoo.com/new_mail