From 43e5fbd8b78848c89c1d0305396464039e452688 Mon Sep 17 00:00:00 2001 From: Thiago Jung Bauermann Date: Thu, 18 Aug 2022 18:21:18 +0000 Subject: gdbserver: Add PID parameter to linux_get_auxv and linux_get_hwcap This patch doesn't change gdbserver behaviour, but after later changes are made it avoids a null pointer dereference when HWCAP needs to be obtained for a specific process while current_thread is nullptr. Fixing linux_read_auxv, linux_get_hwcap and linux_get_hwcap2 to take a PID parameter seems more correct than setting current_thread in one particular code path. Changes are propagated to allow passing the new parameter through the call chain. Approved-By: Simon Marchi --- gdbserver/linux-low.h | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'gdbserver/linux-low.h') diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h index aebfe05..e672855 100644 --- a/gdbserver/linux-low.h +++ b/gdbserver/linux-low.h @@ -178,7 +178,7 @@ public: bool supports_read_auxv () override; - int read_auxv (CORE_ADDR offset, unsigned char *myaddr, + int read_auxv (int pid, CORE_ADDR offset, unsigned char *myaddr, unsigned int len) override; int insert_point (enum raw_bkpt_type type, CORE_ADDR addr, @@ -941,22 +941,21 @@ bool thread_db_thread_handle (ptid_t ptid, gdb_byte **handle, int *handle_len); extern int have_ptrace_getregset; -/* Search for the value with type MATCH in the auxv vector with - entries of length WORDSIZE bytes. If found, store the value in - *VALP and return 1. If not found or if there is an error, return - 0. */ +/* Search for the value with type MATCH in the auxv vector, with entries of + length WORDSIZE bytes, of process with pid PID. If found, store the + value in *VALP and return 1. If not found or if there is an error, + return 0. */ -int linux_get_auxv (int wordsize, CORE_ADDR match, - CORE_ADDR *valp); +int linux_get_auxv (int pid, int wordsize, CORE_ADDR match, CORE_ADDR *valp); /* Fetch the AT_HWCAP entry from the auxv vector, where entries are length - WORDSIZE. If no entry was found, return zero. */ + WORDSIZE, of process with pid PID. If no entry was found, return 0. */ -CORE_ADDR linux_get_hwcap (int wordsize); +CORE_ADDR linux_get_hwcap (int pid, int wordsize); /* Fetch the AT_HWCAP2 entry from the auxv vector, where entries are length - WORDSIZE. If no entry was found, return zero. */ + WORDSIZE, of process with pid PID. If no entry was found, return 0. */ -CORE_ADDR linux_get_hwcap2 (int wordsize); +CORE_ADDR linux_get_hwcap2 (int pid, int wordsize); #endif /* GDBSERVER_LINUX_LOW_H */ -- cgit v1.1