[COMMITTED] ada: Add QNX specific version of System.Parameters

Message ID 20230529082854.2409155-1-poulhies@adacore.com
State Committed
Commit f180888c8f38920e6731e5bc1dc5e06f5ac7d340
Headers
Series [COMMITTED] ada: Add QNX specific version of System.Parameters |

Commit Message

Marc Poulhiès May 29, 2023, 8:28 a.m. UTC
  From: Johannes Kliemann <kliemann@adacore.com>

The QNX runtimes used the default implementation of
System.Parameters that defines a default stack size
of 2 MB. The QNX specific version uses the QNX default
stack size of 256 KB instead.

gcc/ada/

	* Makefile.rtl (QNX): Use s-parame__qnx.adb for s-parame.adb.
	* libgnat/s-parame__qnx.adb: Add QNX specific version of
	System.Parameters.

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

---
 gcc/ada/Makefile.rtl              |  1 +
 gcc/ada/libgnat/s-parame__qnx.adb | 81 +++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+)
 create mode 100644 gcc/ada/libgnat/s-parame__qnx.adb
  

Patch

diff --git a/gcc/ada/Makefile.rtl b/gcc/ada/Makefile.rtl
index 2cfdd8dc613..3da32fa6668 100644
--- a/gcc/ada/Makefile.rtl
+++ b/gcc/ada/Makefile.rtl
@@ -1412,6 +1412,7 @@  ifeq ($(strip $(filter-out arm aarch64 %qnx,$(target_cpu) $(target_os))),)
   s-taspri.ads<libgnarl/s-taspri__posix.ads \
   s-tpopsp.adb<libgnarl/s-tpopsp__posix-foreign.adb \
   g-soliop.ads<libgnat/g-soliop__qnx.ads \
+  s-parame.adb<libgnat/s-parame__qnx.adb \
   $(ATOMICS_TARGET_PAIRS) \
   $(ATOMICS_BUILTINS_TARGET_PAIRS) \
   system.ads<libgnat/system-qnx-arm.ads
diff --git a/gcc/ada/libgnat/s-parame__qnx.adb b/gcc/ada/libgnat/s-parame__qnx.adb
new file mode 100644
index 00000000000..d9b46b6f795
--- /dev/null
+++ b/gcc/ada/libgnat/s-parame__qnx.adb
@@ -0,0 +1,81 @@ 
+------------------------------------------------------------------------------
+--                                                                          --
+--                         GNAT COMPILER COMPONENTS                         --
+--                                                                          --
+--                    S Y S T E M . P A R A M E T E R S                     --
+--                                                                          --
+--                                 B o d y                                  --
+--                                                                          --
+--          Copyright (C) 1995-2023, Free Software Foundation, Inc.         --
+--                                                                          --
+-- GNAT is free software;  you can  redistribute it  and/or modify it under --
+-- terms of the  GNU General Public License as published  by the Free Soft- --
+-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
+-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
+-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
+-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
+--                                                                          --
+-- As a special exception under Section 7 of GPL version 3, you are granted --
+-- additional permissions described in the GCC Runtime Library Exception,   --
+-- version 3.1, as published by the Free Software Foundation.               --
+--                                                                          --
+-- You should have received a copy of the GNU General Public License and    --
+-- a copy of the GCC Runtime Library Exception along with this program;     --
+-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
+-- <http://www.gnu.org/licenses/>.                                          --
+--                                                                          --
+-- GNAT was originally developed  by the GNAT team at  New York University. --
+-- Extensive contributions were provided by Ada Core Technologies Inc.      --
+--                                                                          --
+------------------------------------------------------------------------------
+
+--  This is the version for AArch64 QNX
+
+package body System.Parameters is
+
+   -------------------------
+   -- Adjust_Storage_Size --
+   -------------------------
+
+   function Adjust_Storage_Size (Size : Size_Type) return Size_Type is
+   begin
+      if Size = Unspecified_Size then
+         return Default_Stack_Size;
+      elsif Size < Minimum_Stack_Size then
+         return Minimum_Stack_Size;
+      else
+         return Size;
+      end if;
+   end Adjust_Storage_Size;
+
+   ------------------------
+   -- Default_Stack_Size --
+   ------------------------
+
+   function Default_Stack_Size return Size_Type is
+      Default_Stack_Size : constant Integer;
+      pragma Import (C, Default_Stack_Size, "__gl_default_stack_size");
+   begin
+      if Default_Stack_Size = -1 then
+         --  256K is the default stack size on aarch64 QNX
+         return 256 * 1024;
+      elsif Size_Type (Default_Stack_Size) < Minimum_Stack_Size then
+         return Minimum_Stack_Size;
+      else
+         return Size_Type (Default_Stack_Size);
+      end if;
+   end Default_Stack_Size;
+
+   ------------------------
+   -- Minimum_Stack_Size --
+   ------------------------
+
+   function Minimum_Stack_Size return Size_Type is
+   begin
+      --  256 is the value of PTHREAD_STACK_MIN on QNX and
+      --  12K is required for stack-checking. The value is
+      --  rounded up to a multiple of a 4K page.
+      return 16 * 1024;
+   end Minimum_Stack_Size;
+
+end System.Parameters;