From owner-svn-src-head@freebsd.org Tue Aug 25 17:02:29 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 297D799AE04; Tue, 25 Aug 2015 17:02:29 +0000 (UTC) (envelope-from andrew@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 00878CB9; Tue, 25 Aug 2015 17:02:29 +0000 (UTC) (envelope-from andrew@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t7PH2SMG042871; Tue, 25 Aug 2015 17:02:28 GMT (envelope-from andrew@FreeBSD.org) Received: (from andrew@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t7PH2S2n042870; Tue, 25 Aug 2015 17:02:28 GMT (envelope-from andrew@FreeBSD.org) Message-Id: <201508251702.t7PH2S2n042870@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: andrew set sender to andrew@FreeBSD.org using -f From: Andrew Turner Date: Tue, 25 Aug 2015 17:02:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r287136 - head/sys/arm64/arm64 X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Aug 2015 17:02:29 -0000 Author: andrew Date: Tue Aug 25 17:02:28 2015 New Revision: 287136 URL: https://svnweb.freebsd.org/changeset/base/287136 Log: Use kdb_jmpbuf and setjmp to handle accessing invalid addresses in the debugger memory access functions. This allows us to correctly reenter into the debugger on failure. Sponsored by: ABT Systems Ltd Modified: head/sys/arm64/arm64/db_interface.c Modified: head/sys/arm64/arm64/db_interface.c ============================================================================== --- head/sys/arm64/arm64/db_interface.c Tue Aug 25 16:50:25 2015 (r287135) +++ head/sys/arm64/arm64/db_interface.c Tue Aug 25 17:02:28 2015 (r287136) @@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include static int @@ -107,37 +108,28 @@ db_show_mdpcpu(struct pcpu *pc) { } -static int -db_validate_address(vm_offset_t addr) -{ - struct proc *p = curproc; - struct pmap *pmap; - - if (!p || !p->p_vmspace || !p->p_vmspace->vm_map.pmap || - addr >= VM_MAXUSER_ADDRESS) - pmap = pmap_kernel(); - else - pmap = p->p_vmspace->vm_map.pmap; - - return (pmap_extract(pmap, addr) != 0); -} - /* * Read bytes from kernel address space for debugger. */ int db_read_bytes(vm_offset_t addr, size_t size, char *data) { - const char *src = (const char *)addr; - - while (size-- > 0) { - if (db_validate_address((vm_offset_t)src)) { - db_printf("address %p is invalid\n", src); - return (-1); - } - *data++ = *src++; + jmp_buf jb; + void *prev_jb; + const char *src; + int ret; + + prev_jb = kdb_jmpbuf(jb); + ret = setjmp(jb); + + if (ret == 0) { + src = (const char *)addr; + while (size-- > 0) + *data++ = *src++; } - return (0); + (void)kdb_jmpbuf(prev_jb); + + return (ret); } /* @@ -146,21 +138,25 @@ db_read_bytes(vm_offset_t addr, size_t s int db_write_bytes(vm_offset_t addr, size_t size, char *data) { + jmp_buf jb; + void *prev_jb; char *dst; + int ret; - dst = (char *)addr; - while (size-- > 0) { - if (db_validate_address((vm_offset_t)dst)) { - db_printf("address %p is invalid\n", dst); - return (-1); - } - *dst++ = *data++; + prev_jb = kdb_jmpbuf(jb); + ret = setjmp(jb); + if (ret == 0) { + dst = (char *)addr; + while (size-- > 0) + *dst++ = *data++; + + dsb(ish); + + /* Clean D-cache and invalidate I-cache */ + cpu_dcache_wb_range(addr, (vm_size_t)size); + cpu_icache_sync_range(addr, (vm_size_t)size); } - dsb(ish); - - /* Clean D-cache and invalidate I-cache */ - cpu_dcache_wb_range(addr, (vm_size_t)size); - cpu_icache_sync_range(addr, (vm_size_t)size); + (void)kdb_jmpbuf(prev_jb); - return (0); + return (ret); }