Date: Wed, 5 Feb 2020 11:34:11 +0000 (UTC) From: Leandro Lupori <luporl@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r357570 - head/sys/kern Message-ID: <202002051134.015BYBq4050388@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: luporl Date: Wed Feb 5 11:34:10 2020 New Revision: 357570 URL: https://svnweb.freebsd.org/changeset/base/357570 Log: Add SYSCTL to get KERNBASE and relocated KERNBASE This change adds 2 new SYSCTLs, to retrieve the original and relocated KERNBASE values. This provides an easy, architecture independent way to calculate the running kernel displacement (current/load address minus original base address). The initial goal for this change is to add a new libkvm function that returns the kernel displacement, both for live kernels and crashdumps. This would in turn be used by kgdb to find out how to relocate kernel symbols (if needed). Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D23284 Modified: head/sys/kern/link_elf.c Modified: head/sys/kern/link_elf.c ============================================================================== --- head/sys/kern/link_elf.c Wed Feb 5 11:02:00 2020 (r357569) +++ head/sys/kern/link_elf.c Wed Feb 5 11:34:10 2020 (r357570) @@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$"); #include <sys/fcntl.h> #include <sys/vnode.h> #include <sys/linker.h> +#include <sys/sysctl.h> #include <machine/elf.h> @@ -389,6 +390,13 @@ link_elf_link_common_finish(linker_file_t lf) extern vm_offset_t __startkernel, __endkernel; +static unsigned long kern_relbase = KERNBASE; + +SYSCTL_ULONG(_kern, OID_AUTO, base_address, CTLFLAG_RD, + SYSCTL_NULL_ULONG_PTR, KERNBASE, "Kernel base address"); +SYSCTL_ULONG(_kern, OID_AUTO, relbase_address, CTLFLAG_RD, + &kern_relbase, 0, "Kernel relocated base address"); + static void link_elf_init(void* arg) { @@ -431,6 +439,7 @@ link_elf_init(void* arg) #ifdef __powerpc__ linker_kernel_file->address = (caddr_t)__startkernel; linker_kernel_file->size = (intptr_t)(__endkernel - __startkernel); + kern_relbase = (unsigned long)__startkernel; #else linker_kernel_file->address += KERNBASE; linker_kernel_file->size = -(intptr_t)linker_kernel_file->address;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202002051134.015BYBq4050388>