From owner-freebsd-hackers Fri Sep 28 10:49:27 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from milliways.chance.ru (milliways.chance.ru [195.190.107.35]) by hub.freebsd.org (Postfix) with ESMTP id 3BF1E37B40E for ; Fri, 28 Sep 2001 10:49:20 -0700 (PDT) Received: from do-labs.spb.ru (ppp-4.chance.ru [195.190.107.7]) by milliways.chance.ru (8.9.0/8.9.0) with SMTP id VAA28151 for ; Fri, 28 Sep 2001 21:49:10 +0400 (MSD) Received: (qmail 489 invoked by uid 1000); 28 Sep 2001 21:15:13 -0000 Date: Fri, 28 Sep 2001 21:15:13 +0000 From: Vladimir Dozen To: Robert Watson Cc: hackers@FreeBSD.org Subject: Re: calling open() from inside kernel Message-ID: <20010928211513.A294@eix.do-labs.spb.ru> References: <20010927234624.A403@eix.do-labs.spb.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.4i In-Reply-To: ; from rwatson@FreeBSD.org on Fri, Sep 28, 2001 at 08:29:10AM -0400 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG ehlo. > Generally speaking, you don't want to invoke system call functionss from > within the kernel due to address space expectations, you want to invoke > the supporting service calls. Probably what that maps into in your case is > using NDINIT()/namei() on a string in UIO_SYSSPACE, and then using > vn_open(). You'll want to look carefully at the open() code to see if > there are other things to do/watch out for. That was exactly what I've done. The problem here is that each time someone in kernel space will try to open a file, he/she has to retype the same code already in vfs_syscalls.c. I would like to see more general version of open and two short wrappers -- one for userspace and one for kernel space, something like: /* generic */ open_generic(struct proc* proc,struct open_args* oa,boolean_t inkernel) { if( inkernel ) NDINIT(...,UIO_SYSSPACE,...); else NDINIT(...,UIO_USERSPACE,...); ... } /* user-space */ open(proc,oa){ return open_generic(proc,oa,0); } /* kernel space */ open_sysspace(proc,oa){ return open_generic(proc,oa,1); } Well, I see I was wanted too much. > In the Linux emulation code, when the kernel wants to change arguments > around and keep them in userspace, it uses space allocated out of the > stack gap, a section of VM I assume is otherwise unused in userspace (and > presumably is per-stack, or there would be problems with linux threading). This cure is more dangerous than illness itself. ;) -- dozen @ home To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message