Skip to content

StackSizeControl

Simon Wright edited this page Aug 19, 2018 · 7 revisions

There are two kinds of stack in Cortex GNAT RTS, with distinct uses.

  • The initial stack
    • used during program boot.
    • used for interrupt handlers (which may be nested).
  • task stacks
    • used in the environment task, mainly for elaboration but thereafter for the main program.
    • used in ordinary tasks.

You can control the stack sizes at run time, by declaring special constants (perhaps best in your main program), as below. The values shown are the defaults, which will be used if you don't declare the constants.

For the initial stack (also used for interrupt programs),

   Default_Initial_Stack : constant Natural := 1024
   with
     Export,
     Convention => Ada,
     External_Name => "_default_initial_stack";

For the environment task,

   Environment_Task_Storage_Size : constant Natural := 1536
   with
     Export,
     Convention => Ada,
     External_Name => "_environment_task_storage_size";

For ordinary tasks,

   Default_Storage_Size : constant Natural := 1024
   with
     Export,
     Convention => Ada,
     External_Name => "_default_storage_size";

For the curious, the way this works can be seen in System.Parameters (s-parame.adb),

   --  If the link includes a symbol _default_storage_size,
   --  use this as the storage size: otherwise, use 1024.
   Default_Storage_Size : constant Size_Type
   with
     Import,
     Convention => Ada,
     External_Name => "_default_storage_size";
   pragma Weak_External (Default_Storage_Size);

   function Default_Stack_Size return Size_Type is
     (if Default_Storage_Size'Address = System.Null_Address
      then 1024
      else Default_Storage_Size);

Clone this wiki locally