public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Johannes Kliemann <kliemann@adacore.com>
Subject: [COMMITTED] ada: Ensure Default_Stack_Size is greater than Minimum_Stack_Size
Date: Tue, 30 May 2023 09:20:36 +0200	[thread overview]
Message-ID: <20230530072036.2499750-1-poulhies@adacore.com> (raw)

From: Johannes Kliemann <kliemann@adacore.com>

The Default_Stack_Size function does not check that the binder specified
default stack size is greater than the minimum stack size for the runtime.
This can result in tasks using default stack sizes less than the minimum
stack size because the Adjust_Storage_Size only adjusts storages sizes for
tasks that explicitly specify a storage size. To avoid this, the binder
specified default stack size is round up to the minimum stack size if
required.

gcc/ada/

	* libgnat/s-parame.adb: Check that Default_Stack_Size >=
	Minimum_Stack_size.
	* libgnat/s-parame__rtems.adb: Ditto.
	* libgnat/s-parame__vxworks.adb: Check that Default_Stack_Size >=
	Minimum_Stack_size and use the proper Minimum_Stack_Size if
	Stack_Check_Limits is enabled.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/libgnat/s-parame.adb          |  2 ++
 gcc/ada/libgnat/s-parame__rtems.adb   |  2 ++
 gcc/ada/libgnat/s-parame__vxworks.adb | 11 +++++++++--
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/libgnat/s-parame.adb b/gcc/ada/libgnat/s-parame.adb
index 930c92d35e2..6bd9f03f63f 100644
--- a/gcc/ada/libgnat/s-parame.adb
+++ b/gcc/ada/libgnat/s-parame.adb
@@ -58,6 +58,8 @@ package body System.Parameters is
    begin
       if Default_Stack_Size = -1 then
          return 2 * 1024 * 1024;
+      elsif Size_Type (Default_Stack_Size) < Minimum_Stack_Size then
+         return Minimum_Stack_Size;
       else
          return Size_Type (Default_Stack_Size);
       end if;
diff --git a/gcc/ada/libgnat/s-parame__rtems.adb b/gcc/ada/libgnat/s-parame__rtems.adb
index 2f2e70b1796..1d51ae9ec04 100644
--- a/gcc/ada/libgnat/s-parame__rtems.adb
+++ b/gcc/ada/libgnat/s-parame__rtems.adb
@@ -63,6 +63,8 @@ package body System.Parameters is
    begin
       if Default_Stack_Size = -1 then
          return 32 * 1024;
+      elsif Size_Type (Default_Stack_Size) < Minimum_Stack_Size then
+         return Minimum_Stack_Size;
       else
          return Size_Type (Default_Stack_Size);
       end if;
diff --git a/gcc/ada/libgnat/s-parame__vxworks.adb b/gcc/ada/libgnat/s-parame__vxworks.adb
index 8e0768e1e29..38fe0222622 100644
--- a/gcc/ada/libgnat/s-parame__vxworks.adb
+++ b/gcc/ada/libgnat/s-parame__vxworks.adb
@@ -58,11 +58,13 @@ package body System.Parameters is
    begin
       if Default_Stack_Size = -1 then
          if Stack_Check_Limits then
-            return 32 * 1024;
             --  Extra stack to allow for 12K exception area.
+            return 32 * 1024;
          else
             return 20 * 1024;
          end if;
+      elsif Size_Type (Default_Stack_Size) < Minimum_Stack_Size then
+         return Minimum_Stack_Size;
       else
          return Size_Type (Default_Stack_Size);
       end if;
@@ -74,7 +76,12 @@ package body System.Parameters is
 
    function Minimum_Stack_Size return Size_Type is
    begin
-      return 8 * 1024;
+      if Stack_Check_Limits then
+         --  Extra stack to allow for 12K exception area.
+         return 20 * 1024;
+      else
+         return 8 * 1024;
+      end if;
    end Minimum_Stack_Size;
 
 end System.Parameters;
-- 
2.40.0


                 reply	other threads:[~2023-05-30  7:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230530072036.2499750-1-poulhies@adacore.com \
    --to=poulhies@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=kliemann@adacore.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).