From f4ce0706d9574aecb7d4aa9af7208a1bc9b6afb4 Mon Sep 17 00:00:00 2001 From: Bhupesh Sharma Date: Thu, 20 Dec 2018 16:52:51 +0530 Subject: util_lib: Add functionality to read elf notes 'vmcore-dmesg.c' already implements functionality to read 'vmcoreinfo' from vmcore file. The same can be used in other features as well (one of which is reading the elf notes from 'kcore' file), so there is merit in moving this to the utility libraries (util_lib). Newer kernel versions (>= 4.19, with commit 23c85094fe1895caefdd ["proc/kcore: add vmcoreinfo note to /proc/kcore"], available), have 'kcore' which now contains a new PT_NOTE which carries the VMCOREINFO information. If the same is available, we can benefit by using it in 'kexec-tools'. This is especially useful for architectures like arm64 as we can get kernel symbols like 'PHYS_OFFSET' from the '/proc/kcore' itself and use it to calculate 'phys_offset' before we make a call to 'set_phys_offset()'. For older kernels, we can try and determine the PHYS_OFFSET value from PT_LOAD segments inside 'kcore' via some jugglery of the correct virtual and physical address combinations. Subsequent patch(es) in this series will use the same feature to read the 'kcore' file. This patch also makes some of the functions which were earlier present in 'vmcore-dmesg.c' as non-static, so as to allow future patches to use them as library functions. Also we add the capability to read 'NUMBER(PHYS_OFFSET)' from vmcoreinfo to the already present 'scan_vmcoreinfo()' code. Future patches can look at reading more vmcoreinfo information (for e.g. 'kaslr_offset()' for x86_64 and arm64) by using the same framework. Signed-off-by: Bhupesh Sharma Signed-off-by: Simon Horman --- util_lib/include/elf_info.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 util_lib/include/elf_info.h (limited to 'util_lib/include') diff --git a/util_lib/include/elf_info.h b/util_lib/include/elf_info.h new file mode 100644 index 0000000..1a4debd --- /dev/null +++ b/util_lib/include/elf_info.h @@ -0,0 +1,35 @@ +#ifndef ELF_INFO_H +#define ELF_INFO_H + +#define _XOPEN_SOURCE 700 +#define _GNU_SOURCE +#define _LARGEFILE_SOURCE 1 +#define _FILE_OFFSET_BITS 64 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int get_pt_load(int idx, + unsigned long long *phys_start, + unsigned long long *phys_end, + unsigned long long *virt_start, + unsigned long long *virt_end); +int read_phys_offset_elf_kcore(int fd, unsigned long *phys_off); +int read_elf_kcore(int fd); +int read_elf_vmcore(int fd); + +#endif /* ELF_INFO_H */ -- cgit