From nobody Wed Oct 1 02:55:40 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1545430216658674.0918589812217; Fri, 21 Dec 2018 14:10:16 -0800 (PST) Received: from localhost ([::1]:48344 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gaSzm-0001Xy-Lp for importer@patchew.org; Fri, 21 Dec 2018 17:10:14 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46339) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gaSyh-00013l-38 for qemu-devel@nongnu.org; Fri, 21 Dec 2018 17:09:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gaSye-0000tY-0i for qemu-devel@nongnu.org; Fri, 21 Dec 2018 17:09:07 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:34538) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gaR4R-00056f-Gy for qemu-devel@nongnu.org; Fri, 21 Dec 2018 15:06:57 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wBLK4CMF172401; Fri, 21 Dec 2018 20:04:12 GMT Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2pfh3ae60x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Dec 2018 20:04:12 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id wBLK4ADb004085 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Dec 2018 20:04:11 GMT Received: from abhmp0014.oracle.com (abhmp0014.oracle.com [141.146.116.20]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id wBLK4AZb023564; Fri, 21 Dec 2018 20:04:10 GMT Received: from ol7.uk.oracle.com (/10.175.186.114) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 21 Dec 2018 12:04:09 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=kTb5k1sJ8zYSNI1cPIcdbIq5REK6VYmfmQpJ84AEBeY=; b=BLkDC01poXPICh24tAZOQ2rbCFIdrlFlvAA7W2sEZ+nltRIAtv0fXrWzfxse+kocy9JC 3Zh/lXhOdvk2WX2mTUeaYa2JD8peiUhDY/Va7hThAuXh09FIIOZh9DjfATHj4lyt5JRs XqO6BQsqejnlfIkbYegkLgRPpn3uOq2HS8yZ7NMSCkxNe6WdrpXeVmd96ioedyAlbFwJ dzQ1XZuJ1chHfLzTM4+ip/OfcQhtdGPa4UpCTqFXePTTh43gAtJ1lX29guQxI8fvo2X+ dKFX2UYH8LJNT9k4jtIcbTXzl0eKB6/hC+Oox2Q4edSHzNgbKl4c5yDC0a7FtSK2joSI Cw== From: Liam Merwick To: qemu-devel@nongnu.org Date: Fri, 21 Dec 2018 20:03:50 +0000 Message-Id: <1545422632-24444-3-git-send-email-liam.merwick@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1545422632-24444-1-git-send-email-liam.merwick@oracle.com> References: <1545422632-24444-1-git-send-email-liam.merwick@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9114 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1812210150 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.86 Subject: [Qemu-devel] [RFC v2 2/4] elf-ops.h: Add get_elf_note_type() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ehabkost@redhat.com, mst@redhat.com, maran.wilson@oracle.com, george.kennedy@oracle.com, stefanha@redhat.com, xen-devel@lists.xenproject.org, pbonzini@redhat.com, boris.ostrovsky@oracle.com, rth@twiddle.net, sgarzare@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Introduce a routine which, given a pointer to a range of ELF Notes, searches through them looking for a note matching the type specified and returns a pointer to the matching ELF note. Signed-off-by: Liam Merwick --- include/hw/elf_ops.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++= ++ 1 file changed, 50 insertions(+) diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h index 37d20a3800c1..ffbdfbe9c2d8 100644 --- a/include/hw/elf_ops.h +++ b/include/hw/elf_ops.h @@ -265,6 +265,49 @@ fail: return ret; } =20 +/* Given 'nhdr', a pointer to a range of ELF Notes, search through them + * for a note matching type 'elf_note_type' and return a pointer to + * the matching ELF note. + */ +static struct elf_note *glue(get_elf_note_type, SZ)(struct elf_note *nhdr, + elf_word note_size, + elf_word phdr_align, + elf_word elf_note_type) +{ + elf_word nhdr_size =3D sizeof(struct elf_note); + elf_word elf_note_entry_offset =3D 0; + elf_word note_type; + elf_word nhdr_namesz; + elf_word nhdr_descsz; + + if (nhdr =3D=3D NULL) { + return NULL; + } + + note_type =3D nhdr->n_type; + while (note_type !=3D elf_note_type) { + nhdr_namesz =3D nhdr->n_namesz; + nhdr_descsz =3D nhdr->n_descsz; + + elf_note_entry_offset =3D nhdr_size + + QEMU_ALIGN_UP(nhdr_namesz, phdr_align) + + QEMU_ALIGN_UP(nhdr_descsz, phdr_align); + + /* If the offset calculated in this iteration exceeds the + * supplied size, we are done and no matching note was found. + */ + if (elf_note_entry_offset > note_size) { + return NULL; + } + + /* skip to the next ELF Note entry */ + nhdr =3D (void *)nhdr + elf_note_entry_offset; + note_type =3D nhdr->n_type; + } + + return nhdr; +} + static int glue(load_elf, SZ)(const char *name, int fd, uint64_t (*elf_note_fn)(void *, void *, bool= ), uint64_t (*translate_fn)(void *, uint64_t), @@ -512,6 +555,13 @@ static int glue(load_elf, SZ)(const char *name, int fd, } } =20 + /* Search the ELF notes to find one with a type matching the + * value passed in via 'translate_opaque' + */ + nhdr =3D (struct elf_note *)data; + assert(translate_opaque !=3D NULL); + nhdr =3D glue(get_elf_note_type, SZ)(nhdr, file_size, ph->p_al= ign, + *(uint64_t *)translate_opaq= ue); if (nhdr !=3D NULL) { bool is64 =3D sizeof(struct elf_note) =3D=3D sizeof(struct elf64_not= e); --=20 1.8.3.1