From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60048.outbound.protection.outlook.com [40.107.6.48]) by sourceware.org (Postfix) with ESMTPS id 6FB2E3840C2A for ; Tue, 19 May 2020 09:53:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6FB2E3840C2A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Szabolcs.Nagy@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=8GAl4Wz/IFuzrRS6N947AxxwiplFsHcw/+TfqgJrQnY=; b=QO9lFAFg0e5yM2Sg4RleD/SCBwjGMbnqAWY96HQFIOosJo9B3hP5sN5fQ0va3mNrhIux1LE7trt9HLhhre7tCp7qylPBQyO/9/ej3y8bkMKt5QjYK3w6v+dHUGg4ZV557p03ZZd+7tjau9opDZoYLy0twgtPxImN/J9uryPowTQ= Received: from DB8PR06CA0018.eurprd06.prod.outlook.com (2603:10a6:10:100::31) by DB6PR0801MB1784.eurprd08.prod.outlook.com (2603:10a6:4:39::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.27; Tue, 19 May 2020 09:53:03 +0000 Received: from DB5EUR03FT029.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:100:cafe::d0) by DB8PR06CA0018.outlook.office365.com (2603:10a6:10:100::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.24 via Frontend Transport; Tue, 19 May 2020 09:53:03 +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=bestguesspass 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 DB5EUR03FT029.mail.protection.outlook.com (10.152.20.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.19 via Frontend Transport; Tue, 19 May 2020 09:53:02 +0000 Received: ("Tessian outbound d078647f4174:v57"); Tue, 19 May 2020 09:53:02 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: a0f77f0b2b332d08 X-CR-MTA-TID: 64aa7808 Received: from 119e1e44b324.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 8E0863BE-674B-47A6-A866-80BA037114B2.1; Tue, 19 May 2020 09:52:57 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 119e1e44b324.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 19 May 2020 09:52:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VfX/CzLdIKI+z1NcTUbHUAkhc6eNtYKsxiQ60kZ2Hq2AT3tTMEDdAQZrct5yG7w7X74YqsBIBsLATlVC3Xtv93YnKvIqQJ08zPgl/73E8cBu99P21+w2cQsj8rVH7ix8IMdVm31t1/Wo9wnp/UFISM85xVe83ceV729XOXtd62gFV048OWYvhuBWG3/YKAe7A0kk+ox8WQ3W/fspTCaK5/ICMiHVzMgB77VLZ9A7V5cZdcvJ4n/7YmhEZKV8Xl/HUEVgIa/illJzBm76q3FGGc+0QQjiCHr2sd5UPEPJYSFm9BR09NN44fjhWbwTf8fIE7V2zQkTi7I9XgINMMW5yA== 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=8GAl4Wz/IFuzrRS6N947AxxwiplFsHcw/+TfqgJrQnY=; b=k6W2uyS6yiZT8keKWzIMvFADiHTQS31kZjk9z/k+6I+doGQV3bqIsjD8t3Gj6la8LhXzhOsgjx7ra6Kyqu3nzJaYiwR2CL0hf5lR93kTn2xGyNYwUko21l9qC3DGDxl7gcu+P0Bcutwpz+6QkdNZN2lKuRhsC2gL1GKkRjQ7rZD1y9JefQHFruqOitZoo+7vAqNI+uHcjboaAFrXmdb3aXa3Am0wGEmme66yy/8sSXL9D4wdfQe3LWfJ4Dt2VoRT/qiDPS6sg44GWGzWSW3Y4AjRmU55++bSQc8NeAeOvDvoErWnzS47zPfKOQ3DXhlfrMSsVLa8TJSZ9cjvnvEKdQ== 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=8GAl4Wz/IFuzrRS6N947AxxwiplFsHcw/+TfqgJrQnY=; b=QO9lFAFg0e5yM2Sg4RleD/SCBwjGMbnqAWY96HQFIOosJo9B3hP5sN5fQ0va3mNrhIux1LE7trt9HLhhre7tCp7qylPBQyO/9/ej3y8bkMKt5QjYK3w6v+dHUGg4ZV557p03ZZd+7tjau9opDZoYLy0twgtPxImN/J9uryPowTQ= 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 AM6PR08MB3047.eurprd08.prod.outlook.com (2603:10a6:209:4c::23) by AM6PR08MB3605.eurprd08.prod.outlook.com (2603:10a6:20b:48::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 09:52:55 +0000 Received: from AM6PR08MB3047.eurprd08.prod.outlook.com ([fe80::49fd:6ded:4da7:8862]) by AM6PR08MB3047.eurprd08.prod.outlook.com ([fe80::49fd:6ded:4da7:8862%7]) with mapi id 15.20.3000.034; Tue, 19 May 2020 09:52:55 +0000 From: Szabolcs Nagy To: newlib@sourceware.org Subject: [PATCH] Reimplement aligned_alloc Date: Tue, 19 May 2020 10:52:49 +0100 Message-Id: <20200519095249.22326-1-szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 Content-Type: text/plain X-ClientProxiedBy: LO2P265CA0186.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a::30) To AM6PR08MB3047.eurprd08.prod.outlook.com (2603:10a6:209:4c::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (217.140.106.55) by LO2P265CA0186.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.26 via Frontend Transport; Tue, 19 May 2020 09:52:55 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [217.140.106.55] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 5ff6d05c-8b71-46e4-e755-08d7fbda6c00 X-MS-TrafficTypeDiagnostic: AM6PR08MB3605:|DB6PR0801MB1784: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:913;OLM:913; X-Forefront-PRVS: 040866B734 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: acw7RjBoh0ssyWSRXjMXP2PblIEqFRN9sURUwgW9SqFXxEJyG1EoQZkL9HA9x8L/Tr3Rbk3lFGiPQyWMimuhfJzCA08s5qg6NUQDPUYjAgaRIX676AngbuaF1cOTpOdEmm7lBNPB+Ey4PGhOjRu2AJ7LMsW4Qp6Cj3mdoKmpHOkJ1Ha2BsNRjrXD17pA/Wt9/+6L4syLdcnUzl8b7ls50FW32FgoKrp1KxwyYsgCv3flRS/h733YxiznxBDsKQYl6jpcrsbtDE66EPLlRdDLUnB2/d3rGl0JcmqQ8s6qbev4myCYzTJ4I/5vDJ7qVXQnc15nbuSnIS8nu/sNJzgpoI/TmInBjeY3JMIdOzE8VM6nmvmTC6Kppb4YxEH7pEsD56OVLCywRu6Jbo+qZlrd5PpUrcrQPd2n2kfnDwE+mncqb1lOPsRtjSViEz53jmK2cL/MKyCGcug1Jz/rDDKCIcF37W5KSARcAkGxZ1dkSkP/jy4X0a8Qg2BTwapkZPrK X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR08MB3047.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(366004)(376002)(346002)(136003)(39860400002)(396003)(26005)(6512007)(6666004)(8676002)(36756003)(86362001)(44832011)(52116002)(66946007)(8936002)(66556008)(66476007)(1076003)(5660300002)(316002)(478600001)(69590400007)(6486002)(6506007)(6916009)(2616005)(956004)(16526019)(186003)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: OaAfov/D5LWVVDynX4T+h09+WmBuhsKe5p+8Bi0F2MZ4q9eaOsnS9CTMQJLl/i7Hn8Hmt5A7cUjZA06DeY8FTHZqToM12vG3SerjSgNbDSJ4V+MFK44+IGG7yu45Hoo1hnvKuWDWnbfxJmfWF1/HaQhPidda76vFnUzavmAqJOWmiNDaeICTDBGdJU0Vpc4M9UhIipQThyz7m8ocdNyeABej5ozUZ5+pJYv/T8S8+X4VKpYXBOE21VgH3JHizFCIT9wdtQ+9otVQf+l0mvaJ7KF7bEEvWOY3zVILbR5T+cAN3SkJUEfOQWCQ5m3+XI8Jw2boL3K/nlCJqFNfZrc/msMSOsiXTjtMPiqTIgf3kj1WFkkPFFQR2KV2IXoEcEN32M6vyoR2KlDaA2Shk4as9qVAFYn4u9bKRzi64isvjKRX3jdCUreC1AzlfhvNGlehyO4+bFBHy+bheFa8YbmWd/FWBw57Ued+DTgvSLqMYUrC/TUM5ZMelTmysIBfTse0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3605 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: DB5EUR03FT029.eop-EUR03.prod.protection.outlook.com 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; SFTY:; SFS:(4636009)(376002)(39860400002)(396003)(346002)(136003)(46966005)(47076004)(44832011)(16526019)(186003)(356005)(1076003)(26005)(81166007)(2906002)(82310400002)(336012)(82740400003)(6506007)(8676002)(6666004)(70206006)(8936002)(2616005)(956004)(70586007)(36756003)(6486002)(316002)(5660300002)(478600001)(6512007)(6916009)(86362001)(69590400007); DIR:OUT; SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: 6d220da9-3125-40db-9e21-08d7fbda6791 X-Forefront-PRVS: 040866B734 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mw390Z/8iPMjer64FVG1aGb+9Botb2uB2hH6tKjrSTzdX5rbDvz3hKYtLODLj2lOJxtdLutdai0CDMO1ixLUZ8gymcrccv5cJsRO5An/vWZVNijFqqLJCXEmKO4e9knZ/t7olJxIGuZwMZ6kzVtRYB1G0JV6zsA1tZqldmZRe8lFmdVBvhg8Rl8Vqigrok+aGFRVciYloHusFdI//+g5vCbBk27zmGx3rEoBIS9RQuDjqfmBMFc58M/YImyV/o0m1WzwYIIqUVprQgAtM+t7e0a/k5nGLbwq5T4vS4t/tcVpSfSRBz9iz5zqtKq14FVIaZbXnyDLNLEqO7uhcXlZ0UxmaTJ5sWArG+i8bdI3Ha/O1JqBrCKTucg2F3WnAvRBw+vbtMMHwQ4JoVdo5XkGz4k9GfKZQLTOD3FYEtX9g8f9NLu+0VS/ZxckVDDszIkvLxuPy1skS0jrb1jPSJJ3e1vg6FLN/eMJ0yp0x8gfx266uGj0VbBvQ0cIH0F2pKQ1CVTZCYNXdcD4Zm9Geboc3JTgRYiiQ913I9dx1bPGgBc= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 09:53:02.9575 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5ff6d05c-8b71-46e4-e755-08d7fbda6c00 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-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB1784 X-Spam-Status: No, score=-19.5 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: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 May 2020 09:53:06 -0000 The original implementation had multiple issues: - Only worked when posix_memalign was available (Linux, RTEMS). - Violated C11 link namespace rules by calling posix_memalign. - Failed to set errno on error. These can be fixed by essentially using the same implementation for aligned_alloc as for memalign, i.e. simply calling _memalign_r (which is always available and a "more reserved name" although technically still not in the reserved link namespace, at least code written in c cannot define a colliding symbol, newlib has plenty such namespace issues so this is fine). It is not clear what the right policy is when MALLOC_PROVIDED is set, currently that does not cover aligned_alloc so it is kept that way. Tested on aarch64-none-elf --- newlib/libc/stdlib/aligned_alloc.c | 62 +++++++++++++++--------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/newlib/libc/stdlib/aligned_alloc.c b/newlib/libc/stdlib/aligned_alloc.c index 88413ce86..feb22c24b 100644 --- a/newlib/libc/stdlib/aligned_alloc.c +++ b/newlib/libc/stdlib/aligned_alloc.c @@ -1,38 +1,36 @@ -/*- - * Copyright (c) 2015 embedded brains GmbH - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ +/* C11 aligned_alloc + Copyright (c) 2020 Arm Ltd. All rights reserved. + SPDX-License-Identifier: BSD-3-Clause + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. The name of the company may not be used to endorse or promote + products derived from this software without specific prior written + permission. + + THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include #include void * -aligned_alloc(size_t alignment, size_t size) +aligned_alloc (size_t align, size_t size) { - void *p; - int error; - - error = posix_memalign(&p, alignment, size); - - return (error == 0 ? p : NULL); + return _memalign_r (_REENT, align, size); } -- 2.17.1