Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 Sep 2001 08:29:10 -0400 (EDT)
From:      Robert Watson <rwatson@FreeBSD.org>
To:        Vladimir Dozen <vladimir-dozen@mail.ru>
Cc:        hackers@FreeBSD.org
Subject:   Re: calling open() from inside kernel
Message-ID:  <Pine.NEB.3.96L.1010928082423.31337D-100000@fledge.watson.org>
In-Reply-To: <20010927234624.A403@eix.do-labs.spb.ru>

next in thread | previous in thread | raw e-mail | index | archive | help

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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.NEB.3.96L.1010928082423.31337D-100000>