ded9a5118bb6375ea4a7a672ec4728d2a33eac09
[gcc.git] / gcc / ada / 5zthrini.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S Y S T E M . T H R E A D S . I N I T I A L I Z A T I O N --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2003 Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
21 -- --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
28 -- --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
31 -- --
32 ------------------------------------------------------------------------------
33
34 -- This is the VxWorks version of this package; to use this implementation,
35 -- the task hook libraries should be included in the VxWorks kernel.
36
37 with System.Secondary_Stack;
38 with Interfaces.C;
39 with Unchecked_Conversion;
40
41 package body System.Threads.Initialization is
42
43 use Interfaces.C;
44
45 package SSS renames System.Secondary_Stack;
46
47 procedure Initialize_Task_Hooks;
48 -- Register the appropriate hooks (Register and Reset_TSD) to the
49 -- underlying OS, so that they will be called when a task is created
50 -- or reset.
51
52 Current_ATSD : aliased System.Address;
53 pragma Import (C, Current_ATSD, "__gnat_current_atsd");
54
55 ---------------------------
56 -- Initialize_Task_Hooks --
57 ---------------------------
58
59 procedure Initialize_Task_Hooks is separate;
60 -- Separate, as these hooks are different for AE653 and VxWorks 5.5.
61
62 --------------
63 -- Register --
64 --------------
65
66 function Register (T : OSI.Thread_Id) return OSI.STATUS is
67 TSD : ATSD_Access := new ATSD;
68 Result : OSI.STATUS;
69 begin
70 -- It cannot be assumed that the caller of this routine has a ATSD;
71 -- so neither this procedure nor the procedures that it calls should
72 -- raise or handle exceptions, or make use of a secondary stack.
73
74 if OSI.taskIdVerify (T) = OSI.ERROR
75 or else OSI.taskVarGet (T, Current_ATSD'Access) /= OSI.ERROR
76 then
77 return OSI.ERROR;
78 end if;
79
80 Result := OSI.taskVarAdd (T, Current_ATSD'Access);
81 pragma Assert (Result /= -1);
82 Result := OSI.taskVarSet (T, Current_ATSD'Access, TSD.all'Address);
83 pragma Assert (Result /= -1);
84 TSD.Sec_Stack_Addr := SSS.SS_Create;
85 SSS.SS_Init (TSD.Sec_Stack_Addr);
86 return Result;
87 end Register;
88
89 ---------------
90 -- Reset_TSD --
91 ---------------
92
93 function Reset_TSD (T : OSI.Thread_Id) return OSI.STATUS is
94 TSD_Ptr : int;
95 function To_Address is new Unchecked_Conversion
96 (Interfaces.C.int, ATSD_Access);
97 begin
98 TSD_Ptr := OSI.taskVarGet (T, Current_ATSD'Access);
99 pragma Assert (TSD_Ptr /= OSI.ERROR);
100
101 -- Just reset the secondary stack pointer. The implementation here
102 -- assumes that the fixed secondary stack implementation is used.
103 -- If not, there will be a memory leak (along with allocation, which
104 -- is prohibited for ARINC processes once the system enters "normal"
105 -- mode).
106
107 SSS.SS_Init (To_Address (TSD_Ptr).Sec_Stack_Addr);
108 return OSI.OK;
109 end Reset_TSD;
110
111 begin
112 Initialize_Task_Hooks;
113 end System.Threads.Initialization;