2 * CRTDLL exit/abort/atexit functions
4 * Copyright 1996,1998 Marcus Meissner
5 * Copyright 1996 Jukka Iivonen
6 * Copyright 1997,2000 Uwe Bonnes
7 * Copyright 2000 Jon Griffiths
9 * exit functions differ in whether they perform cleanup
10 * and whether they return to the caller (really!).
12 * Name to caller? cleanup?
18 * Implementation Notes:
19 * Not MT Safe - Adding/Executing exit() functions should be locked
23 * Need a better way of printing errors for GUI programs(MsgBox?).
24 * Is there really a difference between onexit/atexit?
31 DEFAULT_DEBUG_CHANNEL(crtdll);
33 /* INTERNAL: Table of registered atexit() functions */
34 /* FIXME: This should be dynamically allocated */
35 #define CRTDLL_ATEXIT_TABLE_SIZE 16
37 static atexit_function atexit_table[CRTDLL_ATEXIT_TABLE_SIZE];
38 static int atexit_registered = 0; /* Points to free slot */
41 /* INTERNAL: call atexit functions */
42 void __CRTDLL__call_atexit(VOID);
43 void __CRTDLL__call_atexit(VOID)
45 /* Last registered gets executed first */
46 while (atexit_registered > 0)
49 TRACE(":call function (%p)\n",atexit_table[atexit_registered]);
50 (*atexit_table[atexit_registered])();
55 /*********************************************************************
56 * __dllonexit (CRTDLL.25)
58 VOID __cdecl CRTDLL___dllonexit ()
64 /*********************************************************************
65 * _abnormal_termination (CRTDLL.36)
67 * Check if execution is processing during an exception.
69 INT __cdecl CRTDLL__abnormal_termination(VOID)
72 return 0; /* FIME: Can we determine if we are in an exception? */
76 /*********************************************************************
77 * _amsg_exit (CRTDLL.040)
79 * Print an error message and terminate execution. Returns 255 to the
82 VOID __cdecl CRTDLL__amsg_exit(INT err)
84 CRTDLL_fprintf(CRTDLL_stderr,"\nrun-time error:\nError Code %d\n",err);
89 /*********************************************************************
90 * _assert (CRTDLL.041)
92 * Print an assertion message and call abort(). Really only present
93 * for win binaries. Winelib programs would typically use libc's
96 VOID __cdecl CRTDLL__assert(LPVOID str, LPVOID file, UINT line)
98 CRTDLL_fprintf(CRTDLL_stderr,"Assertion failed: %s, file %s, line %d\n\n",
99 (char*)str,(char*)file, line);
104 /*********************************************************************
105 * _c_exit (CRTDLL.047)
107 VOID __cdecl CRTDLL__c_exit(VOID)
109 FIXME("not calling CRTDLL cleanup\n");
110 /* dont exit, return to caller */
114 /*********************************************************************
115 * _cexit (CRTDLL.049)
117 VOID __cdecl CRTDLL__cexit(VOID)
119 FIXME("not calling CRTDLL cleanup\n");
120 /* dont exit, return to caller */
124 /*********************************************************************
127 VOID __cdecl CRTDLL__exit(LONG ret)
129 TRACE(":exit code %ld\n",ret);
134 /*********************************************************************
135 * _onexit (CRTDLL.236)
137 * Register a function to be called when the process terminates.
139 atexit_function __cdecl CRTDLL__onexit( atexit_function func)
141 TRACE("registering function (%p)\n",func);
142 if (func && atexit_registered <= CRTDLL_ATEXIT_TABLE_SIZE - 1)
144 atexit_table[atexit_registered] = (atexit_function)func;
146 return func; /* successful */
148 ERR(":Too many onexit() functions, or NULL function - not registered!\n");
153 /*********************************************************************
156 void __cdecl CRTDLL_exit(DWORD ret)
158 TRACE(":exit code %ld\n",ret);
159 __CRTDLL__call_atexit();
165 /*********************************************************************
168 * Terminate the progam with an abnormal termination message. Returns
171 VOID __cdecl CRTDLL_abort()
173 CRTDLL_fprintf(CRTDLL_stderr,"\nabnormal program termination\n");
178 /*********************************************************************
179 * atexit (CRTDLL.345)
181 * Register a function to be called when the process terminates.
183 INT __cdecl CRTDLL_atexit( atexit_function func)
185 return CRTDLL__onexit(func) == func ? 0 : -1;