From owner-freebsd-hackers@FreeBSD.ORG Tue Sep 30 01:14:25 2003 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 45F5F16A4B3 for ; Tue, 30 Sep 2003 01:14:25 -0700 (PDT) Received: from stork.mail.pas.earthlink.net (stork.mail.pas.earthlink.net [207.217.120.188]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9416843FB1 for ; Tue, 30 Sep 2003 01:14:24 -0700 (PDT) (envelope-from tlambert2@mindspring.com) Received: from user-38lc1ac.dialup.mindspring.com ([209.86.5.76] helo=mindspring.com) by stork.mail.pas.earthlink.net with asmtp (SSLv3:RC4-MD5:128) (Exim 3.33 #1) id 1A4FeD-0004WO-00; Tue, 30 Sep 2003 01:14:17 -0700 Message-ID: <3F793B2F.F5CB8416@mindspring.com> Date: Tue, 30 Sep 2003 01:13:35 -0700 From: Terry Lambert X-Mailer: Mozilla 4.79 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: earthman References: <16244.53594.942762.784390@canoe.dclg.ca> <3F759589.9070700@mindspring.com> <811112091.20030929172247@inbox.ru> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-ELNK-Trace: b1a02af9316fbb217a47c185c03b154d40683398e744b8a40ec50d310886d6fd5f5b65725fbce8dd667c3043c0873f7e350badd9bab72f9c350badd9bab72f9c cc: freebsd-hackers@freebsd.org Subject: Re: user malloc from kernel X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Sep 2003 08:14:25 -0000 earthman wrote: > how to allocate some memory chunk > in user space memory from kernel code? > how to do it correctly? If your intent is to allocate a chunk of memory which is shared between your kernel and a single process in user space, the normal way of doing this is to allocate the memory to a device driver in the kernel, and then support mmap() on it to establish a user space mapping for the kernel allocated memory. In general, you must do this so that the memory is wired down in the kernel address space, so that if you attempt to access it in the kernel while the process you are interested in sharing with is swapped out, you do not segfault and trap-12 ("page not present") panic your kernel. If your intent is to share memory with every process in user space (e.g. similar to what some OS's use to implement zero system call gettimeofday() functions, etc.), then you want to allocate the memory in kernel space (still), make sure it's on a page boundary, and set the PG_G and PG_U bits on the page(s) in question. -- Terry