From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 3A2DF385840F for ; Mon, 20 May 2024 07:49:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3A2DF385840F Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3A2DF385840F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::430 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716191362; cv=none; b=K1UeJJpaPReuY837xV7LLWHbcCkButQmCJKVhD3zoS8HCPOXpcD2POSiUWqSKCjZUOFzICi5dq1uYR6wUq3bGDvUXZlE5ofYNo6ZsWByxkdB8mmssKmDJwDvjxRiPTLtMM2zh7u++VuWwvOWZJzPYmvw3EOdAt5M4IRJHf38D0Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716191362; c=relaxed/simple; bh=EFrU92W4LEwldIs2AZwxIiJVQ3yCQB8biUt4ql8vbMo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=FGGpb92USMieYcU3IaCWbgb94zSuj26BWXC+OQ1Y0j0ne9BgtvC7VaR2Cnm6AVVGWqIvGO3x+L4VyvMpQxO9iW5T0Ayh3g8Ny+/jbNzBjHUdlvDGHoyFNwrUE5hFygIhxHledAzwOtFXNivh4aZsOYRYgSg/H5Wvxw2JK9FnSpU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-34db6a299b8so1577752f8f.3 for ; Mon, 20 May 2024 00:49:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1716191360; x=1716796160; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QIi9IjR18BPZRbiz1Ih2JxOpCaf511lXnEbLLlW2ZbI=; b=IuLZBJ2hE7m4glrveL41KBX8jSyjdK9iO0o+iAljrhcuLfsuyBtCxfbq8tb9jT86j9 BGj90Oc5iogT9GfkEd7nOIQs9BRRo2/+T+Z6DFNGyOXRHjuqBULsl6ROk4BJF3jcb3o0 JkMutCNrdrU9SHhX4LV04vSCouX4mDNDEGU5iYMKSeWoge7xKz/jhQbwtriAxDvlAiDg 27MSGvdPEusumiXuYFev7hzRhiQKvCEUcsuAyehHzug+Z1o/gwyUldraB23y3aQhAUWc HagOFkrUSXsOrHTB63ido4s8O667u/T3K+g1eeX8mSe5W7PLnYtMAkF0STV/fnN4ofgv uCwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716191360; x=1716796160; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QIi9IjR18BPZRbiz1Ih2JxOpCaf511lXnEbLLlW2ZbI=; b=l5DnwDJXbZPcQPiVWwBH0GkjbnY90kRG1e7Voh/0+L+3Ne8n+oFZlyZNaaq6GBNf4u 6o0MFe+bRF40jWqXB+Nw0dUJee36WNadYtmYbnesd7QCnWXYnqq5W+1uEDrY45Lalz1E 7OsSGHLWEndhWjbBuwwyJ5N2ftPnLcB+CecqvZUH5GNYdru3PEj9SQKaKB2ee23glyUp NB8ow62FYQUDBPz1fvMR6PE+JkBODgvBolMgsJNMyK3K/2dcKIo7nTNRBehnEUXYjOiC eArct1TwFjsh2j1D6C/fqr8G2kOPCMbqF2vqUYJK41i3SYOVK14c8ma4n//a93MwDoiu 86Gw== X-Gm-Message-State: AOJu0Yw/oN/QwkEJC5m1hhSHszIcBnhSgu484PtaaV8CbysQDbi+em1Q W0FmmLi9jd9kl6cmXIJJRBhihs1/psQWfQTCGFENfC3u2yiUIsgVkLyR45Z0TKjbByoRhPa2ffs = X-Google-Smtp-Source: AGHT+IGelEOPFY9HNSiUBKogtPdlLzwxaED0XycjdGN27JdrkHf6B7RZWPkapbWnJ0s1OtZbnHxiaA== X-Received: by 2002:a05:6000:e8f:b0:351:cb5b:7369 with SMTP id ffacd0b85a97d-351cb5b7514mr12473266f8f.33.1716191360046; Mon, 20 May 2024 00:49:20 -0700 (PDT) Received: from poulhies-Precision-5550.lan ([2001:861:3382:1a90:de37:8b1c:1f33:2610]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-41f88111033sm446892175e9.34.2024.05.20.00.49.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 00:49:19 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Ronan Desplanques Subject: [COMMITTED 11/30] ada: Fix incorrect free with Task_Info pragma Date: Mon, 20 May 2024 09:48:37 +0200 Message-ID: <20240520074858.222435-11-poulhies@adacore.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240520074858.222435-1-poulhies@adacore.com> References: <20240520074858.222435-1-poulhies@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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: From: Ronan Desplanques Before this patch, on Linux, the procedure System.Task_Primitives.Operations.Set_Task_Affinity called CPU_FREE on instances of cpu_set_t_ptr that it didn't own when the obsolescent Task_Info pragma was in play. This patch fixes that issue. gcc/ada/ * libgnarl/s-taprop__linux.adb (Set_Task_Affinity): Fix decision about whether to call CPU_FREE. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/libgnarl/s-taprop__linux.adb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/gcc/ada/libgnarl/s-taprop__linux.adb b/gcc/ada/libgnarl/s-taprop__linux.adb index 1faa3d8914e..0c09817739c 100644 --- a/gcc/ada/libgnarl/s-taprop__linux.adb +++ b/gcc/ada/libgnarl/s-taprop__linux.adb @@ -1466,12 +1466,13 @@ package body System.Task_Primitives.Operations is and then T.Common.LL.Thread /= Null_Thread_Id then declare - CPUs : constant size_t := - C.size_t (Multiprocessors.Number_Of_CPUs); - CPU_Set : cpu_set_t_ptr := null; - Size : constant size_t := CPU_ALLOC_SIZE (CPUs); + CPUs : constant size_t := + C.size_t (Multiprocessors.Number_Of_CPUs); + CPU_Set : cpu_set_t_ptr := null; + Is_Set_Owned : Boolean := False; + Size : constant size_t := CPU_ALLOC_SIZE (CPUs); - Result : C.int; + Result : C.int; begin -- We look at the specific CPU (Base_CPU) first, then at the @@ -1483,6 +1484,7 @@ package body System.Task_Primitives.Operations is -- Set the affinity to an unique CPU CPU_Set := CPU_ALLOC (CPUs); + Is_Set_Owned := True; System.OS_Interface.CPU_ZERO (Size, CPU_Set); System.OS_Interface.CPU_SET (int (T.Common.Base_CPU), Size, CPU_Set); @@ -1499,6 +1501,7 @@ package body System.Task_Primitives.Operations is -- dispatching domain. CPU_Set := CPU_ALLOC (CPUs); + Is_Set_Owned := True; System.OS_Interface.CPU_ZERO (Size, CPU_Set); for Proc in T.Common.Domain'Range loop @@ -1512,7 +1515,9 @@ package body System.Task_Primitives.Operations is pthread_setaffinity_np (T.Common.LL.Thread, Size, CPU_Set); pragma Assert (Result = 0); - CPU_FREE (CPU_Set); + if Is_Set_Owned then + CPU_FREE (CPU_Set); + end if; end; end if; end Set_Task_Affinity; -- 2.43.2