From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2072.outbound.protection.outlook.com [40.107.104.72]) by sourceware.org (Postfix) with ESMTPS id 59A5D3855155 for ; Mon, 12 Dec 2022 14:22:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 59A5D3855155 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Q3l5uSPgzPRJ1VBigh/eibwpbnIRpoGSAzjYLGi4UCE=; b=gIQ4RO+fyHH9x3Fqzz7hl9ac/0kWQfkkK1ut+KKl7CJnftHZeWGTkq+0fxbODJx0v6A1J5McWpCo6ER6qP4x+NxM+nF4ZxViYzJK2DL4qmGw0MJWFR3mUd726cs0J4DG2hVv6LvuZ2XjwFk6c69miqeoCv3GymqUkJy0U5oPqGg= Received: from AM5PR1001CA0066.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:206:15::43) by AS8PR08MB10313.eurprd08.prod.outlook.com (2603:10a6:20b:5c1::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.8; Mon, 12 Dec 2022 14:22:09 +0000 Received: from AM7EUR03FT059.eop-EUR03.prod.protection.outlook.com (2603:10a6:206:15:cafe::86) by AM5PR1001CA0066.outlook.office365.com (2603:10a6:206:15::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.19 via Frontend Transport; Mon, 12 Dec 2022 14:22:09 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM7EUR03FT059.mail.protection.outlook.com (100.127.140.215) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5901.21 via Frontend Transport; Mon, 12 Dec 2022 14:22:09 +0000 Received: ("Tessian outbound f394866f3f2b:v130"); Mon, 12 Dec 2022 14:22:09 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: a921fa1b7a1e648e X-CR-MTA-TID: 64aa7808 Received: from dacc885ae1b6.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id DD1F9461-6689-4509-8A0C-08B587B28D5E.1; Mon, 12 Dec 2022 14:22:01 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id dacc885ae1b6.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 12 Dec 2022 14:22:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iAwhhNytji2zD41Ke1QrQ3khaMeYc44IZU5Vf4cMQnHflHBu1JQ8dNcTZrxMhTBcGM3ewBvQ0RbcGlYKanojGhZhgAnfAqK8AxFVEznFWkErL6QM6IdqVwvTIFraxtFzP/hePEA2N7bA0TjxKdeohItWMa4EnG1tq7Ra2NwSXe05GobFC2I8OGwjKRs6e3+wUcj11Lpsh3MRaZTihGJdrRYQjsk5tXi1Nx2iWm5bsjRhfnjsx4yH266THFTexU9uNnPvjnoSHeWPE7xWrMnT6kpJLNVm0qXNIemU/JAamcq2iZdwubuE0rtkgMUUO236Oc9HGSfHVODO2uTs7/advw== 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=Q3l5uSPgzPRJ1VBigh/eibwpbnIRpoGSAzjYLGi4UCE=; b=iRUIr95QQsXXPyk6PNYOlEVO9UzaM/qhUXkubgfbevNeMlTF1DyIw0hj1p3Xt4EdzD0Wyg40ZxgbSGzfc4vPh9UVda6VVqiOWkR1WRgV2bKkOPVQMbq3KyTUzIC4Ak1VaiG32LJ23UhoBTJbl+ZVAlBnfCFIu9QBB2E+BlyDB1s+VowlWaXj/5gBKsdXMMC6yyEiYLO49BJcUyIJEyFpnD9R/y+S67X4z/RWjcSFDSzKxchn/LyW/c3osDFaWY20PJD2RNhXfI5XFEtj8wRAahaj6NpopBT2TQuuAO/wgQ5VONZm5411mN/zBoRbtTrR6668e844NSJaPbRFUBYV6g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Q3l5uSPgzPRJ1VBigh/eibwpbnIRpoGSAzjYLGi4UCE=; b=gIQ4RO+fyHH9x3Fqzz7hl9ac/0kWQfkkK1ut+KKl7CJnftHZeWGTkq+0fxbODJx0v6A1J5McWpCo6ER6qP4x+NxM+nF4ZxViYzJK2DL4qmGw0MJWFR3mUd726cs0J4DG2hVv6LvuZ2XjwFk6c69miqeoCv3GymqUkJy0U5oPqGg= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) by DB9PR08MB8227.eurprd08.prod.outlook.com (2603:10a6:10:39f::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.7; Mon, 12 Dec 2022 14:21:53 +0000 Received: from VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::eed7:25a3:e4ea:187a]) by VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::eed7:25a3:e4ea:187a%7]) with mapi id 15.20.5924.009; Mon, 12 Dec 2022 14:21:53 +0000 Message-ID: Date: Mon, 12 Dec 2022 14:21:46 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH,v3] [aarch64] Fix removal of non-address bits for PAuth Content-Language: en-US To: Simon Marchi , gdb-patches@sourceware.org Cc: lsix@lancelotsix.com, thiago.bauermann@linaro.org References: <20220705140037.135012-1-luis.machado@arm.com> <20220823202936.1561526-1-luis.machado@arm.com> From: Luis Machado In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: SA9PR10CA0019.namprd10.prod.outlook.com (2603:10b6:806:a7::24) To VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: VI1PR08MB3919:EE_|DB9PR08MB8227:EE_|AM7EUR03FT059:EE_|AS8PR08MB10313:EE_ X-MS-Office365-Filtering-Correlation-Id: 7e2797ec-f6a2-4ee4-a11f-08dadc4c4139 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: vFaMf7JieoAianG1jipMwnRFNihseIB/IqZN2cAfK39o2WpswPMszvKu4Z10qNGajQPcAFPJFsqJn5ZcA2aPagbBNkS+KOo+gwY1OeNpHocsAVXcjhiQBBJ5ikgj8EmgzaaVwcptykKBoTiglNb0mG4G5GeXZy5sVgCg2tHfRfRRRHjMN2jOk6s2DY7+gLWLvL8trikaMLxfCVOOvOdRi4NfPkdUzP1VOQaRJdNf5m+/dbUfDB1pZMouBkYSaypLx/CPpCjFpNPCju+CaScfsW5AXT7jvQgjtFAoCSq3H2Nt4iIapTkpscHM8MumboLJcvZ+keS5H5KUJaoeyVmJP53JnqHCFJuXQrmbKQsPSICkbig4rUIKDca617stpUc56MMcEdMcb0XCroqvO5HoUhFXUl2qIzPgvuOeGLYJFECLTHxBqnQsGkHTtI9hOYb0mbRm/F8xaGyAPb/AYje+R6/IW5/wLeCxw+mXcGqHRTxzvejtk+kRZbaiJeLgXFo7e9iJt7xOQuO5tsO8Y+86M2qIeF33efw/7wa+Ob9U1E7C9Vs6YdMa1CLCDK9Ru2yXrUnte9ty4zyZXzo5dCIsOnjzummFsVPEF0QrtK5tq+lZ1n+kF3sAlLk5McZVpo0iBbgeRPpec4RDE7PLam0arTWm3/7guyfFWwFLjfmskuRDH1x8fMd4zveKmWgpvvFTjvv/t97Ol8zoV5iSdqOKCxG60d4AKEcjJFJ3ROp7WKbueByuqvEffaqfwSi3RZ5RJdoAXB2WiDdWastQa4eXnQ== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR08MB3919.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(39860400002)(346002)(366004)(376002)(396003)(136003)(451199015)(31696002)(6486002)(86362001)(38100700002)(316002)(478600001)(2906002)(5660300002)(8936002)(66946007)(66476007)(66556008)(44832011)(41300700001)(83380400001)(8676002)(4326008)(53546011)(6666004)(6506007)(6512007)(186003)(26005)(2616005)(31686004)(36756003)(2004002)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB8227 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM7EUR03FT059.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 64141dfe-7a25-4e37-5d00-08dadc4c378f X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Y9fKc3xlXlB6iq9T9OEHadHvjYFLuOYOsmUI8OTvwXzEG1fnvf0Qfi1bo8LDazImGEOvJexLX2Q9afbcwtbQrDzRoNrlVK9zHinYo0VVvYKOsVTJXiRv8kgM6DBpv0VsTBzlmchPBOGob3Slji9exArFCUIz7nOfWXn2hUPD7uVqMFUTkOLe0FdyvjEA+ZSpiWp9GEuICV8NbB+gQY74AyF5tS3ZdOnfAel6dz85zjARyMbWV6CCk/uVZRD+JOH6y+HsUyERBE1ru/WcxD5lsKo4dyaLJe6gWmuLNca0NjKdZgHbbsFMKhFZNKI+mtlyABIIgxqt6nMpxTNKF+hinI5y1ss6wVoGC720gK7mf8QIusjVgim6FuTYuH5edakHhjiRWeh6O071subuUKmcyMSjsAX9C7pbsEoB+qAy7iIm5r7NbNNbn2yqJojeXqlXc9UO/5QRRiMX4mNItEo9IH2iYpWnjgMgNzaeuP25CwRUfyp5ky/sftlTim/jJYRSndjt2RpLDzyPn2E+3j84duuj8v+NW1QamapDjzZIo+QlUW8yzA2QLyK+A6dSJ5N664yRgVShCA10DvuSmqOJLgbRxkFwTeB/+lXUZk4++eBJyKYmQE6ShwRZgkXrcB0WB5f32AjhYKSZfjZtC6n5UDD3JxgJLEdePNiuSpFIRvJ+maJJpOtn03PChcFI0yvROulSLvj5Wd2dcjcEoibwpKysjciTT75Ci1xdTuFWqJHZN+y09K1R4tizPR0eWtpCZywxSaYs3CU1CxBPDc2guKBMtIFaY5sWKBHBFZIKXGw= X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230022)(4636009)(136003)(39860400002)(396003)(376002)(346002)(451199015)(40470700004)(46966006)(36840700001)(31686004)(36756003)(53546011)(107886003)(8936002)(86362001)(44832011)(5660300002)(82740400003)(40460700003)(6506007)(81166007)(356005)(36860700001)(6486002)(31696002)(186003)(83380400001)(40480700001)(316002)(478600001)(47076005)(6666004)(4326008)(8676002)(2616005)(82310400005)(70206006)(41300700001)(70586007)(6512007)(26005)(336012)(2906002)(2004002)(43740500002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2022 14:22:09.5486 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7e2797ec-f6a2-4ee4-a11f-08dadc4c4139 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM7EUR03FT059.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB10313 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,KAM_DMARC_NONE,KAM_SHORT,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP,UNPARSEABLE_RELAY 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: Hi Simon, On 12/9/22 19:14, Simon Marchi wrote: >> @@ -1961,6 +1962,47 @@ aarch64_linux_decode_memtag_section (struct gdbarch *gdbarch, >> return tags; >> } >> >> +/* AArch64 implementation of the remove_non_address_bits gdbarch hook. Remove >> + non address bits from a pointer value. */ >> + >> +static CORE_ADDR >> +aarch64_remove_non_address_bits (struct gdbarch *gdbarch, CORE_ADDR pointer) >> +{ >> + aarch64_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); >> + >> + /* By default, we assume TBI and discard the top 8 bits plus the VA range >> + select bit (55). */ >> + CORE_ADDR mask = AARCH64_TOP_BITS_MASK; > Declare mask in the context where it's needed. > I decided to declare it here in case we skip the if block, then we return the default value. Did you have something else in mind? >> + >> + if (tdep->has_pauth ()) >> + { >> + /* Fetch the PAC masks. These masks are per-process, so we can just >> + fetch data from whatever thread we have at the moment. >> + >> + Also, we have both a code mask and a data mask. For now they are the >> + same, but this may change in the future. */ >> + struct regcache *regs = get_current_regcache (); >> + CORE_ADDR cmask, dmask; >> + >> + if (regs->cooked_read (tdep->pauth_reg_base, &dmask) != REG_VALID) >> + dmask = mask; >> + >> + if (regs->cooked_read (tdep->pauth_reg_base + 1, &cmask) != REG_VALID) >> + cmask = mask; >> + >> + if (dmask != cmask) >> + { >> + /* Warn if the masks are different. */ >> + aarch64_pauth_mask_warning (); >> + mask |= dmask > cmask? dmask : cmask; > > I think we typically put a space before the ? operator, like for other > operators. > Fixed. >> @@ -143,4 +156,8 @@ enum aarch64_regnum >> /* Maximum supported VQ value. Increase if required. */ >> #define AARCH64_MAX_SVE_VQ 16 >> >> +/* Mask with 1's in bits 55~63, used to remove the top byte of pointers >> + (Top Byte Ignore). */ >> +#define AARCH64_TOP_BITS_MASK (~((((CORE_ADDR) 1) << (64 - 9)) - 1)) > > I think I would find it clearer to just have the numerical value right > there. > Done. >> diff --git a/gdb/gdbarch-components.py b/gdb/gdbarch-components.py >> index 71aa5991fbe..25b6d69d2d9 100644 >> --- a/gdb/gdbarch-components.py >> +++ b/gdb/gdbarch-components.py >> @@ -1116,15 +1116,23 @@ possible it should be in TARGET_READ_PC instead). >> invalid=False, >> ) >> >> -Value( >> +Method( >> comment=""" >> -On some machines, not all bits of an address word are significant. >> -For example, on AArch64, the top bits of an address known as the "tag" >> -are ignored by the kernel, the hardware, etc. and can be regarded as >> -additional data associated with the address. >> +On some architectures, not all bits of a pointer are significant. >> +On AArch64, for example, the top bits of a pointer may carry a "tag", which >> +can be ignored by the kernel and the hardware. The "tag" can be regarded as >> +additional data associated with the pointer, but it is not part of the address. >> + >> +Given a pointer for the architecture, this hook removes all the >> +non-significant bits and sign-extends things as needed. It gets used to remove >> +non-address bits from data pointers (for example, removing the AArch64 MTE tag >> +bits from a pointer) and from code pointers (removing the AArch64 PAC signature >> +from a pointer containing the return address). > > Two spaces after period above, a few times. > Oops. Fixed. >> diff --git a/gdb/testsuite/gdb.arch/aarch64-non-address-bits.exp b/gdb/testsuite/gdb.arch/aarch64-non-address-bits.exp >> new file mode 100644 >> index 00000000000..2b5a7b2f517 >> --- /dev/null >> +++ b/gdb/testsuite/gdb.arch/aarch64-non-address-bits.exp >> @@ -0,0 +1,121 @@ >> +# Copyright 2022 Free Software Foundation, Inc. >> +# >> +# This program 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 of the License, 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. If not, see . >> +# >> +# This file is part of the gdb testsuite. >> +# >> +# Test that GDB for AArch64/Linux can properly handle pointers with >> +# the upper 16 bits (PAC) or 8 bits (Tag) set, as well as the >> +# VA_RANGE_SELECT bit (55). >> + >> +if {![is_aarch64_target]} { >> + verbose "Skipping ${gdb_test_file_name}." >> + return >> +} >> + >> +global hex >> +global decimal > > I don't think it's useful to put a global declaration like this in the > global scope. And as you probably know by know, I encourage people to > use the $::hex notation anyway, which doesn't need the global keyword. > Indeed. Fixed now to use the global access notation. >> + >> +standard_testfile >> +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { >> + return -1 >> +} >> + >> +if ![runto_main] { >> + return -1 >> +} >> + >> +# We need to iterate over two distinct ranges, separated by a single bit. >> +# This bit is 55 (VA_RANGE_SELECT) which tells us if we have a kernel-space >> +# address or a user-space address. >> + >> +# The tag field has 8 bits. >> +set tag_bits_count 8 >> + >> +# The pac field has 7 bits. >> +set pac_bits_count 7 >> + >> +# A couple patterns that we reuse for the tests later. One is for a successful >> +# memory read and the other is for a memory read failure. >> +set memory_read_ok_pattern "$hex\( \)?:\[ \t\]+$hex" >> +set memory_read_fail_pattern "$hex:\[ \t\]+Cannot access memory at address $hex" >> + >> +set pac_enabled 0 >> + >> +# Check if PAC is enabled. >> +gdb_test_multiple "ptype \$pauth_cmask" "fetch PAC cmask" { >> + -re "type = long\r\n$gdb_prompt" { >> + set pac_enabled 1 >> + } >> + -re "type = void\r\n$gdb_prompt" { >> + } > > Pedantically, you probably want to consume a space after the > $gdb_prompt. You could also use -wrap in all three cases to simplify > them (and in the gdb_test_multiples below too). > Fixed it to use wrap now. Thanks! >> diff --git a/gdbserver/linux-aarch64-low.cc b/gdbserver/linux-aarch64-low.cc >> index db508696261..155706f1138 100644 >> --- a/gdbserver/linux-aarch64-low.cc >> +++ b/gdbserver/linux-aarch64-low.cc >> @@ -508,21 +508,36 @@ aarch64_target::low_remove_point (raw_bkpt_type type, CORE_ADDR addr, >> return ret; >> } >> >> -/* Return the address only having significant bits. This is used to ignore >> - the top byte (TBI). */ >> - >> static CORE_ADDR >> -address_significant (CORE_ADDR addr) >> +aarch64_remove_non_address_bits (CORE_ADDR pointer) >> { >> - /* Clear insignificant bits of a target address and sign extend resulting >> - address. */ >> - int addr_bit = 56; >> + /* By default, we assume TBI and discard the top 8 bits plus the >> + VA range select bit (55). */ >> + CORE_ADDR mask = AARCH64_TOP_BITS_MASK; >> + >> + /* Check if PAC is available for this target. */ >> + if (tdesc_contains_feature (current_process ()->tdesc, >> + "org.gnu.gdb.aarch64.pauth")) >> + { >> + /* Fetch the PAC masks. These masks are per-process, so we can just >> + fetch data from whatever thread we have at the moment. >> + >> + Also, we have both a code mask and a data mask. For now they are the >> + same, but this may change in the future. */ >> >> - CORE_ADDR sign = (CORE_ADDR) 1 << (addr_bit - 1); >> - addr &= ((CORE_ADDR) 1 << addr_bit) - 1; >> - addr = (addr ^ sign) - sign; >> + struct regcache *regs = get_thread_regcache (current_thread, 1); >> + CORE_ADDR dmask = regcache_raw_get_unsigned_by_name (regs, "pauth_dmask"); >> + CORE_ADDR cmask = regcache_raw_get_unsigned_by_name (regs, "pauth_cmask"); >> + >> + if (dmask != cmask && dmask != 0 && cmask != 0) >> + { >> + /* Warn if the masks are different. */ >> + aarch64_pauth_mask_warning (); >> + mask |= (dmask > cmask)? dmask : cmask; > > I think you can omit the parenthesis (like you did in the GDB version of > the code. Done. > > It would be nice to factor out what we can to the common code. Do you > think you can move this part to the common code? > > if (dmask != cmask && dmask != 0 && cmask != 0) > { > /* Warn if the masks are different. */ > aarch64_pauth_mask_warning (); > mask |= (dmask > cmask)? dmask : cmask; > } > > Simon > Done now. I'll send a v4. Thanks for the review.