6
6
-- --
7
7
-- B o d y --
8
8
-- --
9
- -- Copyright (C) 2016-2017 Free Software Foundation, Inc. --
9
+ -- Copyright (C) 2016-2018 Free Software Foundation, Inc. --
10
10
-- --
11
11
-- GNARL is free software; you can redistribute it and/or modify it under --
12
12
-- terms of the GNU General Public License as published by the Free Soft- --
35
35
-- This package represents the high level tasking interface used by the
36
36
-- compiler to expand Ada 95 tasking constructs into simpler run time calls.
37
37
38
- -- This is is the version for the Cortex GNAT RTS project.
38
+ -- This is the version for the Cortex GNAT RTS project.
39
39
40
40
with Ada.Unchecked_Conversion ;
41
41
with System.Address_To_Access_Conversions ;
@@ -55,6 +55,7 @@ package body System.Tasking.Restricted.Stages is
55
55
ATCB : Task_Id;
56
56
Task_Proc : Task_Procedure_Access;
57
57
Discriminants : System.Address;
58
+ SStack_Addr : System.Secondary_Stack.SS_Stack_Ptr;
58
59
SStack_Size : System.Parameters.Size_Type;
59
60
end record ;
60
61
@@ -63,25 +64,48 @@ package body System.Tasking.Restricted.Stages is
63
64
64
65
procedure Wrapper (Arg1 : System.Address) is
65
66
function Convert_Task_Id
66
- is new Ada.Unchecked_Conversion (Task_Id, System.Address);
67
+ is new Ada.Unchecked_Conversion (Task_Id, System.Address);
67
68
68
69
P : constant Parameters_Conversion.Object_Pointer :=
69
70
Parameters_Conversion.To_Pointer (Arg1);
70
71
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;
74
73
begin
75
74
-- Save the ATCB in the FreeRTOS TCB
76
75
FreeRTOS.TCB.Set_Application_Parameter (Convert_Task_Id (P.ATCB));
77
76
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 ;
85
109
86
110
-- If we return here, the task procedure has exited (and not
87
111
-- because of an exception, which would already have reached
@@ -108,8 +132,6 @@ package body System.Tasking.Restricted.Stages is
108
132
Created_Task : Task_Id) is
109
133
110
134
pragma Unreferenced (Stack_Address);
111
- pragma Unreferenced (Sec_Stack_Address);
112
- pragma Unreferenced (Secondary_Stack_Size);
113
135
pragma Unreferenced (Task_Info);
114
136
pragma Unreferenced (CPU);
115
137
pragma Unreferenced (Chain);
@@ -123,6 +145,7 @@ package body System.Tasking.Restricted.Stages is
123
145
constant Parameters_Conversion.Object_Pointer :=
124
146
Parameters_Conversion.To_Pointer (Wrapper_Parameter_Address);
125
147
148
+ use type System.Parameters.Size_Type;
126
149
use type FreeRTOS.Tasks.Task_Handle;
127
150
begin
128
151
if Wrapper_Parameter_Address = System.Null_Address then
@@ -132,8 +155,11 @@ package body System.Tasking.Restricted.Stages is
132
155
(ATCB => Created_Task,
133
156
Task_Proc => State,
134
157
Discriminants => Discriminants,
158
+ SStack_Addr => Sec_Stack_Address,
135
159
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?
137
163
138
164
Created_Task.Common.Base_Priority := (if Priority = Unspecified_Priority
139
165
then System.Default_Priority
0 commit comments