1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
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 --
9 -- Copyright (C) 1992-2003 Free Software Foundation, Inc. --
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. --
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. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
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.
37 with System.Secondary_Stack;
39 with Unchecked_Conversion;
41 package body System.Threads.Initialization is
45 package SSS renames System.Secondary_Stack;
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
52 Current_ATSD : aliased System.Address;
53 pragma Import (C, Current_ATSD, "__gnat_current_atsd");
55 ---------------------------
56 -- Initialize_Task_Hooks --
57 ---------------------------
59 procedure Initialize_Task_Hooks is separate;
60 -- Separate, as these hooks are different for AE653 and VxWorks 5.5.
66 function Register (T : OSI.Thread_Id) return OSI.STATUS is
67 TSD : ATSD_Access := new ATSD;
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.
74 if OSI.taskIdVerify (T) = OSI.ERROR
75 or else OSI.taskVarGet (T, Current_ATSD'Access) /= OSI.ERROR
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);
93 function Reset_TSD (T : OSI.Thread_Id) return OSI.STATUS is
95 function To_Address is new Unchecked_Conversion
96 (Interfaces.C.int, ATSD_Access);
98 TSD_Ptr := OSI.taskVarGet (T, Current_ATSD'Access);
99 pragma Assert (TSD_Ptr /= OSI.ERROR);
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"
107 SSS.SS_Init (To_Address (TSD_Ptr).Sec_Stack_Addr);
112 Initialize_Task_Hooks;
113 end System.Threads.Initialization;