From patchwork Wed Nov 10 08:58:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 47372 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2C70A3858409 for ; Wed, 10 Nov 2021 09:08:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2C70A3858409 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636535287; bh=V6eGJuR2wtIOEpxZzA0yCtbsxOfJzsze95ejJ/mGid8=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=uDlhQ/0qs6z7M5gifbldFaaOP5r4OpN5j3tIjcrhLJgW8p3yiEvEfchtNsf3bqaI6 YYpooShdLT9yxu13NUlIsD+BdM786f8nDshRUNKisAZjlnYQxTda2BB0orm14rCbXW iDw+FjdXkIo8OZGQxgJNO7S/Axuj7B6uiLZUK3B4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by sourceware.org (Postfix) with ESMTPS id 4D894385802A for ; Wed, 10 Nov 2021 08:58:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4D894385802A Received: by mail-lj1-x22f.google.com with SMTP id 1so3913708ljv.2 for ; Wed, 10 Nov 2021 00:58:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=V6eGJuR2wtIOEpxZzA0yCtbsxOfJzsze95ejJ/mGid8=; b=ak3VzFSJIpxGP+00yru4lTH4Rm54EgIa8YAUGh2ZTJdBNjdVcySPHWUva4Z2K6DmBI sJCUWIwWVN4aCfkGTjDvyop2HHvYPytw/cmqWjU1y/TsDgAO4yc58M+g19HOPFqMGiVZ Qg1o1VbaJBSOoXYoDdiJEwzCcOZ6G28QWJIWKpAQfp6wDhUrNhS9dgmjhqNkrMZcFX2n Mv7ri1z2ycsJsCuo3aN7nBs0nabvjSXH7l0kwnma6sR9CTFH64BlN9Gv1B4CK1muIdjC uvM5QwZIs4LThqTwJ4X/0j6AQ92SmmghYQfGekJ5mLxi0e66ovULovrQL4tXLa7472fQ Fw3Q== X-Gm-Message-State: AOAM531VbRwi2dTVF4HsETNk7F0SdCVFI9o1gNfVQTMqixTMRVe3v0lm PkVJFywx96cIT7DiHssaQXMh5H4XRVcDug== X-Google-Smtp-Source: ABdhPJzV1LgYqLx8i3SoxrwUOfm38lq813aZR6fB7Fn+p+FI3KIwM12NcACFrtuLpGLVVKboLTTuJQ== X-Received: by 2002:a2e:9e9a:: with SMTP id f26mr14537061ljk.5.1636534723231; Wed, 10 Nov 2021 00:58:43 -0800 (PST) Received: from adacore.com ([2a02:2ab8:224:2ce:72b5:e8ff:feef:ee60]) by smtp.gmail.com with ESMTPSA id q5sm56434lfu.18.2021.11.10.00.58.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Nov 2021 00:58:42 -0800 (PST) Date: Wed, 10 Nov 2021 08:58:41 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Do not assume a priority value of zero is a valid priority Message-ID: <20211110085841.GA2811161@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.1 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Patrick Bernardi Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" While a priority value of zero is typically valid on most systems, there are some targets where zero may be reserved for OS purposes (for example: RTEMS where zero is reserved for use by the idle thread and should not be used by applications). This patch removes one occurrence in GNARL where a Priority object was initialized to zero instead of Priority'First, and adjusts the Priority type on RTEMS to prevent the use of priority level zero. By contrast, System.Tasking.Unspecified_Priority is hardcoded as -1 since it is used in init.c, which does not have access to the Priority type. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * libgnarl/s-taskin.adb (Initialize_ATCB): Initialize T.Common.Current_Priority to Priority'First. * libgnarl/s-taskin.ads (Unspecified_Priority): Redefined as -1. * libgnat/system-rtems.ads: Start priority range from 1, as 0 is reserved by the operating system. diff --git a/gcc/ada/libgnarl/s-taskin.adb b/gcc/ada/libgnarl/s-taskin.adb --- a/gcc/ada/libgnarl/s-taskin.adb +++ b/gcc/ada/libgnarl/s-taskin.adb @@ -127,7 +127,7 @@ package body System.Tasking is end if; pragma Assert (T.Common.Domain /= null); - T.Common.Current_Priority := 0; + T.Common.Current_Priority := Priority'First; T.Common.Protected_Action_Nesting := 0; T.Common.Call := null; T.Common.Task_Arg := Task_Arg; diff --git a/gcc/ada/libgnarl/s-taskin.ads b/gcc/ada/libgnarl/s-taskin.ads --- a/gcc/ada/libgnarl/s-taskin.ads +++ b/gcc/ada/libgnarl/s-taskin.ads @@ -773,7 +773,10 @@ package System.Tasking is -- Priority info -- ------------------- - Unspecified_Priority : constant Integer := System.Priority'First - 1; + Unspecified_Priority : constant Integer := -1; + -- Indicates that a task has an unspecified priority. This is hardcoded as + -- -1 rather than System.Priority'First - 1 as the value needs to be used + -- in init.c to specify that the main task has no specified priority. Priority_Not_Boosted : constant Integer := System.Priority'First - 1; -- Definition of Priority actually has to come from the RTS configuration diff --git a/gcc/ada/libgnat/system-rtems.ads b/gcc/ada/libgnat/system-rtems.ads --- a/gcc/ada/libgnat/system-rtems.ads +++ b/gcc/ada/libgnat/system-rtems.ads @@ -109,15 +109,13 @@ package System is -- hardware priority levels. Protected Object ceilings can -- override these values. -- 245 is used by the Interrupt_Manager task - -- 0 is reserved for the RTEMS IDLE task and really should not - -- be accessible from Ada but GNAT initializes - -- Current_Priority to 0 so it must be valid + -- 0 is reserved for the RTEMS IDLE task Max_Priority : constant Positive := 244; Max_Interrupt_Priority : constant Positive := 254; - subtype Any_Priority is Integer range 0 .. 254; - subtype Priority is Any_Priority range 0 .. 244; + subtype Any_Priority is Integer range 1 .. 254; + subtype Priority is Any_Priority range 1 .. 244; subtype Interrupt_Priority is Any_Priority range 245 .. 254; Default_Priority : constant Priority := 122;