From patchwork Fri Mar 19 13:26:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 1455854 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=ExAReKiY; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F24SM75bbz9s1l for ; Sat, 20 Mar 2021 00:27:15 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0DA39384A01D; Fri, 19 Mar 2021 13:27:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0DA39384A01D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1616160434; bh=VU1szCNw7+bBArLTTl09mqGD+pJmXc0G2pw6Q3wfdWA=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ExAReKiY08W0QS8mrwW0rt6/vDevXUW5oml9ka5HsBYfn/6MUaZRFj7pI6coZ9GIw nMusmI4j5EF8bpIYxsPnpaNZ7Cd9Xem5quLN6bGP/ZUQ9NWJRRNkID/a5k+pUiaqXW ZjNP82FKl/Uc0ia+OMIwf5fWfkAw93CtBkIIJxU8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2043.outbound.protection.outlook.com [40.107.21.43]) by sourceware.org (Postfix) with ESMTPS id 11EF73857C7F for ; Fri, 19 Mar 2021 13:27:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 11EF73857C7F Received: from AM6P194CA0049.EURP194.PROD.OUTLOOK.COM (2603:10a6:209:84::26) by DB6PR0801MB2085.eurprd08.prod.outlook.com (2603:10a6:4:79::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.32; Fri, 19 Mar 2021 13:27:08 +0000 Received: from VE1EUR03FT026.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:84:cafe::b4) by AM6P194CA0049.outlook.office365.com (2603:10a6:209:84::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18 via Frontend Transport; Fri, 19 Mar 2021 13:27:08 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; sourceware.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;sourceware.org; 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; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT026.mail.protection.outlook.com (10.152.18.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18 via Frontend Transport; Fri, 19 Mar 2021 13:27:08 +0000 Received: ("Tessian outbound 26664f7d619a:v87"); Fri, 19 Mar 2021 13:27:07 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 146ff488219cd4c4 X-CR-MTA-TID: 64aa7808 Received: from 5749acc68fb2.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 25345A89-CDCC-4730-9FE7-F286BF44E215.1; Fri, 19 Mar 2021 13:27:01 +0000 Received: from EUR01-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 5749acc68fb2.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 19 Mar 2021 13:27:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aLMNmDIol4BhOCm/41rhXKgsYJg/QwwTTusYnsJn3tpfAhVicWQx1UgTUTp6li9UOfkOa75XeY3LSbmZaH58d0ZACvmidm+2y3MVJ+75Gn8shII9u757hTCX9pKlm7iR9VKWaDmVN1URerFvMCryXKjz9fqcOkfdXay7M8FKgxu+qxmsKR36x3heF3HRxqvJpwGMNkk54cu299vcKD4+vzoCAGRHo+dgNtyNngYyJabcNEYFz1vki9Z73b/5BzvC1enVnlaf8MEDAxjN/+O3Yo+SUVWhu3roS6t+u3BgNFenxYhnwzqiRn6zQ5/raUQ1Vym955Zz9jCRhHpaPl3+yg== 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-SenderADCheck; bh=VU1szCNw7+bBArLTTl09mqGD+pJmXc0G2pw6Q3wfdWA=; b=UFJDO8+PgQY1y9UQRdy/PNP+MIDUUxw2a/fG0BuuQRlrIuv5GTiILRCSIlpfUfinXzZv3W2A7A81oYkE7bo91q6++CgaEQNgS0Fr8udqvyn8he6sgxu3EznSklPPtvcFlPLsuhSFcbvdU27Op3OvXyMqwpSMnOJ6kEMnrMbyIAuMaxRDUIP65ADIQfJ6PBy9Z7zGgHE4A8vEJwmt2A5z4zUr0/cSynNeM/HgEdGlhfb81ZJ2zal2wWhSgiCgT44ghpSZ6lK4++knlQKEdmTbp/gTZ8JFbKIVoPWiP5rBc7kPq2ZxjbRWgbu1c50XlxLky0htkI7KFNYOY4N876f+AQ== 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 Authentication-Results-Original: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=arm.com; Received: from PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) by PA4PR08MB5966.eurprd08.prod.outlook.com (2603:10a6:102:ee::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18; Fri, 19 Mar 2021 13:26:59 +0000 Received: from PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::60f0:3773:69b8:e336]) by PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::60f0:3773:69b8:e336%2]) with mapi id 15.20.3955.018; Fri, 19 Mar 2021 13:26:59 +0000 To: libc-alpha@sourceware.org, DJ Delorie Subject: [PATCH 3/6] malloc: Use chunk2rawmem throughout Date: Fri, 19 Mar 2021 13:26:49 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [217.140.106.49] X-ClientProxiedBy: BL1PR13CA0092.namprd13.prod.outlook.com (2603:10b6:208:2b9::7) To PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (217.140.106.49) by BL1PR13CA0092.namprd13.prod.outlook.com (2603:10b6:208:2b9::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.9 via Frontend Transport; Fri, 19 Mar 2021 13:26:58 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: f191c643-71b2-4bba-0bda-08d8eadab22d X-MS-TrafficTypeDiagnostic: PA4PR08MB5966:|DB6PR0801MB2085: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:10000;OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: l6bOQnPcj6kD3HIrL1ULYdZPi+Fs1z5KFtaSMa+GSFBE1kZgwzNsM5DO3RMH5MtUowsQ1sD10qKYpe+pmC9FkIcAj2J5QtqMlS8lV6D2egxfoutHQLleYLPP2I/96eNheO4tzrB54rk52KBilXQYQ8NhSIkfnwb4O0hSPac+JskWusoVbvRCWwATmIhcemDrPkkl/tmnAw89ciewlXym07Rn9UdEchn+MEZrrlf0FkYGZMLVc5omgZvk2pe2iYFw789rbBcUwG6m0YvmJeunR+cVudpkWFX/vZqFTCa0JcrNsMAWXOX+Ebvk75Q1NuaN3xnrpORADgIdKLDTl9/lhjovNY7Gp85Ie5sXe/yL1a6j2bTGKP4yS73INV8dN0u9spAcJ9XrdRt8pQXpvKpKq34GvSygfZ8u9Yw/kfUnZmMwe4GTdirJrWEU5yX05Vw/kOqsntWIiH+v0bAYzR475VAuiJwkmDobEL+7JY740U4pYN1SGLYP+JWzCFCtmy8AYk2gO/Pz4GW0+Pd7QsBDovT4YFpDeJDyO9Xb4qjap44Fmvw0Uv9YvV+M6BSLVSWBWDeOJhx8SMG9bxQbTcHKjReZSZ8QAauK2M3NRLwUVtwCWZPHp38pd53KZzAvWOSs/judxV+raMeV+oDxM7GqFraLrw+RHXai3c1XgAhA47DWQJ/zuRLqIT0gmXGYq3bQ X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PA4PR08MB6320.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(2616005)(6916009)(26005)(36756003)(8936002)(6512007)(44832011)(5660300002)(8676002)(66556008)(66476007)(186003)(2906002)(6666004)(6506007)(66946007)(69590400012)(16526019)(86362001)(6486002)(83380400001)(498600001)(52116002)(38100700001)(956004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 1UQaZ3+h7tHG58l1XTfrH6nsFUMmj/qlCJLSodKgrJFJ4GOE3KcBqEYuSSfla8uJLsYrKKRIUFHQD30+u0E+mKz4G6T7v0J8Jf0phbLSjhkDJJM/o5uNVUD8p7SY4jR7pZZwHN5yJH4zayeg4zGLTnxPLs3JWFUqA0gl833eZVJPsQ1saccVbtla7Ai/2HOB4daKe0XzneASEevH5jNenWFlw2043qyKrt3FTAoi6+o/ZqnoNrp6cyPf3tr2pq/W2gwEbFtTQNHxeY9Oifmr++QBfXfIg10uZPYVC3X/zgQ9+YfzecQcGa/l/6/doz0SlV/XWuFLkajoBZwJhICMy3OiynviigHrwIxh8TAdDJHL4cD5QY5mIrV21SAslUr7NMaDoTnJky3hqkEVePeb9kmj9Jc7y9TolMslq4ZDNGBtciLERskUJb7zz5Jezn4kp/TMzZIi93YhwW3sjS3drRRQSbY//gEsK0Z2K2w7XA8XdveYyRBVee5Zue+b2SZKE2PBlTAfzH4ZVt7iI/XRaHOMFoGvBWjEf7ctnrBiun7k5l8yytxL1NTIjgly44fBaEFv5999gboAdBIeQ/dLjZDvRDSAqvBRtjKcxyfJKk/CQGQ66Fq2JphF+cZK+doqOePyZ1AEpSHKokL2D5Dxf88qtGj6mTsxot1MgDljBCR6THXLsSxPl61DyPI8zHje7zG2TiUXUenJhoPik7dKU9mNiO8kWXIMcHTTO6rNjbD9zqL8QKtiZwAje7v9TbjKdzUtGh9EtriC0jllbxxqiCwQbb/o0KoSbRcHQJP/BUvuQPdvyR77/vVg3uqqOBIfzRJliuWbr3WElMrDXh+oOZB6aGlQnj/orkKFT1dslOABISsbcF4gEgw8IHVyxnml7dqlbgpA4NCzuSuzsIeWMt0cAP5S6J20C46P/n7YfmTco17trTMO6xU3z2/e+ixGuWBVJytoJv3+Mqm/llfATHobO1gEmBLhAnVvagSfpmBN4TgoDAbWEc05xWDJlfmcYHrMLQZdHf1If+sD673dT+vvbosWs0s460dtK5KZHokOR2S9o1qaUMa66/mCn81fQH4sRES2Frszn33f57UsBIGW584DbsQUwgAh3lbNt82fmYJRJ7vhpVOfHckU66/c4pVpqLs2YHXGotXaAGbTHZrTKPP+BsbjOA3lq/G7pIS8ppB5holbwbsP5ADmpDO1GzK42DJKImDK47C8udPWrIl/q8QiHuqSFF0jPN+uLp93oqUqb7mpdzdXnSXcC3dBeZIWdLvJ3XWeOG7RXhKh45CzX2UmNwEnwoE4RGxq319bDN4qV4wkzbXwLgUa+gUQ X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB5966 Original-Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT026.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: fbe2583b-411d-4b06-37bd-08d8eadaac7e X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RkozR9lgi+jz4x7ZR+4/NLAt5D8QDeDGq9XcDiJ6/WkgQWgo9KUgdcUBNxE1IEbclFTDleVDDda+5gyudaazn4R6FDDRUG77zcD8dLK3S3JI4h7qlJQEtFA9UwWva6avCY/5nIryfygzJpZ0jEATo7nREh8Keksp9v8WsV7oRZ+oiOKAuPVH+iUO87Fp/vInO8bd+9IRzO3eVM54475g9h0FX6E990GqxNtPv8ZVOHAfHN07szqZdG/xC0wGuiap2yCoLIuqzsDr47iTvytmzajMNIcKKeKmtusZtCdbsJcc+A/M1/2gFtrUSJNPpKhIFdX+y4TzF2buYzcFULd0R4rAnMgxgA8BGz7W46Db6U0U/lbz9+hvPSL9eDc1M1QfJRDYK/dC7yQUMJdz384TxLDwjlidI8mpqMw7H+6FBnfhC1ytFqoRtDVUUJu5BesDmKslk5GoyNA4KNtkI+vewZRRugd8V+l38tcDvRIrgBnCYcag4+vi3pUNdvSRsnI8nhcPXe3jOEVdW7QWkEiaoIVFtAeQz+m+8/KVzVIklUQJqWaJVb72w1EAk/a1psxGnqWRH1z7N9bXaSPovMrsoimfxklbs8Y8NvtlK918EagDbAV3Bo8Lv8/j3/O+BwEOHAqJFRSf6a0hgMueGWOrQVLUEDKW+yFIIGLyKz4hEM6pu1mQXhC2cotFOq61JKNc 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:(4636009)(136003)(39860400002)(346002)(376002)(396003)(46966006)(36840700001)(16526019)(186003)(8676002)(8936002)(2906002)(44832011)(6486002)(2616005)(6862004)(81166007)(83380400001)(6666004)(26005)(316002)(70206006)(70586007)(956004)(336012)(5660300002)(6512007)(36756003)(86362001)(478600001)(82310400003)(36860700001)(82740400003)(69590400012)(356005)(47076005)(6506007); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Mar 2021 13:27:08.4165 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f191c643-71b2-4bba-0bda-08d8eadab22d 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: VE1EUR03FT026.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB2085 X-Spam-Status: No, score=-14.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Szabolcs Nagy via Libc-alpha From: Szabolcs Nagy Reply-To: Szabolcs Nagy Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The difference between chunk2mem and chunk2rawmem is that the latter does not get the memory tag for the returned pointer. It turns out chunk2rawmem almost always works: The input of chunk2mem is a chunk pointer that is untagged so it can access the chunk header. All memory that is not user allocated heap memory is untagged, which in the current implementation means that it has the 0 tag, but this patch does not rely on the tag value. The patch relies on that chunk operations are either done on untagged chunks or without doing memory access to the user owned part. Internal interface contracts: sysmalloc: Returns untagged memory. _int_malloc: Returns untagged memory. _int_free: Takes untagged memory. _int_memalign: Returns untagged memory. _int_realloc: Takes and returns tagged memory. So only _int_realloc and functions outside this list need care. Alignment checks do not need the right tag and tcache works with untagged memory. tag_at was kept in realloc after an mremap, which is not strictly necessary, since the pointer is only used to retag the memory, but this way the tag is guaranteed to be different from the old tag. --- malloc/hooks.c | 2 +- malloc/malloc.c | 58 ++++++++++++++++++++++++++++--------------------- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/malloc/hooks.c b/malloc/hooks.c index b82ff5781b..e888adcdc3 100644 --- a/malloc/hooks.c +++ b/malloc/hooks.c @@ -330,7 +330,7 @@ realloc_check (void *oldmem, size_t bytes, const void *caller) #if HAVE_MREMAP mchunkptr newp = mremap_chunk (oldp, chnb); if (newp) - newmem = chunk2mem (newp); + newmem = tag_at (chunk2rawmem (newp)); else #endif { diff --git a/malloc/malloc.c b/malloc/malloc.c index 34884808e2..9ddb65f029 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -1286,18 +1286,26 @@ nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ headers have distinct tags. Converting fully from one to the other involves extracting the tag at the other address and creating a suitable pointer using it. That can be quite expensive. There are - many occasions, though when the pointer will not be dereferenced - (for example, because we only want to assert that the pointer is - correctly aligned). In these cases it is more efficient not - to extract the tag, since the answer will be the same either way. - chunk2rawmem() can be used in these cases. - */ + cases when the pointers are not dereferenced (for example only used + for alignment check) so the tags are not relevant, and there are + cases when user data is not tagged distinctly from malloc headers + (user data is untagged because tagging is done late in malloc and + early in free). User memory tagging across internal interfaces: + + sysmalloc: Returns untagged memory. + _int_malloc: Returns untagged memory. + _int_free: Takes untagged memory. + _int_memalign: Returns untagged memory. + _int_memalign: Returns untagged memory. + _mid_memalign: Returns tagged memory. + _int_realloc: Takes and returns tagged memory. +*/ /* The chunk header is two SIZE_SZ elements, but this is used widely, so we define it here for clarity later. */ #define CHUNK_HDR_SZ (2 * SIZE_SZ) -/* Convert a user mem pointer to a chunk address without correcting +/* Convert a chunk address to a user mem pointer without correcting the tag. */ #define chunk2rawmem(p) ((void*)((char*)(p) + CHUNK_HDR_SZ)) @@ -1320,7 +1328,7 @@ nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ #define aligned_OK(m) (((unsigned long)(m) & MALLOC_ALIGN_MASK) == 0) #define misaligned_chunk(p) \ - ((uintptr_t)(MALLOC_ALIGNMENT == CHUNK_HDR_SZ ? (p) : chunk2mem (p)) \ + ((uintptr_t)(MALLOC_ALIGNMENT == CHUNK_HDR_SZ ? (p) : chunk2rawmem (p)) \ & MALLOC_ALIGN_MASK) /* pad request bytes into a usable size -- internal version */ @@ -2528,7 +2536,7 @@ sysmalloc (INTERNAL_SIZE_T nb, mstate av) check_chunk (av, p); - return chunk2mem (p); + return chunk2rawmem (p); } } } @@ -2898,7 +2906,7 @@ sysmalloc (INTERNAL_SIZE_T nb, mstate av) set_head (p, nb | PREV_INUSE | (av != &main_arena ? NON_MAIN_ARENA : 0)); set_head (remainder, remainder_size | PREV_INUSE); check_malloced_chunk (av, p, nb); - return chunk2mem (p); + return chunk2rawmem (p); } /* catch all failure paths */ @@ -3030,7 +3038,7 @@ mremap_chunk (mchunkptr p, size_t new_size) assert (chunk_is_mmapped (p)); uintptr_t block = (uintptr_t) p - offset; - uintptr_t mem = (uintptr_t) chunk2mem(p); + uintptr_t mem = (uintptr_t) chunk2rawmem(p); size_t total_size = offset + size; if (__glibc_unlikely ((block | total_size) & (pagesize - 1)) != 0 || __glibc_unlikely (!powerof2 (mem & (pagesize - 1)))) @@ -3096,7 +3104,7 @@ static __thread tcache_perthread_struct *tcache = NULL; static __always_inline void tcache_put (mchunkptr chunk, size_t tc_idx) { - tcache_entry *e = (tcache_entry *) chunk2mem (chunk); + tcache_entry *e = (tcache_entry *) chunk2rawmem (chunk); /* Mark this chunk as "in the tcache" so the test in _int_free will detect a double free. */ @@ -3411,7 +3419,7 @@ __libc_realloc (void *oldmem, size_t bytes) newp = mremap_chunk (oldp, nb); if (newp) { - void *newmem = chunk2mem (newp); + void *newmem = tag_at (chunk2rawmem (newp)); /* Give the new block a different tag. This helps to ensure that stale handles to the previous mapping are not reused. There's a performance hit for both us and the @@ -3852,7 +3860,7 @@ _int_malloc (mstate av, size_t bytes) } } #endif - void *p = chunk2mem (victim); + void *p = chunk2rawmem (victim); alloc_perturb (p, bytes); return p; } @@ -3910,7 +3918,7 @@ _int_malloc (mstate av, size_t bytes) } } #endif - void *p = chunk2mem (victim); + void *p = chunk2rawmem (victim); alloc_perturb (p, bytes); return p; } @@ -4011,7 +4019,7 @@ _int_malloc (mstate av, size_t bytes) set_foot (remainder, remainder_size); check_malloced_chunk (av, victim, nb); - void *p = chunk2mem (victim); + void *p = chunk2rawmem (victim); alloc_perturb (p, bytes); return p; } @@ -4043,7 +4051,7 @@ _int_malloc (mstate av, size_t bytes) { #endif check_malloced_chunk (av, victim, nb); - void *p = chunk2mem (victim); + void *p = chunk2rawmem (victim); alloc_perturb (p, bytes); return p; #if USE_TCACHE @@ -4205,7 +4213,7 @@ _int_malloc (mstate av, size_t bytes) set_foot (remainder, remainder_size); } check_malloced_chunk (av, victim, nb); - void *p = chunk2mem (victim); + void *p = chunk2rawmem (victim); alloc_perturb (p, bytes); return p; } @@ -4313,7 +4321,7 @@ _int_malloc (mstate av, size_t bytes) set_foot (remainder, remainder_size); } check_malloced_chunk (av, victim, nb); - void *p = chunk2mem (victim); + void *p = chunk2rawmem (victim); alloc_perturb (p, bytes); return p; } @@ -4351,7 +4359,7 @@ _int_malloc (mstate av, size_t bytes) set_head (remainder, remainder_size | PREV_INUSE); check_malloced_chunk (av, victim, nb); - void *p = chunk2mem (victim); + void *p = chunk2rawmem (victim); alloc_perturb (p, bytes); return p; } @@ -4419,7 +4427,7 @@ _int_free (mstate av, mchunkptr p, int have_lock) if (tcache != NULL && tc_idx < mp_.tcache_bins) { /* Check to see if it's already in the tcache. */ - tcache_entry *e = (tcache_entry *) chunk2mem (p); + tcache_entry *e = (tcache_entry *) chunk2rawmem (p); /* This test succeeds on double free. However, we don't 100% trust it (it also matches random payload data at a 1 in @@ -4491,7 +4499,7 @@ _int_free (mstate av, mchunkptr p, int have_lock) malloc_printerr ("free(): invalid next size (fast)"); } - free_perturb (chunk2mem(p), size - CHUNK_HDR_SZ); + free_perturb (chunk2rawmem(p), size - CHUNK_HDR_SZ); atomic_store_relaxed (&av->have_fastchunks, true); unsigned int idx = fastbin_index(size); @@ -4564,7 +4572,7 @@ _int_free (mstate av, mchunkptr p, int have_lock) || __builtin_expect (nextsize >= av->system_mem, 0)) malloc_printerr ("free(): invalid next size (normal)"); - free_perturb (chunk2mem(p), size - CHUNK_HDR_SZ); + free_perturb (chunk2rawmem(p), size - CHUNK_HDR_SZ); /* consolidate backward */ if (!prev_inuse(p)) { @@ -4964,7 +4972,7 @@ _int_memalign (mstate av, size_t alignment, size_t bytes) { set_prev_size (newp, prev_size (p) + leadsize); set_head (newp, newsize | IS_MMAPPED); - return chunk2mem (newp); + return chunk2rawmem (newp); } /* Otherwise, give back leader, use the rest */ @@ -4995,7 +5003,7 @@ _int_memalign (mstate av, size_t alignment, size_t bytes) } check_inuse_chunk (av, p); - return chunk2mem (p); + return chunk2rawmem (p); }