1169689Skan/* Startup routines for NetWare.
2169689Skan   Contributed by Jan Beulich (jbeulich@novell.com)
3169689Skan   Copyright (C) 2004 Free Software Foundation, Inc.
4169689Skan
5169689SkanThis file is part of GCC.
6169689Skan
7169689SkanGCC is free software; you can redistribute it and/or modify
8169689Skanit under the terms of the GNU General Public License as published by
9169689Skanthe Free Software Foundation; either version 2, or (at your option)
10169689Skanany later version.
11169689Skan
12169689SkanGCC is distributed in the hope that it will be useful,
13169689Skanbut WITHOUT ANY WARRANTY; without even the implied warranty of
14169689SkanMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15169689SkanGNU General Public License for more details.
16169689Skan
17169689SkanYou should have received a copy of the GNU General Public License
18169689Skanalong with GCC; see the file COPYING.  If not, write to
19169689Skanthe Free Software Foundation, 51 Franklin Street, Fifth Floor,
20169689SkanBoston, MA 02110-1301, USA.  */
21169689Skan
22169689Skan#include <stddef.h>
23169689Skan#include <stdint.h>
24169689Skan#include "unwind-dw2-fde.h"
25169689Skan
26169689Skanint __init_environment (void *);
27169689Skanint __deinit_environment (void *);
28169689Skan
29169689Skan
30169689Skan#define SECTION_DECL(name, decl) decl __attribute__((__section__(name)))
31169689Skan
32169689SkanSECTION_DECL(".ctors",   void(*const __CTOR_LIST__)(void))
33169689Skan  = (void(*)(void))(intptr_t)-1;
34169689SkanSECTION_DECL(".ctors$_", void(*const __CTOR_END__)(void)) = NULL;
35169689Skan
36169689SkanSECTION_DECL(".dtors",   void(*const __DTOR_LIST__)(void))
37169689Skan  = (void(*)(void))(intptr_t)-1;
38169689SkanSECTION_DECL(".dtors$_", void(*const __DTOR_END__)(void)) = NULL;
39169689Skan
40169689Skan/* No need to use the __[de]register_frame_info_bases functions since
41169689Skan   for us the bases are NULL always anyway. */
42169689Skanvoid __register_frame_info (const void *, struct object *)
43169689Skan  __attribute__((__weak__));
44169689Skanvoid *__deregister_frame_info (const void *) __attribute__((__weak__));
45169689Skan
46169689SkanSECTION_DECL(".eh_frame", /*const*/ uint32_t __EH_FRAME_BEGIN__[]) = { };
47169689SkanSECTION_DECL(".eh_frame$_", /*const*/ uint32_t __EH_FRAME_END__[]) = {0};
48169689Skan
49169689Skanint
50169689Skan__init_environment (void *unused __attribute__((__unused__)))
51169689Skan{
52169689Skan  void (* const * pctor)(void);
53169689Skan  static struct object object;
54169689Skan
55169689Skan  if (__register_frame_info)
56169689Skan    __register_frame_info (__EH_FRAME_BEGIN__, &object);
57169689Skan
58169689Skan  for (pctor = &__CTOR_END__ - 1; pctor > &__CTOR_LIST__; --pctor)
59169689Skan    if (*pctor != NULL)
60169689Skan      (*pctor)();
61169689Skan
62169689Skan  return 0;
63169689Skan}
64169689Skan
65169689Skanint
66169689Skan__deinit_environment (void *unused __attribute__((__unused__)))
67169689Skan{
68169689Skan  /* This should be static to prevent calling the same destructor
69169689Skan     twice (just in case where we get here multiple times).  */
70169689Skan  static void (* const * pdtor)(void) = &__DTOR_LIST__ + 1;
71169689Skan
72169689Skan  while (pdtor < &__DTOR_END__)
73169689Skan    if (*pdtor++ != NULL)
74169689Skan      pdtor[-1] ();
75169689Skan
76169689Skan  if (__deregister_frame_info)
77169689Skan    __deregister_frame_info(__EH_FRAME_BEGIN__);
78169689Skan
79169689Skan  return 0;
80169689Skan}
81