From owner-freebsd-hackers Tue Jul 29 19:56:33 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id TAA01925 for hackers-outgoing; Tue, 29 Jul 1997 19:56:33 -0700 (PDT) Received: from implode.root.com (implode.root.com [198.145.90.17]) by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id TAA01920 for ; Tue, 29 Jul 1997 19:56:31 -0700 (PDT) Received: from implode.root.com (localhost [127.0.0.1]) by implode.root.com (8.8.5/8.8.5) with ESMTP id TAA12085; Tue, 29 Jul 1997 19:57:42 -0700 (PDT) Message-Id: <199707300257.TAA12085@implode.root.com> To: Vinay Bannai cc: freebsd-hackers@FreeBSD.ORG Subject: Re: Location of copyin() and copyout().. In-reply-to: Your message of "Tue, 29 Jul 1997 19:27:30 PDT." <199707300227.TAA05696@agni.nuko.com> From: David Greenman Reply-To: dg@root.com Date: Tue, 29 Jul 1997 19:57:42 -0700 Sender: owner-freebsd-hackers@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk >So in a situation where I pin the user pages down (for DMA), it is okay to >use copyin()/copyout(). copyin/copyout can only be used at non-interrupt time while running in the context of the process to which you're copying to/from. Otherwise, you have to temporarily map the pages into the kernel address space, after which you can access them directly (i.e. not use copyin/copyout). Does this make sense? The main purpose of copyin/copyout is to provide a machine-independant mechanism for copying data through the kernel<->user protection domain. In the case of the x86, it just happens that user process memory is accessible to the kernel in the lower part of the address space, with one caveat: the i386 processor doesn't honor kernel (CPL 0/supervisor) write protection on pages and thus breaks COW when running in the kernel. So for the i386, copyout, if necessary, simulates a write fault to the affected pages. A secondary purpose of copyin/copyout is to catch page protection violations. There is a mechanism for catching a fatal page fault trap during a copyin/copyout so that the kernel can recover from such an event gracefully rather than crashing. When this happens, copyin/copyout return EFAULT to the caller. -DG David Greenman Core-team/Principal Architect, The FreeBSD Project