From owner-freebsd-hackers@FreeBSD.ORG Sun Jul 30 15:53:58 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 DF3CF16A4DA for ; Sun, 30 Jul 2006 15:53:58 +0000 (UTC) (envelope-from admin@intron.ac) Received: from intron.ac (unknown [210.51.165.237]) by mx1.FreeBSD.org (Postfix) with ESMTP id 64AF443D46 for ; Sun, 30 Jul 2006 15:53:57 +0000 (GMT) (envelope-from admin@intron.ac) Received: from localhost (localhost [127.0.0.1]) (uid 1003) by intron.ac with local; Sun, 30 Jul 2006 23:53:55 +0800 id 00102E04.44CCD613.0001443C References: <20060730105731.GA64955@stud.fit.vutbr.cz> In-Reply-To: <20060730105731.GA64955@stud.fit.vutbr.cz> From: "Intron" To: Divacky Roman Date: Sun, 30 Jul 2006 23:53:55 +0800 Mime-Version: 1.0 Content-Type: text/plain; charset="gb2312"; format=flowed Content-Transfer-Encoding: 7bit Message-ID: 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: Sun, 30 Jul 2006 15:53:59 -0000 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) > > currently I solve this by using pcb_onfault. this must be done in asm (kib@ > told me) so currently the code looks like this: > > futex_fault: > movl PCPU(CURPCB), %edx > movl $0, PCB_ONFAULT(%edx) > movl $-EFAULT, %eax > ret > > /* int futex_xchgl(int oparg, caddr_t uaddr, int *oldval); */ > .globl futex_xchgl > futex_xchgl: > movl PCPU(CURPCB), %eax > movl $futex_fault, PCB_ONFAULT(%eax) > movl 4(%esp), %eax > movl 8(%esp), %edx > > xchgl %eax, (%edx) > movl 0xc(%esp), %edx > movl %eax, (%edx) > xorl %eax, %eax > > movl PCPU(CURPCB), %edx > movl $0, PCB_ONFAULT(%edx) > ret > > this is not very nice nor portable. I wonder if its possible to do something > like this: > > LOCK_VM_SOMEHOW(); > if (!memory_accessible(mem1) || !memory_accessible(mem2)) > return EFAULT; > > mem1 = mem1 + mem2; > > UNLOCK_VM_SOMEHOW(); > > if its possible - what is the LOCK_VM_SOMEHOW lock? and what is the > memory_accessible() function? > > thnx for pointing me to the right directions > > roman > > > ---------------------- > www.liberalnistrana.cz > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org" As I know, there're two ways to detect page fault: 1. Look up in page mapping table (i.e. GDT and IDT on x86 or x86_64). See copyin() and copyout() in "/sys/i386/i386/support.s". 2. Capture exception interrupt triggered by CPU (i.e. INT 0x0E on x86 and x86_64) like vm_fault() in "/sys/vm/vm_fault.c". Actually, kernel memory page fault should not arise at all, which means bug made by programmer. ------------------------------------------------------------------------ From Beijing, China