From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id BF41B3854830 for ; Fri, 30 Sep 2022 00:05:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BF41B3854830 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28TMitv4026774; Fri, 30 Sep 2022 00:05:18 GMT 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 : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=c7AD6Ae8OsBigjmzzh/xlzf/2BNxfXiKijpCYfGz8fY=; b=r+iN3xa10pRLWLNdpAaGnqDckbYtatC0yRpaIo+EZJaZYaCfDaO0hn4EOQdst6TiNgRY Gd1Me3vqLfwbj6fczmxoY2QxH2vnUJy10xKHnta98HyKALuW178JTF/G1RtkDggk4IkF eFhJt6KdIBUBSfzpnmTZDampBHJBx/jFlxYYRagBaPOwrl2giUr1CtRlYxV2ldYgKCge INUHIEbMnZShnHMZ8gz8sCaGMOFQZrmhqkS+ZjgwTWDAcbZogg8VND5TjxtbNdkerta7 CBNuGhSs4V6IZhaqmTvORwFmReooSVhbPoW/zH5/Gy86+FUZe7WqjRoB/BVwr5gdkLVs fw== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3jst0kx3rc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 30 Sep 2022 00:05:17 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 28TL0s75033653; Fri, 30 Sep 2022 00:05:17 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2175.outbound.protection.outlook.com [104.47.55.175]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3jtpv3d6p4-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 30 Sep 2022 00:05:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VtCkgTRgkXFLRg070U/C8RaMMYkR9W/IjHd1qmUmZsujC4LkoFxeNx9YQWIQygC46X1WLf88ex6z0FWOYRp+ugXJbC3ZHV+OKeuKk1luX9y15rI/bsAq6vJVfryan4HBobsL0WuRzplrcsCzlxBK29wvKgWOa+bRsHCRF2FZkMFLI0w2jhUBRw8/49DVt9Lnya1Bu+3FYFW60m+DRhPr0hDrdNerFbsjsFeiTFQyD/tPt4s7YnqKge9/RcCmBNhs6LGCBTkis25wIYM/7c3zh9P855YzFKP8xULSnx+BYtnKtz94u5l+Wr7k8bUND/E5OoR6ioLXxV/yo06vRqbTbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=c7AD6Ae8OsBigjmzzh/xlzf/2BNxfXiKijpCYfGz8fY=; b=OxLboaN97Rft/3vUbwaecxjgWcgTd6KsaAF0aCa2HvX2w3aKTaj6Hjx2iz9+m1tq7jcBlzoaHf/1d0ut7ELCrWfOiR186UUxsTZRgLBfv8CGHFVvzCyUbCKJ6CqQd3A+Bbbp9u0w95lMQUL9qSNg9B0293QwbI49HA7bGdAhXqR5KvIpb4lYwQSP5GLxicbOK1uAm8nwGHllJ9exknLwc4534wtYLgJjQI6zcrDit6q3ePFUvcaH86uoEqRt2kdIZajHw7QxieF43D+J+tVPCn4EZL7eWuR1DmFXRdXZXUMwjamFcp5b/30uIUC7LSwgdptkK136oTfl3MF138IgJg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=c7AD6Ae8OsBigjmzzh/xlzf/2BNxfXiKijpCYfGz8fY=; b=jMSLkhSrpIztjy6w9aEammhxkaNaUS3BjziI4q2WcQQT/aCWrXy8SNjNjzaFoDYhVePwylxP4U840uVX2DRxCUjTalieLzURVxJVOMxFj4pmP0mhdbzjeU6+Kyu0YVEjr3WcRFx9bx8itDBrmhm4oqh2yDXMdUIkTacqqsy1jvE= Received: from MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) by SJ0PR10MB6397.namprd10.prod.outlook.com (2603:10b6:a03:449::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.20; Fri, 30 Sep 2022 00:05:05 +0000 Received: from MWHPR1001MB2158.namprd10.prod.outlook.com ([fe80::80a7:f7f3:4303:54e4]) by MWHPR1001MB2158.namprd10.prod.outlook.com ([fe80::80a7:f7f3:4303:54e4%5]) with mapi id 15.20.5676.017; Fri, 30 Sep 2022 00:05:05 +0000 From: Indu Bhagat To: binutils@sourceware.org Cc: nickc@redhat.com, weimin.pan@oracle.com, Indu Bhagat Subject: [PATCH,V1 01/14] sframe.h: Add SFrame format definition Date: Thu, 29 Sep 2022 17:04:27 -0700 Message-Id: <20220930000440.1672106-2-indu.bhagat@oracle.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220930000440.1672106-1-indu.bhagat@oracle.com> References: <20220930000440.1672106-1-indu.bhagat@oracle.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: MW4PR03CA0211.namprd03.prod.outlook.com (2603:10b6:303:b9::6) To MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR1001MB2158:EE_|SJ0PR10MB6397:EE_ X-MS-Office365-Filtering-Correlation-Id: bb2a2ab9-f3b5-443b-78f8-08daa2776dbd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uUeDBp+R1tc0uJ9ME5mdwCL13yynyqBSb0XYyWlUYChAhVru2BP2MECu0/IW9L0raCXytobo4YT9FO2AEwuyv928U3jWRRB0HFYrfcjt+COeia4CLcyGjtCrdfo18hNVt37TIGft5Vj8vEm5rdoRyc+H/Q/9VFar1HaD/YmCR6Smog6VKrg9bV7xrsnzENzfMfSM1HVRNYkdSXtWW12dI3hyuP9sd+E2hnivVdGfMJ1YQpgJOiJ7ghewJTB9QlxuFI05WM4UvX2zNObLmBCp24XKunHDeWdC/kmnFBehH1ey7uBbf2h0XjICKTOQrwThwEl9IkjTpAf0k8y96gGdvjs62auNfNaKw6QojmtKRQGn29xB115x0gwgHrkWJZGn0OeZ/UMMO/SInHUkSbb2pNVHqOt7K013M+T6TFnZ/a7Avbek5d79MhaSw4paWQBh70nvinsUkRrGSitB7DiQzQ/GwdH+doW58NV8qimxCprisQyAxs8bm7pExIFutta75iHzy+MGYBW1NfKiGNpHMA5Ayldk5tUyOnjOkQkb5DetCzlbD4EjsrOXMqbCJcE3XIqCvO7i9C9byMZ3tXM25q4kIrWcQjp9L7//+hqeqntsJok9EOmunPHX97zuOqx06bzHQ8nTMRSjObdHeU5dBsx8euS0VunuoJN/Gebx2ZLTqmgwvN7FvEwg1WPtUMwVWlziCNDOVFz1us/k5oOXOQbSKHbtzQcMwC68HjmCBFJ2T4RGjmcVVbXN2/tj2A7qEQQs9fqMUI5ZFoP0D2HDJROBg9JtwVgzGIGdeaGklkr0PLnbkL8eMIZuIV9fA5QN X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR1001MB2158.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(136003)(376002)(39860400002)(346002)(396003)(366004)(451199015)(30864003)(1076003)(36756003)(83380400001)(2906002)(8676002)(186003)(44832011)(4326008)(66946007)(6916009)(26005)(6512007)(66476007)(66556008)(6666004)(8936002)(107886003)(6506007)(316002)(5660300002)(86362001)(2616005)(41300700001)(6486002)(478600001)(38100700002)(2004002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?lt7XQR2jIurmofT3qFwyHIo9/vXM+a5d9OlWEteh6BshGrdcinbfHQsiLfgH?= =?us-ascii?Q?Rksu81DSGQlmpy6Kbio+QmIPHYxTz6hzqYGML5anMVc0jmJBNf0f+Nl4O69m?= =?us-ascii?Q?i54FybeaiejelVtgMwlTseMz6W6+za4OVCZ6K1Lo9AXGH5wMsET8J/AIiVPC?= =?us-ascii?Q?ePAkau9b3w6IaRhBTD8f3HKD4e5B5SRfMNRMLKTfkrcRaa8J1i2jNmkRnlFZ?= =?us-ascii?Q?Do1YjHFcH6JtBlld6TVLvTmO5Ep+he2ZEGlgfwTv1egrO8ZbNQKgFN8Aejky?= =?us-ascii?Q?XAdl5nuf8+swDoQvTmAdq9M+E9A9WL3WbhiQ0Eq993n3SRDYdlE6Skiyj+fY?= =?us-ascii?Q?jdQsR+Cw28p1JguweIHCMI+cMuWP/QMaG2gJPtJ40MP/RRCsr5VuFHMw2TNQ?= =?us-ascii?Q?YZthZ9wHtehZ+sKQBw8X2cNjl8ytSwAqE4Sfg+ZrRhxlhPfIP2D0Uzc/rfIq?= =?us-ascii?Q?G2rJpGA71RxKcEUVua3dKG9ZgQ3uQBTuiT/O49sk+6Sz18HP8tW9UGnT1L96?= =?us-ascii?Q?gib4pCmVJRwwqgFczn85uNjLdjYR7/Ddl3ue5SajsIyCcxAgksY0xgO1oU3h?= =?us-ascii?Q?3MmzSReerK0OhRvCMY3E5gY7VB291SLVBsLN14R5QfrUR1YPOEyi5L89jK8K?= =?us-ascii?Q?tUU4JIacOIFKuT4ttGSba79gzUlzvJJH23h/bAx5WjnJ8iHxan+ImrsDaxOb?= =?us-ascii?Q?5Vnuh6ly1am8LQEbaW7x9snnwvQUzc9bgWgR8bOafu1M5WWXUIohgSH1j3oS?= =?us-ascii?Q?qIggVwdJMcRdUdCRuCtDoZ0cRMO8oVpclqgNz2rLlar7JDr/FMuj7fwqyqce?= =?us-ascii?Q?kxV5JJ9e5JYLAEhHhQETE5ADtsvoGPRYqjHmJ1lshRHmAJUlDuFgmmIYghN3?= =?us-ascii?Q?bdCSYA1QCzl+Qlai81znCd4v2dK6pZm4EKMh/hdz+6sMNFMJPdckAb16GGv0?= =?us-ascii?Q?CuY/68Em9Uu/keqqo8E2++a10fEJl1gRwnwSI9YVsOtXFIdRWy5ZiiT1ExCs?= =?us-ascii?Q?M0hcy8Latmk7zdn+cpiK/oCTKsYnCGibqhpBLboREnwIl94R4TmayVKHXuVn?= =?us-ascii?Q?cdVVLsdgy9U+UPfVY6L4nmkWMn3zJGrv6LY37gsBkQn6tmlfTeHV55ubqwAf?= =?us-ascii?Q?JKsLFCBs5I6Xci1bUkRZcxqWPPa6QUiIA8ugvTPrs2xgSZdW8GB9pWL5hu23?= =?us-ascii?Q?nAnNBcWLGluWgMaUMBXmTVlz9cJle1UhaRNCT7ruoiVUo2Nu0+CCs+XOi3GV?= =?us-ascii?Q?rgw08oerGV1aSz9eVc860yZeJurDPaSVMCYuaiEzndvT1BnbMfnRutIqVmaO?= =?us-ascii?Q?J0NF219NP8fbsJ3qZj3nlwgEpz9JCY1FcKo62l/pvRrwlJmoq3GOufmGzrza?= =?us-ascii?Q?S4eLQ3jFoDuZtgzAUogXEe7qVizjcZKDWpHqPstetnFADawts5w8GW4+jvGV?= =?us-ascii?Q?rgRl8l/Fkjb4fCv0gFJrvcECgh400IAKgJDy8cN/cMgO5A4SOxK/3Km1SW31?= =?us-ascii?Q?WD66Ud77e4xnu+Oigt32/dPCg3IuKojlIR6E0tjyPRLqltQMp4lgQUDSSXjh?= =?us-ascii?Q?1Ia+Bx66K8ui2vsams47ZYNJvwi6vOi4J4LrVf2E?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: bb2a2ab9-f3b5-443b-78f8-08daa2776dbd X-MS-Exchange-CrossTenant-AuthSource: MWHPR1001MB2158.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2022 00:05:05.4475 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: BdIPPQsG63HjZ0Qy8QaWZy8UqIsr0UYrFhdGpYN8FKCEm5iclXM36V2ZkgJsJ1EQXr7UJOozvxGxSqzu+RdmRg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB6397 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-29_13,2022-09-29_03,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 bulkscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2209290150 X-Proofpoint-GUID: vCrrHAhgM-TxkYxkxVzEgfxt_4GTqGCY X-Proofpoint-ORIG-GUID: vCrrHAhgM-TxkYxkxVzEgfxt_4GTqGCY X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_ASCII_DIVIDERS,KAM_SHORT,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: The header sframe.h defines the SFrame format. The SFrame format is the Simple Frame format. It can be used to represent the minimal necessary unwind information required for backtracing. The current version supports AMD64 and AARCH64. More details of the SFrame format are included in the documentation of the header file in this patch. include/ChangeLog: * sframe.h: New file. --- include/sframe.h | 281 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 281 insertions(+) create mode 100644 include/sframe.h diff --git a/include/sframe.h b/include/sframe.h new file mode 100644 index 00000000000..b761be6e297 --- /dev/null +++ b/include/sframe.h @@ -0,0 +1,281 @@ +/* SFrame format description. + Copyright (C) 2022 Free Software Foundation, Inc. + + This file is part of libsframe. + + libsframe is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation; either version 3, or (at your option) any later + version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not see + . */ + +#ifndef _SFRAME_H +#define _SFRAME_H + +#include +#include +#include + +#include "ansidecl.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +/* SFrame format. + + SFrame format is a simple format to represent the information needed + for vanilla virtual stack unwinding. SFrame format keeps track of the + minimal necessary information needed for stack unwinding: + - Canonical Frame Address (CFA) + - Frame Pointer (FP) + - Return Address (RA) + + The SFrame section itself has the following structure: + + +--------+------------+---------+ + | file | function | frame | + | header | descriptor | row | + | | entries | entries | + +--------+------------+---------+ + + The file header stores a magic number and version information, flags, and + the byte offset of each of the sections relative to the end of the header + itself. The file header also specifies the total number of Function + Descriptor Entries, Frame Row Entries and length of the FRE sub-section. + + Following the header is a list of Function Descriptor Entries (FDEs). + This list may be sorted if the flags in the file header indicate it to be + so. The sort order, if applicable, is the order of functions in the + .text.* sections in the resulting binary artifact. Each Function + Descriptor Entry specifies the start PC of a function, the size in bytes + of the function and an offset to its first Frame Row Entry (FRE). Each FDE + additionally also specifies the type of FRE it uses to encode the unwind + information. + + Next, the Frame Row Entry section is a list of variable size records, + each of which represent SFrame unwind information for a set of PCs. A + singular Frame Row Entry is a self-sufficient record with information on + how to virtually unwind the stack for the applicable set of PCs. + + */ + + +/* SFrame format versions. */ +#define SFRAME_VERSION_1 1 +/* SFrame magic number. */ +#define SFRAME_MAGIC 0xdee2 +/* Current version of SFrame format. */ +#define SFRAME_VERSION SFRAME_VERSION_1 + +/* Various flags for SFrame. */ + +/* Function Descriptor Entries are sorted on PC. */ +#define SFRAME_F_FDE_SORTED 0x1 +/* Frame-pointer based unwinding. */ +#define SFRAME_F_FRAME_POINTER 0x2 + +#define SFRAME_CFA_FIXED_FP_INVALID 0 +#define SFRAME_CFA_FIXED_RA_INVALID 0 + +/* Supported ABIs/Arch. */ +#define SFRAME_ABI_AARCH64_ENDIAN_BIG 1 /* AARCH64 big endian. */ +#define SFRAME_ABI_AARCH64_ENDIAN_LITTLE 2 /* AARCH64 little endian. */ +#define SFRAME_ABI_AMD64_ENDIAN_LITTLE 3 /* AMD64 little endian. */ + +/* SFrame FRE types. */ +#define SFRAME_FRE_TYPE_ADDR1 1 +#define SFRAME_FRE_TYPE_ADDR2 2 +#define SFRAME_FRE_TYPE_ADDR4 3 + +/* SFrame Function Descriptor Entry types. + + The SFrame format has two possible representations for functions. The + choice of which type to use is made according to the instruction patterns + in the relevant program stub. + + A SFrame FDE of type SFRAME_FDE_TYPE_PCINC is an indication + that the PCs in the FREs should be treated as increments in bytes. This is + used for a bulk of the executable code of a program, which contains + instructions with no specific pattern. + + A SFrame FDE of type SFRAME_FDE_TYPE_PCMASK is an indication + that the PCs in the FREs should be treated as masks. This type is useful + for the cases when a small pattern of instructions in a program stub is + repeatedly to cover a specific functionality. Typical usescases are pltN + entries, trampolines etc. */ + +/* Unwinders perform a (PC >= FRE_START_ADDR) to look up a matching FRE. */ +#define SFRAME_FDE_TYPE_PCINC 0 +/* Unwinders perform a (PC & FRE_START_ADDR_AS_MASK >= FRE_START_ADDR_AS_MASK) + to look up a matching FRE. */ +#define SFRAME_FDE_TYPE_PCMASK 1 + +typedef struct sframe_preamble +{ + uint16_t sfp_magic; /* Magic number (SFRAME_MAGIC). */ + uint8_t sfp_version; /* Data format version number (SFRAME_VERSION). */ + uint8_t sfp_flags; /* Flags. */ +} ATTRIBUTE_PACKED sframe_preamble; + +typedef struct sframe_header +{ + sframe_preamble sfh_preamble; + /* Information about the arch (endianness) and ABI. */ + uint8_t sfh_abi_arch; + /* Offset for the Frame Pointer (FP) from CFA may be fixed for some + ABIs (e.g, in AMD64 when -fno-omit-frame-pointer is used). When fixed, + this field specifies the fixed stack frame offset and the individual + FREs do not need to track it. When not fixed, it is set to + SFRAME_CFA_FIXED_FP_INVALID, and the individual FREs may provide + the applicable stack frame offset, if any. */ + int8_t sfh_cfa_fixed_fp_offset; + /* Offset for the Return Address from CFA is fixed for some ABIs + (e.g., AMD64 has it as CFA-8). When fixed, the header specifies the + fixed stack frame offset and the individual FREs do not track it. When + not fixed, it is set to SFRAME_CFA_FIXED_RA_INVALID, and individual + FREs provide the applicable stack frame offset, if any. */ + int8_t sfh_cfa_fixed_ra_offset; + /* Number of SFrame FDEs in this SFrame section. */ + uint32_t sfh_num_fdes; + /* Number of SFrame Frame Row Entries. */ + uint32_t sfh_num_fres; + /* Number of bytes in the SFrame Frame Row Entry section. */ + uint32_t sfh_fre_len; + /* Offset of SFrame Function Descriptor Entry section. */ + uint32_t sfh_fdeoff; + /* Offset of SFrame Frame Row Entry section. */ + uint32_t sfh_freoff; +} ATTRIBUTE_PACKED sframe_header; + +typedef struct sframe_func_desc_entry +{ + /* Function start address. Encoded as a signed offset, relative to the + beginning of the current FDE. */ + int32_t sfde_func_start_address; + /* Size of the function in bytes. */ + uint32_t sfde_func_size; + /* Offset of the first SFrame Frame Row Entry of the function, relative to the + beginning of the SFrame Frame Row Entry sub-section. */ + uint32_t sfde_func_start_fre_off; + /* Number of frame row entries for the function. */ + uint32_t sfde_func_num_fres; + /* Additional information for deciphering the unwind information for the + function. + - 4-bits: Identify the FRE type used for the function. + - 1-bit: Identify the FDE type of the function - mask or inc. + - 3-bits: Unused. + -------------------------------------------- + | Unused | FDE type | FRE type | + -------------------------------------------- + 8 5 4 0 */ + uint8_t sfde_func_info; +} ATTRIBUTE_PACKED sframe_func_desc_entry; + +/* Macros to compose and decompose function info in FDE. */ + +#define SFRAME_V1_FUNC_INFO(fde_type, fre_enc_type) \ + (((fde_type) & 0x1) << 4 | (fre_enc_type)) + +#define SFRAME_V1_FUNC_FRE_TYPE(data) ((data) & 0xf) +#define SFRAME_V1_FUNC_FDE_TYPE(data) ((data >> 4) & 0x1) + +/* Size of stack frame offsets in an SFrame Frame Row Entry. A single + SFrame FRE has all offsets of the same size. Offset size may vary + across frame row entries. */ +#define SFRAME_FRE_OFFSET_1B 0 +#define SFRAME_FRE_OFFSET_2B 1 +#define SFRAME_FRE_OFFSET_4B 2 + +/* A SFrame Frame Row Entry can be SP or FP based. */ +#define SFRAME_BASE_REG_FP 0 +#define SFRAME_BASE_REG_SP 1 + +/* The index at which a specific offset is presented in the variable length + bytes of an FRE. */ +#define SFRAME_FRE_CFA_OFFSET_IDX 0 +#define SFRAME_FRE_FP_OFFSET_IDX 1 +#define SFRAME_FRE_RA_OFFSET_IDX 2 + +typedef struct sframe_fre_info +{ + /* Information about + - 1 bit: base reg for CFA + - 4 bits: Number of offsets (N). A value of upto 3 is allowed to track + all three of CFA, FP and RA (fixed implicit order). + - 2 bits: information about size of the offsets (S) in bytes. + Valid values are SFRAME_FRE_OFFSET_1B, SFRAME_FRE_OFFSET_2B, + SFRAME_FRE_OFFSET_4B + - 1 bit: Unused. + ----------------------------------------------------------------------- + | Unused | Size of offsets | Number of offsets | base_reg | + ----------------------------------------------------------------------- + 8 7 5 1 0 + + */ + uint8_t fre_info; +} sframe_fre_info; + +/* Macros to compose and decompose FRE info. */ + +#define SFRAME_V1_FRE_INFO(base_reg_id, offset_num, offset_size) \ + ((offset_size << 5) | (offset_num << 1) | (base_reg_id)) + +#define SFRAME_V1_FRE_CFA_BASE_REG_ID(data) ((data) & 0x1) +#define SFRAME_V1_FRE_OFFSET_COUNT(data) (((data) >> 1) & 0xf) +#define SFRAME_V1_FRE_OFFSET_SIZE(data) (((data) >> 5) & 0x3) + +/* SFrame Frame Row Entry definitions. + + Used for both AMD64 and AARCH64. + + A SFrame Frame Row Entry is a self-sufficient record containing SFrame + unwind info for a range of addresses, starting at the specified offset in + the function. Each SFrame Frame Row Entry is followed by S*N bytes, where: + S is the size of the stack frame offset for the FRE, and + N is the number of stack frame offsets in the FRE + + The offsets are interpreted in order as follows: + offset1 (interpreted as CFA = BASE_REG + offset1) + offset2 (interpreted as FP = CFA + offset2) + offset3 (interpreted as RA = CFA + offset3) +*/ + +typedef struct sframe_frame_row_entry_addr1 +{ + /* Start address of the frame row entry. Encoded as an 1-byte unsigned + offset, relative to the start address of the function. */ + uint8_t sfre_start_address; + sframe_fre_info sfre_info; +} ATTRIBUTE_PACKED sframe_frame_row_entry_addr1; + +typedef struct sframe_frame_row_entry_addr2 +{ + /* Start address of the frame row entry. Encoded as an 2-byte unsigned + offset, relative to the start address of the function. */ + uint16_t sfre_start_address; + sframe_fre_info sfre_info; +} ATTRIBUTE_PACKED sframe_frame_row_entry_addr2; + +typedef struct sframe_frame_row_entry_addr4 +{ + /* Start address of the frame row entry. Encoded as a 4-byte unsigned + offset, relative to the start address of the function. */ + uint32_t sfre_start_address; + sframe_fre_info sfre_info; +} ATTRIBUTE_PACKED sframe_frame_row_entry_addr4; + +#ifdef __cplusplus +} +#endif + +#endif /* _SFRAME_H */ -- 2.37.2