/* emx-ctordtor.c (emx+gcc) -- Copyright (c) 1993-1994 by Eberhard Mattes */

/*
  Define __NO_CPLUSPLUS__ to avoid extra code used for frame unwind info
  (used for C++ exceptions without -fsjlj-exceptions)
*/

extern int __eh_frame__;
void __register_frame_table (void *begin);
void __deregister_frame (void *begin);
extern int __CTOR_LIST__;
extern int __DTOR_LIST__;
extern void __ctordtorInit1 (int *ptr);
extern void __ctordtorTerm1 (int *ptr);

void __ctordtorInit (void)
{
  static int done;

  if (!done)
    {
#ifndef __NO_CPLUSPLUS__
      int *ptr = &__eh_frame__;
#endif

      done = 1;
#ifndef __NO_CPLUSPLUS__
      __register_frame_table (&ptr[*ptr == -2 ? 1 : 2]);
#endif
      __ctordtorInit1 (&__CTOR_LIST__);
    }
}

void __ctordtorTerm (void)
{
  static int done;

  if (!done)
    {
#ifndef __NO_CPLUSPLUS__
      int *ptr = &__eh_frame__;
#endif

      done = 1;
      __ctordtorTerm1 (&__DTOR_LIST__);
#ifndef __NO_CPLUSPLUS__
      __deregister_frame (&ptr[*ptr == -2 ? 1 : 2]);
#endif
    }
}
