From owner-freebsd-hackers Fri Sep 28 5:29:55 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from fledge.watson.org (fledge.watson.org [204.156.12.50]) by hub.freebsd.org (Postfix) with ESMTP id D3D5F37B40C for ; Fri, 28 Sep 2001 05:29:46 -0700 (PDT) Received: from fledge.watson.org (robert@fledge.pr.watson.org [192.0.2.3]) by fledge.watson.org (8.11.6/8.11.5) with SMTP id f8SCTAB32080; Fri, 28 Sep 2001 08:29:11 -0400 (EDT) (envelope-from robert@fledge.watson.org) Date: Fri, 28 Sep 2001 08:29:10 -0400 (EDT) From: Robert Watson X-Sender: robert@fledge.watson.org To: Vladimir Dozen Cc: hackers@FreeBSD.org Subject: Re: calling open() from inside kernel In-Reply-To: <20010927234624.A403@eix.do-labs.spb.ru> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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 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. 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). Similar tricks could probably be played in the FreeBSD vm space, in a worst case scenario, by mmap'ing some space for the process. However, I would generally advise using the UIO_SYSPACE/vn_open() appraoch above. One final thing to note: name lookups occur with respects to a process's current working directory, and root directory--this means you need to think carefully about what process is present when invoking namei(), especially if there's likely to be lots of chroot()ing going on. Hope that helps, Robert N M Watson FreeBSD Core Team, TrustedBSD Project robert@fledge.watson.org NAI Labs, Safeport Network Services On Thu, 27 Sep 2001, Vladimir Dozen wrote: > ehlo. > > I'm creating a patch to kernel that requires to create a set > of files; names of files are generated inside kernel, i.e., > strings belong to kernel address space. > > Initially, I tried to use open(), but failed with EFAULT: open() > expects filename string is in userspace, and passes UIO_USERSPACE > to NDINIT. > > Well, I copied a portion of code from kern/vfs_syscalls, and it works > fine. But, the length and complexity of the code is too far beyond > I could expect from such a basic operation as file opening, and all > this just because single string is in wrong space. > > So, is there any way to call open() in simple way? Something like > remapping string into curproc space, or telling open() that string > is not in userspace, or smth else? Or, may be, I do something > completely wrong? I'm new in kernel programming. > > -- > dozen @ home > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-hackers" in the body of the message > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message