Skip to content

Commit de0aae9

Browse files
committed
Implement Secondary_Stack_Size.
* common/gcc7/s-tarest.adb: if Secondary_Stack_Size isn't Unspecified_Size, use it as-is. * common/gnat-gpl-2017/s-tarest.adb: likewise. Remove unneeded 'with Interfaces;'. * common/gcc8/s-tarest.adb (Parameters): add SStack_Addr. (Wrapper): if P.SStack_Addr is null, allocate secondary stack on task stack. If it isn't, register it as-is in the ATCB. (Create_Restricted_Task): pass Sec_Stack_Address to Wrapper. If Secondary_Stack_Size isn't Unspecified_Size, use it as-is (regardless of whether it's going to be used).
1 parent 1f6fc56 commit de0aae9

File tree

3 files changed

+54
-25
lines changed

3 files changed

+54
-25
lines changed

common/gcc7/s-tarest.adb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
-- --
77
-- B o d y --
88
-- --
9-
-- Copyright (C) 2016, 2017 Free Software Foundation, Inc. --
9+
-- Copyright (C) 2016-2018 Free Software Foundation, Inc. --
1010
-- --
1111
-- GNARL is free software; you can redistribute it and/or modify it under --
1212
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -35,7 +35,7 @@
3535
-- This package represents the high level tasking interface used by the
3636
-- compiler to expand Ada 95 tasking constructs into simpler run time calls.
3737

38-
-- This is is the version for the Cortex GNAT RTS project.
38+
-- This is the version for the Cortex GNAT RTS project.
3939

4040
with Ada.Unchecked_Conversion;
4141
with System.Address_To_Access_Conversions;
@@ -107,7 +107,6 @@ package body System.Tasking.Restricted.Stages is
107107
Created_Task : Task_Id) is
108108

109109
pragma Unreferenced (Stack_Address);
110-
pragma Unreferenced (Secondary_Stack_Size);
111110
pragma Unreferenced (Task_Info);
112111
pragma Unreferenced (CPU);
113112
pragma Unreferenced (Chain);
@@ -121,6 +120,7 @@ package body System.Tasking.Restricted.Stages is
121120
constant Parameters_Conversion.Object_Pointer :=
122121
Parameters_Conversion.To_Pointer (Wrapper_Parameter_Address);
123122

123+
use type System.Parameters.Size_Type;
124124
use type FreeRTOS.Tasks.Task_Handle;
125125
begin
126126
if Wrapper_Parameter_Address = System.Null_Address then
@@ -131,7 +131,9 @@ package body System.Tasking.Restricted.Stages is
131131
Task_Proc => State,
132132
Discriminants => Discriminants,
133133
SStack_Size =>
134-
System.Parameters.Secondary_Stack_Size (Actual_Stack_Size));
134+
(if Secondary_Stack_Size = System.Parameters.Unspecified_Size
135+
then System.Parameters.Secondary_Stack_Size (Actual_Stack_Size)
136+
else Secondary_Stack_Size));
135137

