Changeset 439


Ignore:
Timestamp:
Jul 25, 2003, 3:37:21 PM (22 years ago)
Author:
bird
Message:

#577: Fixed problem with the use of atexit(ehTerm) for DLLs.

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/src/lib/startup/dllinit.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r438 r439  
    1 /* This is the startup code for gcc.dll (and can be used as well for any other
    2    DLL which uses exceptions). It should call __ehInit() as any other dynamic
    3    library which uses exceptions, otherwise the C++ programs linked to it will
    4    fail to catch exceptions.
    5 
    6  -= This is duplicated in libgcc and this copy must be removed when  =-
    7  -= we've done a new release!                                        =-
    8 
    9     */
    10 
     1/*  */
     2#include <emx/startup.h>
    113extern int _CRT_init (void);
    124extern void __ctordtorInit (void);
    135extern void __ctordtorTerm (void);
    14 extern void __ehInit (void);
    15 extern void __ehTerm (void);
     6extern void __ehInitDLL (void);
     7#pragma weak __ehInitDLL
     8extern void __ehTermDLL (void);
     9#pragma weak __ehTermDLL
    1610
    17 unsigned long _System _DLL_InitTerm (unsigned long mod_handle, unsigned long flag)
     11/**
     12 * This is the typical DLL startup code. __ehInitDLL and __ehTermDLL is called
     13 * are for exception handler stuff in gcc, the two functions will be linked if
     14 * there is exception handler info in the module. (Btw. if these calls wasn't
     15 * made we would fail to catch exceptions in C++ code.)
     16 * @returns 1 on success.
     17 * @returns 0 on failure.
     18 * @param   hmod    Handle of this DLL.
     19 * @param   flag    0 init.
     20 *                  1 term.
     21 * @remark  This function is called from dll0.asm.
     22 */
     23unsigned _System _DLL_InitTerm (unsigned hmod, unsigned flag)
    1824{
    1925  switch (flag)
     
    2127    case 0:
    2228      if (_CRT_init () != 0)
    23         return 0;
     29        break;
     30      if (__ehInitDLL)
     31        __ehInitDLL ();
    2432      __ctordtorInit ();
    25       __ehInit ();
    2633      return 1;
    2734    case 1:
    28       __ehTerm ();
    2935      __ctordtorTerm ();
     36      if (__ehTermDLL)
     37        __ehTermDLL ();
    3038      return 1;
    31     default:
    32       return 0;
    3339  }
     40  return 0;
    3441}
  • trunk/src/gcc/gcc/config/i386/emx-dllinit.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r438 r439  
    22   DLL which uses exceptions). It should call __ehInit() as any other dynamic
    33   library which uses exceptions, otherwise the C++ programs linked to it will
    4    fail to catch exceptions. */
     4   fail to catch exceptions.
     5
     6 -= This is duplicated in libgcc and this copy must be removed when  =-
     7 -= we've done a new release!                                        =-
     8
     9    */
    510
    611extern int _CRT_init (void);
    712extern void __ctordtorInit (void);
    813extern void __ctordtorTerm (void);
    9 extern void __ehInit (void);
    10 extern void __ehTerm (void);
     14extern void __ehInitDLL (void);
     15#pragma weak __ehInitDLL
     16extern void __ehTermDLL (void);
     17#pragma weak __ehTermDLL
    1118
    1219unsigned long _System _DLL_InitTerm (unsigned long mod_handle, unsigned long flag)
     
    1623    case 0:
    1724      if (_CRT_init () != 0)
    18         return 0;
     25        break;
     26      if (__ehInitDLL)
     27        __ehInitDLL ();
    1928      __ctordtorInit ();
    20       __ehInit ();
    2129      return 1;
    2230    case 1:
    23       __ehTerm ();
    2431      __ctordtorTerm ();
     32      if (__ehTermDLL)
     33        __ehTermDLL ();
    2534      return 1;
    26     default:
    27       return 0;
    2835  }
     36  return 0;
    2937}
  • trunk/src/gcc/gcc/config/i386/emx-eh.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r438 r439  
    66extern void __register_frame_table (void *begin);
    77extern void __deregister_frame (void *begin);
     8
     9/** Exception handler stuff init indicator. 0 means not inited, 1 means inited. */
     10static int inited;
    811extern void __ehInit (void);
    912extern void __ehTerm (void);
     13extern void __ehTermDLL (void);
    1014
    11 void __ehTerm (void)
     15/**
     16 * Inits exception handler stuff.
     17 * Intended external caller is _DLL_InitTerm.
     18 */
     19void __ehInitDLL (void)
    1220{
    13   static int done;
    14 
    15   if (!done)
     21  if (!inited)
    1622    {
    1723      int *ptr = &__eh_frame__;
    18       done = 1;
     24      inited = 1;
     25      __register_frame_table (&ptr [*ptr == -2 ? 1 : 2]);
     26    }
     27}
     28
     29/**
     30 * Terminates exception handler stuff.
     31 * Intended external caller is _DLL_InitTerm.
     32 */
     33void __ehTermDLL (void)
     34{
     35  if (inited)
     36    {
     37      int *ptr = &__eh_frame__;
     38      inited = 0;
    1939      __deregister_frame (&ptr [*ptr == -2 ? 1 : 2]);
    2040    }
    2141}
    2242
     43
     44/**
     45 * atexit() procedure used pto terminate exception stuff in programs.
     46 * Registered by __ehInit.
     47 */
     48static void __ehTerm (void)
     49{
     50  __ehTermDLL();
     51}
     52
     53/**
     54 * Init exception handler stuff for a program.
     55 * Intended external caller is GCC generated main() code.
     56 */
    2357void __ehInit (void)
    2458{
    25   static int done;
    26 
    27   if (!done)
     59  if (!inited)
    2860    {
    29       int *ptr = &__eh_frame__;
    30       done = 1;
    31       __register_frame_table (&ptr [*ptr == -2 ? 1 : 2]);
    3261      atexit (__ehTerm);
     62      __ehInitDLL();
    3363    }
    3464}
     65
Note: See TracChangeset for help on using the changeset viewer.