From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1944) id 06C1F385153E; Thu, 27 Oct 2022 13:58:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 06C1F385153E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666879093; bh=9v6k7HT+zKe9c+fO1IU61w+fKslCI1U2u/OQ2Mp5/W0=; h=From:To:Subject:Date:From; b=GOy/Jp18yl0a0wP1pCjx/UguQMLNmjFeQJp0PDWdsPJ1KPGGU9UIIGiYfopMmr3OD /j2UZUYed4iHBydhzTWVibLHDRwOId2AQgdpq2Ie4sucuguAWIPsMfd1WekUAGQpIE x1H2YQY9wPzMLKu/VWHGhQXz397VAGeK3zDeJZ6U= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Szabolcs Nagy To: glibc-cvs@sourceware.org Subject: [glibc/arm/morello/main] aarch64: morello: add dl-r_debug.h X-Act-Checkin: glibc X-Git-Author: Szabolcs Nagy X-Git-Refname: refs/heads/arm/morello/main X-Git-Oldrev: 73d195966deacbd30a7c62ad922b66dfba804ccc X-Git-Newrev: fc00799a8d1f3975714c82c351b5c8ff08e7caf9 Message-Id: <20221027135813.06C1F385153E@sourceware.org> Date: Thu, 27 Oct 2022 13:58:13 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=fc00799a8d1f3975714c82c351b5c8ff08e7caf9 commit fc00799a8d1f3975714c82c351b5c8ff08e7caf9 Author: Szabolcs Nagy Date: Wed Sep 14 11:25:55 2022 +0100 aarch64: morello: add dl-r_debug.h Used internally for r_debug tests, but with the assumption that the return value can be dereferenced, so change the prototype and return a valid capability. Also used in pldd, where we only support purecap abi processes. Diff: --- sysdeps/aarch64/morello/dl-r_debug.h | 61 ++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/sysdeps/aarch64/morello/dl-r_debug.h b/sysdeps/aarch64/morello/dl-r_debug.h new file mode 100644 index 0000000000..827609ff76 --- /dev/null +++ b/sysdeps/aarch64/morello/dl-r_debug.h @@ -0,0 +1,61 @@ +/* Function to access r_debug structure. Morello version. + Copyright (C) 2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include + +static int +E(callback) (struct dl_phdr_info *info, size_t size, void *data) +{ + /* Assume phdr covers the load segments. */ + const void *phdr = info->dlpi_phdr; + uintptr_t *p = data; + unsigned long addr = *p; + unsigned long base = __builtin_cheri_base_get (phdr); + unsigned long len = __builtin_cheri_length_get (phdr); + if (addr - base >= len) + return 0; + *p = __builtin_cheri_address_set ((uintptr_t) phdr, addr); + return 1; +} + +/* Return a valid runtime pointer to r_debug instead of an address since + that's how this function is used despite its generic prototype. + Assume the lookup is for the main exe and return uintptr_t type. */ + +static inline uintptr_t +E(r_debug_address) (ElfW(Dyn) *d) +{ + if (d->d_tag != DT_DEBUG) + return 0; + uintptr_t p = d->d_un.d_ptr; + if (dl_iterate_phdr (E(callback), &p) == 1) + return p; + return 0; +} + +/* Return the offset of the struct r_debug before relocation. */ + +static inline EW(Addr) +E(r_debug_offset) (EW(Dyn) *d, int fd, EW(Addr) offset) +{ + if (d->d_tag == DT_DEBUG) + return (EW(Addr)) d->d_un.d_ptr; + + return 0; +}