From owner-freebsd-hackers@FreeBSD.ORG Wed Jul 4 08:48:04 2007 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 38C5916A400 for ; Wed, 4 Jul 2007 08:48:04 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from cyrus.watson.org (cyrus.watson.org [209.31.154.42]) by mx1.freebsd.org (Postfix) with ESMTP id 0AD6B13C457 for ; Wed, 4 Jul 2007 08:48:03 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from fledge.watson.org (fledge.watson.org [209.31.154.41]) by cyrus.watson.org (Postfix) with ESMTP id 17B6D46B14; Wed, 4 Jul 2007 04:16:21 -0400 (EDT) Date: Wed, 4 Jul 2007 09:16:21 +0100 (BST) From: Robert Watson X-X-Sender: robert@fledge.watson.org To: Nicolas Cormier In-Reply-To: Message-ID: <20070704091349.T42421@fledge.watson.org> References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: freebsd-hackers@freebsd.org Subject: Re: p_vmspace in syscall X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Jul 2007 08:48:04 -0000 On Mon, 2 Jul 2007, Nicolas Cormier wrote: > I am trying to map some data allocated in kernel to a user process (via a > syscall). I need the proc's vmspace, but the value of p_vmspace of the input > proc argument is NULL ... How can I get a valid vmspace ? When operating in a system call, the 'td' argument to the system call function is the current thread pointer. You can follow td->td_proc to get to the current process (and therefore, its address space). In general, I prefer mapping user pages into kernel instead of kernel pages into user space, as it reduces the chances of leakage of kernel data to user space, and there are some useful primitives for making this easier. For example, take a look at the sf_buf infrastructure used for things like socket zero-copy send, which manages a temporary kernel mapping for a page. Robert N M Watson Computer Laboratory University of Cambridge