The branch main has been updated by vexeduxr:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=29418225611689d5dafeff1f0b7e2f170305ca90

commit 29418225611689d5dafeff1f0b7e2f170305ca90
Author:     Ahmad Khalifa <vexed...@freebsd.org>
AuthorDate: 2025-05-21 20:57:33 +0000
Commit:     Ahmad Khalifa <vexed...@freebsd.org>
CommitDate: 2025-06-22 03:49:32 +0000

    sys: provide the kernel's pa when dumping on amd64
    
    Provide the kernel's physical address in an ELF section when doing a
    full memory dump on amd64. This allows libkvm to figure out where the
    kernel was loaded in physical memory.
    
    Reviewed by: markj
    Approved by: imp (mentor)
    Pull Request: https://github.com/freebsd/freebsd-src/pull/1706
---
 sys/sys/elf_common.h       |  4 ++--
 sys/x86/include/dump.h     |  8 ++++++++
 sys/x86/x86/dump_machdep.c | 26 ++++++++++++++++++++++++++
 3 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/sys/sys/elf_common.h b/sys/sys/elf_common.h
index 1c33b55fc5b6..a5e605624e1e 100644
--- a/sys/sys/elf_common.h
+++ b/sys/sys/elf_common.h
@@ -554,8 +554,8 @@ typedef struct {
 #define        PT_GNU_EH_FRAME 0x6474e550
 #define        PT_GNU_STACK    0x6474e551
 #define        PT_GNU_RELRO    0x6474e552
-#define        PT_DUMP_DELTA   0x6fb5d000      /* va->pa map for kernel dumps
-                                          (currently arm). */
+#define        PT_DUMP_DELTA   0x6fb5d000      /* va->pa map for arm and amd64 
kernel
+                                          dumps */
 #define        PT_LOSUNW       0x6ffffffa
 #define        PT_SUNWBSS      0x6ffffffa      /* Sun Specific segment */
 #define        PT_SUNWSTACK    0x6ffffffb      /* describes the stack segment 
*/
diff --git a/sys/x86/include/dump.h b/sys/x86/include/dump.h
index 7f4caf9e8292..cdd07f32703c 100644
--- a/sys/x86/include/dump.h
+++ b/sys/x86/include/dump.h
@@ -38,7 +38,11 @@
 
 /* 20 phys_avail entry pairs correspond to 10 pa's */
 #define        DUMPSYS_MD_PA_NPAIRS    10
+#ifdef __amd64__
+#define        DUMPSYS_NUM_AUX_HDRS    1
+#else
 #define        DUMPSYS_NUM_AUX_HDRS    0
+#endif
 
 /* How often to check the dump progress bar? */
 #define        DUMPSYS_PB_CHECK_BITS   24      /* Every 16MB */
@@ -71,12 +75,16 @@ dumpsys_unmap_chunk(vm_paddr_t pa, size_t s, void *va)
        dumpsys_gen_unmap_chunk(pa, s, va);
 }
 
+#ifdef __amd64__
+int dumpsys_write_aux_headers(struct dumperinfo *di);
+#else
 static inline int
 dumpsys_write_aux_headers(struct dumperinfo *di)
 {
 
        return (dumpsys_gen_write_aux_headers(di));
 }
+#endif
 
 static inline int
 dumpsys(struct dumperinfo *di)
diff --git a/sys/x86/x86/dump_machdep.c b/sys/x86/x86/dump_machdep.c
index 866247610c07..71598e2c9808 100644
--- a/sys/x86/x86/dump_machdep.c
+++ b/sys/x86/x86/dump_machdep.c
@@ -37,6 +37,13 @@
 #include <vm/vm.h>
 #include <vm/pmap.h>
 
+#ifdef __amd64__
+#include <machine/elf.h>
+#include <machine/vmparam.h>
+#include <machine/md_var.h>
+#include <machine/dump.h>
+#endif
+
 int do_minidump = 1;
 SYSCTL_INT(_debug, OID_AUTO, minidump, CTLFLAG_RWTUN, &do_minidump, 0,
     "Enable mini crash dumps");
@@ -52,3 +59,22 @@ dumpsys_map_chunk(vm_paddr_t pa, size_t chunk, void **va)
                *va = pmap_kenter_temporary(trunc_page(a), i);
        }
 }
+
+#ifdef __amd64__
+int
+dumpsys_write_aux_headers(struct dumperinfo *di)
+{
+       Elf_Phdr phdr;
+
+       phdr.p_type = PT_DUMP_DELTA;
+       phdr.p_flags = PF_R;
+       phdr.p_offset = 0;
+       phdr.p_vaddr = KERNBASE;
+       phdr.p_paddr = kernphys;
+       phdr.p_filesz = 0;
+       phdr.p_memsz = 0;
+       phdr.p_align = KERNLOAD;
+
+       return (dumpsys_buf_write(di, (char *)&phdr, sizeof(phdr)));
+}
+#endif

Reply via email to