Date: Tue, 25 Aug 2015 17:02:28 +0000 (UTC) From: Andrew Turner <andrew@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r287136 - head/sys/arm64/arm64 Message-ID: <201508251702.t7PH2S2n042870@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <machine/cpu.h> #include <machine/pcb.h> +#include <machine/stack.h> #include <machine/vmparam.h> 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); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201508251702.t7PH2S2n042870>