From owner-freebsd-hackers@FreeBSD.ORG Mon Jul 31 18:15:13 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org 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 8DCCC16A4E1 for ; Mon, 31 Jul 2006 18:15:13 +0000 (UTC) (envelope-from asmrookie@gmail.com) Received: from wx-out-0102.google.com (wx-out-0102.google.com [66.249.82.204]) by mx1.FreeBSD.org (Postfix) with ESMTP id CB77A43D55 for ; Mon, 31 Jul 2006 18:15:12 +0000 (GMT) (envelope-from asmrookie@gmail.com) Received: by wx-out-0102.google.com with SMTP id t12so236722wxc for ; Mon, 31 Jul 2006 11:15:12 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=tBxzkcZiic1uDautFoPEjEUCDIjeac7YArbEzFNH+t2UgQBu6UwMZe0lRIMN+k5uh9RU4+GcHa0r8KcaKEUv+k4pBmCNFoqLWCca5PlydEY/CRhs4FgKmpATsWstgCXjzzzuIxS7kHVc5zK5HFEsS8jofguCWt00aDcx0p4KbF4= Received: by 10.70.80.3 with SMTP id d3mr3108367wxb; Mon, 31 Jul 2006 11:15:12 -0700 (PDT) Received: by 10.70.11.18 with HTTP; Mon, 31 Jul 2006 11:15:11 -0700 (PDT) Message-ID: <3bbf2fe10607311115ua9b7b9axd9d3e6dcff2c1daf@mail.gmail.com> Date: Mon, 31 Jul 2006 20:15:11 +0200 From: "Attilio Rao" Sender: asmrookie@gmail.com To: "Divacky Roman" In-Reply-To: <20060730200354.GA82547@stud.fit.vutbr.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <20060730105731.GA64955@stud.fit.vutbr.cz> <20060730200354.GA82547@stud.fit.vutbr.cz> X-Google-Sender-Auth: 9e82a4bd3d8b3797 Cc: freebsd-hackers@freebsd.org Subject: Re: VM question related to faults 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: Mon, 31 Jul 2006 18:15:13 -0000 2006/7/30, Divacky Roman : > On Sun, Jul 30, 2006 at 12:57:32PM +0200, Divacky Roman wrote: > > hi, > > > > while working on SoC linuxolator project I am in a need of this: > > > > I need to do some operation on memory like mem1 = mem1 + mem2 etc. > > where the mem1/mem2 access can trigger fault. (memory not mapped or something) > > to make it clear.. I am trying to access user-space memory from kernel. > This needs to be atomic (its an implementation of linux futexes) > > I need to check from kernel if some memory is accessible and then perform an > operation on this memory. All atomically. > > hence I need two things - function which checks wheter the memory is accessible > and something which makes it atomic (some mutex/something which prevents other > process to enter VM to unmap/etc. the memory in question) > > hope its a bit more clear now You would use something like: #include #include #include #include #include #include #include #include ... int lock_and_fetch(const void* mem1, const void *mem2) { mtx_lock(&vm_page_queue_mtx); if (fubyte(mem1) == -1 || fubyte(mem2) == -1) { mtx_unlock(&vm_page_queue_mtx); return(EINVAL); } /* Operations... */ mtx_unlock(&vm_page_queue_mtx); return(0); } It prevents to virtual pages to be passed through queues. Attilio -- Peace can only be achieved by understanding - A. Einstein