From owner-freebsd-hackers@FreeBSD.ORG Tue Nov 18 12:49:45 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 EC91E16A4CE for ; Tue, 18 Nov 2003 12:49:44 -0800 (PST) Received: from ms-smtp-01-eri0.socal.rr.com (ms-smtp-01-qfe0.socal.rr.com [66.75.162.133]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2705243FBD for ; Tue, 18 Nov 2003 12:49:44 -0800 (PST) (envelope-from sean@mcneil.com) Received: from blue.mcneil.com (cpe-66-75-176-109.socal.rr.com [66.75.176.109])hAIKnev1011926 for ; Tue, 18 Nov 2003 12:49:41 -0800 (PST) Received: from [66.75.176.109] (mcneil.com [66.75.176.109]) by blue.mcneil.com (8.12.10/8.12.10) with ESMTP id hAIKnZUe076305 for ; Tue, 18 Nov 2003 12:49:36 -0800 (PST) (envelope-from sean@mcneil.com) From: Sean McNeil To: freebsd-hackers@freebsd.org Content-Type: text/plain Organization: Sean McNeil Consulting Message-Id: <1069188575.76277.8.camel@blue.mcneil.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.5 Date: Tue, 18 Nov 2003 12:49:35 -0800 Content-Transfer-Encoding: 7bit X-DCC-Servercave-Metrics: blue.mcneil.com 1183; Body=1 Fuz1=1 Fuz2=1 X-Virus-Scanned: Symantec AntiVirus Scan Engine Subject: memory address space conversion 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, 18 Nov 2003 20:49:45 -0000 Hello all, I ask a while ago a question and received great response. I'm hoping to repeat the experience :) I have a driver that I cannot change the ioctl API to. Unfortunately, it has a peculiar need to return a user-space address based on the physical address. Here is the scenario: user calls mmap and gets a user-space mapping to a chunk of memory. user calls an ioctl that passes an array of user-space addresses inside that mapping. I had a hack working for the case of a single-threaded process, but it will not work in a threaded environment. Here is what I came up with: static vm_map_entry_t find_entry (vm_map_t map, vm_paddr_t address) { vm_map_entry_t entry; int i; for (i = 0, entry = &map->header; i < map->nentries; i++, entry = entry->next) { vm_page_t page; vm_paddr_t paddr; if (entry->eflags & MAP_ENTRY_IS_SUB_MAP) { vm_map_entry_t sub_entry = find_entry (entry->object.sub_map, address); if (! sub_entry) continue; entry = sub_entry; break; } if (entry->object.vm_object == NULL) continue; VM_OBJECT_LOCK (entry->object.vm_object); page = vm_page_lookup (entry->object.vm_object, OFF_TO_IDX(MMAP_OFFSET)); paddr = (page) ? VM_PAGE_TO_PHYS (page) : 0; VM_OBJECT_UNLOCK (entry->object.vm_object); if (paddr == address) break; } return (i < map->nentries) ? entry : NULL; } where MMAP_OFFSET is 0x40000000. This was the offset passed in by the mmap call. Does anyone know of a more proper mechanism that will work for the threaded model? Any and all assistance will be greatly appreciated. TIA, Sean