136138
Created_Task.Common.Base_Priority := (if Priority = Unspecified_Priority
137139
then System.Default_Priority

common/gcc8/s-tarest.adb

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
-- --
77
-- B o d y --
88
-- --
9-
-- Copyright (C) 2016-2017 Free Software Foundation, Inc. --
9+
-- Copyright (C) 2016-2018 Free Software Foundation, Inc. --
1010
-- --
1111
-- GNARL is free software; you can redistribute it and/or modify it under --
1212
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -35,7 +35,7 @@
3535
-- This package represents the high level tasking interface used by the
3636
-- compiler to expand Ada 95 tasking constructs into simpler run time calls.
3737

38-
-- This is is the version for the Cortex GNAT RTS project.
38+
-- This is the version for the Cortex GNAT RTS project.
3939

4040
with Ada.Unchecked_Conversion;
4141
with System.Address_To_Access_Conversions;
@@ -55,6 +55,7 @@ package body System.Tasking.Restricted.Stages is
5555
ATCB : Task_Id;
5656
Task_Proc : Task_Procedure_Access;
5757
Discriminants : System.Address;
58+
SStack_Addr : System.Secondary_Stack.SS_Stack_Ptr;
5859
SStack_Size : System.Parameters.Size_Type;
5960
end record;
6061

@@ -63,25 +64,48 @@ package body System.Tasking.Restricted.Stages is
6364

6465
procedure Wrapper (Arg1 : System.Address) is
6566
function Convert_Task_Id
66-
is new Ada.Unchecked_Conversion (Task_Id, System.Address);
67+
is new Ada.Unchecked_Conversion (Task_Id, System.Address);
6768

6869
P : constant Parameters_Conversion.Object_Pointer :=
6970
Parameters_Conversion.To_Pointer (Arg1);
7071

71-
Secondary_Stack :
72-
aliased System.Secondary_Stack.SS_Stack (Size => P.SStack_Size);
73-
-- At this point, the stack is the task's stack
72+
use type System.Secondary_Stack.SS_Stack_Ptr;
7473
begin
7574
-- Save the ATCB in the FreeRTOS TCB
7675
FreeRTOS.TCB.Set_Application_Parameter (Convert_Task_Id (P.ATCB));
7776

78-
-- Register the secondary stack
79-
P.ATCB.Secondary_Stack := Secondary_Stack'Unchecked_Access;
80-
-- Unchecked_Access is OK because it can only be accessed from
81-
-- the current task, within Task_Proc.
82-
83-
-- Call the task procedure
84-
P.Task_Proc (P.Discriminants);
77+
-- Secondary stack handling:
78+
--
79+
-- If P.SStack_Addr is Null_Address, then we are to allocate a
80+
-- region from the bottom of the task's stack, size P.SStack_Size.
81+
--
82+
-- If P.SStack_Addr isn't Null_Address, it's a region of the
83+
-- task's package's BSS allocated and initialized by the
84+
-- compiler.
85+
86+
if P.SStack_Addr = null then
87+
declare
88+
-- At this point, the stack is the task's stack. Declare
89+
-- a stack here.
90+
Secondary_Stack :
91+
aliased System.Secondary_Stack.SS_Stack (Size => P.SStack_Size);
92+
begin
93+
-- Register the secondary stack
94+
P.ATCB.Secondary_Stack := Secondary_Stack'Unchecked_Access;
95+
-- Unchecked_Access is OK because it can only be accessed from
96+
-- the current task, within Task_Proc.
97+
98+
-- Call the task procedure. The secondary stack is still
99+
-- on the stack.
100+
P.Task_Proc (P.Discriminants);
101+
end;
102+
else
103+
-- Register the compiler-allocated secondary stack
104+
P.ATCB.Secondary_Stack := P.SStack_Addr;
105+
106+
-- Call the task procedure
107+
P.Task_Proc (P.Discriminants);
108+
end if;
85109

86110
-- If we return here, the task procedure has exited (and not
87111
-- because of an exception, which would already have reached
@@ -108,8 +132,6 @@ package body System.Tasking.Restricted.Stages is
108132
Created_Task : Task_Id) is
109133

110134
pragma Unreferenced (Stack_Address);
111-
pragma Unreferenced (Sec_Stack_Address);
112-
pragma Unreferenced (Secondary_Stack_Size);
113135
pragma Unreferenced (Task_Info);
114136
pragma Unreferenced (CPU);
115137
pragma Unreferenced (Chain);
@@ -123,6 +145,7 @@ package body System.Tasking.Restricted.Stages is
123145
constant Parameters_Conversion.Object_Pointer :=
124146
Parameters_Conversion.To_Pointer (Wrapper_Parameter_Address);
125147

148+
use type System.Parameters.Size_Type;
126149
use type FreeRTOS.Tasks.Task_Handle;
127150
begin
128151
if Wrapper_Parameter_Address = System.Null_Address then
@@ -132,8 +155,11 @@ package body System.Tasking.Restricted.Stages is
132155
(ATCB => Created_Task,
133156
Task_Proc => State,
134157
Discriminants => Discriminants,
158+
SStack_Addr => Sec_Stack_Address,
135159
SStack_Size =>
136-
System.Parameters.Secondary_Stack_Size (Actual_Stack_Size));
160+
(if Secondary_Stack_Size = System.Parameters.Unspecified_Size
161+
then System.Parameters.Secondary_Stack_Size (Actual_Stack_Size)
162+
else Secondary_Stack_Size)); -- don't think this will happen?
137163

138164
Created_Task.Common.Base_Priority := (if Priority = Unspecified_Priority
139165
then System.Default_Priority

common/gnat-gpl-2017/s-tarest.adb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
-- --
77
-- B o d y --
88
-- --
9-
-- Copyright (C) 2016, 2017 Free Software Foundation, Inc. --
9+
-- Copyright (C) 2016-2018 Free Software Foundation, Inc. --
1010
-- --
1111
-- GNARL is free software; you can redistribute it and/or modify it under --
1212
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -35,10 +35,9 @@
3535
-- This package represents the high level tasking interface used by the
3636
-- compiler to expand Ada 95 tasking constructs into simpler run time calls.
3737

38-
-- This is is the version for the Cortex GNAT RTS project.
38+
-- This is the version for the Cortex GNAT RTS project.
3939

4040
with Ada.Unchecked_Conversion;
41-
with Interfaces;
4241
with System.Address_To_Access_Conversions;
4342
with System.FreeRTOS.TCB;
4443
with System.Memory;
@@ -108,7 +107,6 @@ package body System.Tasking.Restricted.Stages is
108107
Created_Task : Task_Id) is
109108

110109
pragma Unreferenced (Stack_Address);
111-
pragma Unreferenced (Secondary_Stack_Size);
112110
pragma Unreferenced (Task_Info);
113111
pragma Unreferenced (CPU);
114112
pragma Unreferenced (Chain);
@@ -122,6 +120,7 @@ package body System.Tasking.Restricted.Stages is
122120
constant Parameters_Conversion.Object_Pointer :=
123121
Parameters_Conversion.To_Pointer (Wrapper_Parameter_Address);
124122

123+
use type System.Parameters.Size_Type;
125124
use type FreeRTOS.Tasks.Task_Handle;
126125
begin
127126
if Wrapper_Parameter_Address = System.Null_Address then
@@ -132,7 +131,9 @@ package body System.Tasking.Restricted.Stages is
132131
Task_Proc => State,
133132
Discriminants => Discriminants,
134133
SStack_Size =>
135-
System.Parameters.Secondary_Stack_Size (Actual_Stack_Size));
134+
(if Secondary_Stack_Size = System.Parameters.Unspecified_Size
135+
then System.Parameters.Secondary_Stack_Size (Actual_Stack_Size)
136+
else Secondary_Stack_Size));
136137

137138
Created_Task.Common.Base_Priority := (if Priority = Unspecified_Priority
138139
then System.Default_Priority

0 commit comments

Comments
 (0)