x86: avoid accessing invalid addresses in ddb like arm32
This avoids that a command stops in the middle of an execution if a fault occurs due to an access to an invalid address.
This commit is contained in:
parent
5e1f20377c
commit
c1510da660
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: db_memrw.c,v 1.5 2018/03/15 03:45:05 ozaki-r Exp $ */
|
||||
/* $NetBSD: db_memrw.c,v 1.6 2018/03/16 04:48:19 ozaki-r Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996, 2000 The NetBSD Foundation, Inc.
|
||||
|
@ -53,7 +53,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: db_memrw.c,v 1.5 2018/03/15 03:45:05 ozaki-r Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: db_memrw.c,v 1.6 2018/03/16 04:48:19 ozaki-r Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/proc.h>
|
||||
|
@ -64,6 +64,22 @@ __KERNEL_RCSID(0, "$NetBSD: db_memrw.c,v 1.5 2018/03/15 03:45:05 ozaki-r Exp $")
|
|||
#include <ddb/db_access.h>
|
||||
#include <ddb/db_output.h>
|
||||
|
||||
static int
|
||||
db_validate_address(vaddr_t addr)
|
||||
{
|
||||
struct proc *p = curproc;
|
||||
struct pmap *pmap;
|
||||
|
||||
if (!p || !p->p_vmspace || !p->p_vmspace->vm_map.pmap ||
|
||||
addr >= VM_MIN_KERNEL_ADDRESS
|
||||
)
|
||||
pmap = pmap_kernel();
|
||||
else
|
||||
pmap = p->p_vmspace->vm_map.pmap;
|
||||
|
||||
return (pmap_extract(pmap, addr, NULL) == false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Read bytes from kernel address space for debugger.
|
||||
*/
|
||||
|
@ -74,6 +90,11 @@ db_read_bytes(vaddr_t addr, size_t size, char *data)
|
|||
|
||||
src = (char *)addr;
|
||||
|
||||
if (db_validate_address((vaddr_t)src)) {
|
||||
db_printf("address %p is invalid\n", src);
|
||||
return;
|
||||
}
|
||||
|
||||
if (size == 8) {
|
||||
*((long *)data) = *((long *)src);
|
||||
return;
|
||||
|
@ -89,8 +110,14 @@ db_read_bytes(vaddr_t addr, size_t size, char *data)
|
|||
return;
|
||||
}
|
||||
|
||||
while (size-- > 0)
|
||||
while (size-- > 0) {
|
||||
if (db_validate_address((vaddr_t)src)) {
|
||||
db_printf("address %p is invalid\n", src);
|
||||
return;
|
||||
}
|
||||
|
||||
*data++ = *src++;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue