From fe1fe620f8418f588086cadfe1b03bb5d224b548 Mon Sep 17 00:00:00 2001 From: cheloha Date: Fri, 23 Feb 2024 18:19:02 +0000 Subject: [PATCH] ddb(4): db_read_bytes/db_write_bytes: change dst/src parameter to void* Almost all db_read_bytes() callers cast the destination buffer argument to char*, which suggests the API's prototype is incompatible with how the API is actually used. Change db_read_bytes() and db_write_bytes() to take a void* as the destination/source buffer parameter so callers don't need to cast the argument. With input from bluhm@. Bugs caught by Clemens Gossnitzer (ASCII approximation of name). Thread: https://marc.info/?l=openbsd-tech&m=170740813021636&w=2 ok bluhm@ --- sys/arch/alpha/alpha/db_interface.c | 14 +++++++------- sys/arch/amd64/amd64/db_memrw.c | 10 +++++----- sys/arch/arm/arm/db_interface.c | 10 +++++----- sys/arch/arm64/arm64/db_interface.c | 10 +++++----- sys/arch/hppa/hppa/db_interface.c | 8 +++++--- sys/arch/i386/i386/db_memrw.c | 10 +++++----- sys/arch/m88k/m88k/db_interface.c | 10 +++++----- sys/arch/mips64/mips64/db_machdep.c | 9 ++++++--- sys/arch/powerpc/ddb/db_memrw.c | 10 +++++----- sys/arch/powerpc64/powerpc64/db_memrw.c | 10 +++++----- sys/arch/riscv64/riscv64/db_interface.c | 8 ++++---- sys/arch/sh/sh/db_memrw.c | 10 +++++----- sys/arch/sparc64/sparc64/db_interface.c | 8 +++++--- sys/ddb/db_access.h | 6 +++--- 14 files changed, 70 insertions(+), 63 deletions(-) diff --git a/sys/arch/alpha/alpha/db_interface.c b/sys/arch/alpha/alpha/db_interface.c index f0289c6acc7..a27505862a1 100644 --- a/sys/arch/alpha/alpha/db_interface.c +++ b/sys/arch/alpha/alpha/db_interface.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_interface.c,v 1.28 2022/04/14 19:47:10 naddy Exp $ */ +/* $OpenBSD: db_interface.c,v 1.29 2024/02/23 18:19:02 cheloha Exp $ */ /* $NetBSD: db_interface.c,v 1.8 1999/10/12 17:08:57 jdolecek Exp $ */ /* @@ -188,12 +188,12 @@ ddb_trap(a0, a1, a2, entry, regs) * Read bytes from kernel address space for debugger. */ void -db_read_bytes(addr, size, data) +db_read_bytes(addr, size, datap) vaddr_t addr; register size_t size; - register char *data; + register void *datap; { - register char *src; + register char *data = datap, *src; src = (char *)addr; while (size-- > 0) @@ -204,12 +204,12 @@ db_read_bytes(addr, size, data) * Write bytes to kernel address space for debugger. */ void -db_write_bytes(addr, size, data) +db_write_bytes(addr, size, datap) vaddr_t addr; register size_t size; - register char *data; + register void *datap; { - register char *dst; + register char *data = datap, *dst; dst = (char *)addr; while (size-- > 0) diff --git a/sys/arch/amd64/amd64/db_memrw.c b/sys/arch/amd64/amd64/db_memrw.c index 8d75cc3baf4..a0562a8dc87 100644 --- a/sys/arch/amd64/amd64/db_memrw.c +++ b/sys/arch/amd64/amd64/db_memrw.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_memrw.c,v 1.8 2017/04/30 13:04:49 mpi Exp $ */ +/* $OpenBSD: db_memrw.c,v 1.9 2024/02/23 18:19:02 cheloha Exp $ */ /* $NetBSD: db_memrw.c,v 1.1 2003/04/26 18:39:27 fvdl Exp $ */ /*- @@ -60,9 +60,9 @@ * Read bytes from kernel address space for debugger. */ void -db_read_bytes(vaddr_t addr, size_t size, char *data) +db_read_bytes(vaddr_t addr, size_t size, void *datap) { - char *src; + char *data = datap, *src; src = (char *)addr; @@ -160,10 +160,10 @@ db_write_text(vaddr_t addr, size_t size, char *data) * Write bytes to kernel address space for debugger. */ void -db_write_bytes(vaddr_t addr, size_t size, char *data) +db_write_bytes(vaddr_t addr, size_t size, void *datap) { extern char etext; - char *dst; + char *data = datap, *dst; /* If any part is in kernel text, use db_write_text() */ if (addr >= KERNBASE && addr < (vaddr_t)&etext) { diff --git a/sys/arch/arm/arm/db_interface.c b/sys/arch/arm/arm/db_interface.c index 45ab8bc6d2d..40ee1d84c6e 100644 --- a/sys/arch/arm/arm/db_interface.c +++ b/sys/arch/arm/arm/db_interface.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_interface.c,v 1.20 2022/10/15 08:04:02 jsg Exp $ */ +/* $OpenBSD: db_interface.c,v 1.21 2024/02/23 18:19:02 cheloha Exp $ */ /* $NetBSD: db_interface.c,v 1.34 2003/10/26 23:11:15 chris Exp $ */ /* @@ -182,9 +182,9 @@ db_validate_address(vaddr_t addr) * Read bytes from kernel address space for debugger. */ void -db_read_bytes(vaddr_t addr, size_t size, char *data) +db_read_bytes(vaddr_t addr, size_t size, void *datap) { - char *src = (char *)addr; + char *data = datap, *src = (char *)addr; if (db_validate_address((u_int)src)) { db_printf("address %p is invalid\n", src); @@ -301,11 +301,11 @@ db_write_text(vaddr_t addr, size_t size, char *data) * Write bytes to kernel address space for debugger. */ void -db_write_bytes(vaddr_t addr, size_t size, char *data) +db_write_bytes(vaddr_t addr, size_t size, void *datap) { extern char etext[]; extern char kernel_text[]; - char *dst; + char *data = datap, *dst; size_t loop; /* If any part is in kernel text, use db_write_text() */ diff --git a/sys/arch/arm64/arm64/db_interface.c b/sys/arch/arm64/arm64/db_interface.c index 7b2a14e9e8a..a7ed1e1db83 100644 --- a/sys/arch/arm64/arm64/db_interface.c +++ b/sys/arch/arm64/arm64/db_interface.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_interface.c,v 1.14 2022/11/07 09:43:04 mpi Exp $ */ +/* $OpenBSD: db_interface.c,v 1.15 2024/02/23 18:19:03 cheloha Exp $ */ /* $NetBSD: db_interface.c,v 1.34 2003/10/26 23:11:15 chris Exp $ */ /* @@ -197,9 +197,9 @@ db_validate_address(vaddr_t addr) * Read bytes from kernel address space for debugger. */ void -db_read_bytes(vaddr_t addr, size_t size, char *data) +db_read_bytes(vaddr_t addr, size_t size, void *datap) { - char *src = (char *)addr; + char *data = datap, *src = (char *)addr; if (db_validate_address((vaddr_t)src)) { db_printf("address %p is invalid\n", src); @@ -277,10 +277,10 @@ db_write_text(vaddr_t addr, size_t size, char *data) * Write bytes to kernel address space for debugger. */ void -db_write_bytes(vaddr_t addr, size_t size, char *data) +db_write_bytes(vaddr_t addr, size_t size, void *datap) { extern char etext[]; - char *dst; + char *data = datap, *dst; size_t loop; /* If any part is in kernel text, use db_write_text() */ diff --git a/sys/arch/hppa/hppa/db_interface.c b/sys/arch/hppa/hppa/db_interface.c index 2d278b03568..e7527e9f4a1 100644 --- a/sys/arch/hppa/hppa/db_interface.c +++ b/sys/arch/hppa/hppa/db_interface.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_interface.c,v 1.49 2023/04/26 16:53:58 claudio Exp $ */ +/* $OpenBSD: db_interface.c,v 1.50 2024/02/23 18:19:03 cheloha Exp $ */ /* * Copyright (c) 1999-2003 Michael Shalayeff @@ -134,8 +134,9 @@ db_enter(void) } void -db_read_bytes(vaddr_t addr, size_t size, char *data) +db_read_bytes(vaddr_t addr, size_t size, void *datap) { + char *data = datap; register char *src = (char *)addr; while (size--) @@ -143,8 +144,9 @@ db_read_bytes(vaddr_t addr, size_t size, char *data) } void -db_write_bytes(vaddr_t addr, size_t size, char *data) +db_write_bytes(vaddr_t addr, size_t size, void *datap) { + char *data = datap; register char *dst = (char *)addr; while (size--) diff --git a/sys/arch/i386/i386/db_memrw.c b/sys/arch/i386/i386/db_memrw.c index 3a39c698d55..0ece19dab9a 100644 --- a/sys/arch/i386/i386/db_memrw.c +++ b/sys/arch/i386/i386/db_memrw.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_memrw.c,v 1.18 2020/09/23 15:13:26 deraadt Exp $ */ +/* $OpenBSD: db_memrw.c,v 1.19 2024/02/23 18:19:03 cheloha Exp $ */ /* $NetBSD: db_memrw.c,v 1.6 1999/04/12 20:38:19 pk Exp $ */ /* @@ -50,9 +50,9 @@ * Read bytes from kernel address space for debugger. */ void -db_read_bytes(vaddr_t addr, size_t size, char *data) +db_read_bytes(vaddr_t addr, size_t size, void *datap) { - char *src; + char *data = datap, *src; src = (char *)addr; while (size-- > 0) @@ -136,9 +136,9 @@ db_write_text(vaddr_t addr, size_t size, char *data) * Write bytes to kernel address space for debugger. */ void -db_write_bytes(vaddr_t addr, size_t size, char *data) +db_write_bytes(vaddr_t addr, size_t size, void *datap) { - char *dst; + char *data = datap, *dst; extern char etext; if (addr >= VM_MIN_KERNEL_ADDRESS && diff --git a/sys/arch/m88k/m88k/db_interface.c b/sys/arch/m88k/m88k/db_interface.c index 4827c21a108..ba6e5428266 100644 --- a/sys/arch/m88k/m88k/db_interface.c +++ b/sys/arch/m88k/m88k/db_interface.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_interface.c,v 1.28 2022/04/14 19:47:11 naddy Exp $ */ +/* $OpenBSD: db_interface.c,v 1.29 2024/02/23 18:19:03 cheloha Exp $ */ /* * Mach Operating System * Copyright (c) 1993-1991 Carnegie Mellon University @@ -487,9 +487,9 @@ ddb_entry_trap(level, eframe) * Read bytes from kernel address space for debugger. */ void -db_read_bytes(vaddr_t addr, size_t size, char *data) +db_read_bytes(vaddr_t addr, size_t size, void *datap) { - char *src; + char *data = datap, *src; src = (char *)addr; @@ -502,10 +502,10 @@ db_read_bytes(vaddr_t addr, size_t size, char *data) * Write bytes to kernel address space for debugger. */ void -db_write_bytes(vaddr_t addr, size_t size, char *data) +db_write_bytes(vaddr_t addr, size_t size, void *datap) { extern pt_entry_t *pmap_pte(pmap_t, vaddr_t); - char *dst = (char *)addr; + char *data = datap, *dst = (char *)addr; vaddr_t va; paddr_t pa; pt_entry_t *pte, opte, npte; diff --git a/sys/arch/mips64/mips64/db_machdep.c b/sys/arch/mips64/mips64/db_machdep.c index c2d8f0321d5..4324dd68c35 100644 --- a/sys/arch/mips64/mips64/db_machdep.c +++ b/sys/arch/mips64/mips64/db_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_machdep.c,v 1.60 2023/01/11 03:17:56 visa Exp $ */ +/* $OpenBSD: db_machdep.c,v 1.61 2024/02/23 18:19:03 cheloha Exp $ */ /* * Copyright (c) 1998-2003 Opsycon AB (www.opsycon.se) @@ -281,8 +281,10 @@ db_cpuinfo_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif) #endif void -db_read_bytes(vaddr_t addr, size_t size, char *data) +db_read_bytes(vaddr_t addr, size_t size, void *datap) { + char *data = datap; + while (size >= sizeof(uint32_t)) { *(uint32_t *)data = kdbpeek(addr); data += sizeof(uint32_t); @@ -302,8 +304,9 @@ db_read_bytes(vaddr_t addr, size_t size, char *data) } void -db_write_bytes(vaddr_t addr, size_t size, char *data) +db_write_bytes(vaddr_t addr, size_t size, void *datap) { + char *data = datap; vaddr_t ptr = addr; size_t len = size; diff --git a/sys/arch/powerpc/ddb/db_memrw.c b/sys/arch/powerpc/ddb/db_memrw.c index da60d02af6c..838df93aca9 100644 --- a/sys/arch/powerpc/ddb/db_memrw.c +++ b/sys/arch/powerpc/ddb/db_memrw.c @@ -1,5 +1,5 @@ /* $NetBSD: db_memrw.c,v 1.4 2001/05/18 20:38:27 matt Exp $ */ -/* $OpenBSD: db_memrw.c,v 1.6 2022/10/15 08:04:02 jsg Exp $ */ +/* $OpenBSD: db_memrw.c,v 1.7 2024/02/23 18:19:03 cheloha Exp $ */ /* * Mach Operating System @@ -53,9 +53,9 @@ * Read bytes from kernel address space for debugger. */ void -db_read_bytes(vaddr_t addr, size_t size, char *data) +db_read_bytes(vaddr_t addr, size_t size, void *datap) { - char *src = (char *)addr; + char *data = datap, *src = (char *)addr; faultbuf env; faultbuf *old_onfault = curpcb->pcb_onfault; if (setfault(&env)) { @@ -80,9 +80,9 @@ db_read_bytes(vaddr_t addr, size_t size, char *data) * Write bytes to kernel address space for debugger. */ void -db_write_bytes(vaddr_t addr, size_t size, char *data) +db_write_bytes(vaddr_t addr, size_t size, void *datap) { - char *dst = (char *)addr; + char *data = datap, *dst = (char *)addr; faultbuf env; faultbuf *old_onfault = curpcb->pcb_onfault; diff --git a/sys/arch/powerpc64/powerpc64/db_memrw.c b/sys/arch/powerpc64/powerpc64/db_memrw.c index f1f322a334a..11e20444389 100644 --- a/sys/arch/powerpc64/powerpc64/db_memrw.c +++ b/sys/arch/powerpc64/powerpc64/db_memrw.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_memrw.c,v 1.2 2020/06/12 22:01:01 gkoehler Exp $ */ +/* $OpenBSD: db_memrw.c,v 1.3 2024/02/23 18:19:03 cheloha Exp $ */ /* $NetBSD: db_memrw.c,v 1.1 2003/04/26 18:39:27 fvdl Exp $ */ /*- @@ -46,9 +46,9 @@ * Read bytes from kernel address space for debugger. */ void -db_read_bytes(vaddr_t addr, size_t size, char *data) +db_read_bytes(vaddr_t addr, size_t size, void *datap) { - char *src; + char *data = datap, *src; src = (char *)addr; @@ -136,10 +136,10 @@ db_write_text(vaddr_t addr, size_t size, char *data) * Write bytes to kernel address space for debugger. */ void -db_write_bytes(vaddr_t addr, size_t size, char *data) +db_write_bytes(vaddr_t addr, size_t size, void *datap) { extern char _start[], _etext[]; - char *dst; + char *data = datap, *dst; /* If any part is in kernel text, use db_write_text() */ if (addr >= (vaddr_t)_start && addr < (vaddr_t)_etext) { diff --git a/sys/arch/riscv64/riscv64/db_interface.c b/sys/arch/riscv64/riscv64/db_interface.c index 1f4911b09c8..ade427794e7 100644 --- a/sys/arch/riscv64/riscv64/db_interface.c +++ b/sys/arch/riscv64/riscv64/db_interface.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_interface.c,v 1.8 2022/04/14 19:47:11 naddy Exp $ */ +/* $OpenBSD: db_interface.c,v 1.9 2024/02/23 18:19:03 cheloha Exp $ */ /* * Copyright (c) 1996 Scott K. Stevens @@ -179,9 +179,9 @@ db_validate_address(vaddr_t addr) * Read bytes from kernel address space for debugger. */ void -db_read_bytes(vaddr_t addr, size_t size, char *data) +db_read_bytes(vaddr_t addr, size_t size, void *datap) { - char *src = (char *)addr; + char *data = datap, *src = (char *)addr; if (db_validate_address((vaddr_t)src)) { db_printf("address %p is invalid\n", src); @@ -217,7 +217,7 @@ db_read_bytes(vaddr_t addr, size_t size, char *data) * Write bytes to kernel address space for debugger. */ void -db_write_bytes(vaddr_t addr, size_t size, char *data) +db_write_bytes(vaddr_t addr, size_t size, void *datap) { // XXX } diff --git a/sys/arch/sh/sh/db_memrw.c b/sys/arch/sh/sh/db_memrw.c index 978c8c37005..43343f9bf07 100644 --- a/sys/arch/sh/sh/db_memrw.c +++ b/sys/arch/sh/sh/db_memrw.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_memrw.c,v 1.1.1.1 2006/10/06 21:02:55 miod Exp $ */ +/* $OpenBSD: db_memrw.c,v 1.2 2024/02/23 18:19:03 cheloha Exp $ */ /* $NetBSD: db_memrw.c,v 1.8 2006/02/24 00:57:19 uwe Exp $ */ /* @@ -49,9 +49,9 @@ * Read bytes from kernel address space for debugger. */ void -db_read_bytes(vaddr_t addr, size_t size, char *data) +db_read_bytes(vaddr_t addr, size_t size, void *datap) { - char *src = (char *)addr; + char *data = datap, *src = (char *)addr; /* properly aligned 4-byte */ if (size == 4 && ((addr & 3) == 0) && (((uintptr_t)data & 3) == 0)) { @@ -73,9 +73,9 @@ db_read_bytes(vaddr_t addr, size_t size, char *data) * Write bytes to kernel address space for debugger. */ void -db_write_bytes(vaddr_t addr, size_t size, char *data) +db_write_bytes(vaddr_t addr, size_t size, void *datap) { - char *dst = (char *)addr; + char *data = datap, *dst = (char *)addr; /* properly aligned 4-byte */ if (size == 4 && ((addr & 3) == 0) && (((uintptr_t)data & 3) == 0)) { diff --git a/sys/arch/sparc64/sparc64/db_interface.c b/sys/arch/sparc64/sparc64/db_interface.c index f5ee2964d00..570285b90a8 100644 --- a/sys/arch/sparc64/sparc64/db_interface.c +++ b/sys/arch/sparc64/sparc64/db_interface.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_interface.c,v 1.61 2023/01/31 15:18:55 deraadt Exp $ */ +/* $OpenBSD: db_interface.c,v 1.62 2024/02/23 18:19:03 cheloha Exp $ */ /* $NetBSD: db_interface.c,v 1.61 2001/07/31 06:55:47 eeh Exp $ */ /* @@ -523,8 +523,9 @@ db_stopcpu(struct cpu_info *ci) * Read bytes from kernel address space for debugger. */ void -db_read_bytes(vaddr_t addr, size_t size, char *data) +db_read_bytes(vaddr_t addr, size_t size, void *datap) { + char *data = datap; register char *src; src = (char *)addr; @@ -541,8 +542,9 @@ db_read_bytes(vaddr_t addr, size_t size, char *data) * Write bytes to kernel address space for debugger. */ void -db_write_bytes(vaddr_t addr, size_t size, char *data) +db_write_bytes(vaddr_t addr, size_t size, void *datap) { + char *data = datap; register char *dst; extern vaddr_t ktext; extern paddr_t ktextp; diff --git a/sys/ddb/db_access.h b/sys/ddb/db_access.h index 7a352079828..c09fc8ffb63 100644 --- a/sys/ddb/db_access.h +++ b/sys/ddb/db_access.h @@ -1,4 +1,4 @@ -/* $OpenBSD: db_access.h,v 1.11 2020/01/20 15:58:23 visa Exp $ */ +/* $OpenBSD: db_access.h,v 1.12 2024/02/23 18:19:02 cheloha Exp $ */ /* $NetBSD: db_access.h,v 1.6 1994/10/09 08:29:57 mycroft Exp $ */ /* @@ -36,5 +36,5 @@ db_expr_t db_get_value(vaddr_t, size_t, int); void db_put_value(vaddr_t, size_t, db_expr_t); -void db_read_bytes(vaddr_t, size_t, char *); -void db_write_bytes(vaddr_t, size_t, char *); +void db_read_bytes(vaddr_t, size_t, void *); +void db_write_bytes(vaddr_t, size_t, void *); -- 2.20.1