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?
30 DEFAULT_DEBUG_CHANNEL(crtdll);
32 /* INTERNAL: Table of registered atexit() functions */
33 /* FIXME: This should be dynamically allocated */
34 #define CRTDLL_ATEXIT_TABLE_SIZE 16
36 static atexit_function atexit_table[CRTDLL_ATEXIT_TABLE_SIZE];
37 static int atexit_registered = 0; /* Points to free slot */
40 /* INTERNAL: call atexit functions */
41 void __CRTDLL__call_atexit(VOID);
42 void __CRTDLL__call_atexit(VOID)
44 /* Last registered gets executed first */
45 while (atexit_registered > 0)
48 TRACE(":call function (%p)\n",atexit_table[atexit_registered]);
49 (*atexit_table[atexit_registered])();
54 /*********************************************************************
55 * __dllonexit (CRTDLL.25)
57 VOID __cdecl CRTDLL___dllonexit ()
63 /*********************************************************************
64 * _abnormal_termination (CRTDLL.36)
66 * Check if execution is processing during an exception.
68 INT __cdecl CRTDLL__abnormal_termination(VOID)
71 return 0; /* FIME: Can we determine if we are in an exception? */
75 /*********************************************************************
76 * _amsg_exit (CRTDLL.040)
78 * Print an error message and terminate execution. Returns 255 to the
81 VOID __cdecl CRTDLL__amsg_exit(INT err)
83 CRTDLL_fprintf(CRTDLL_stderr,"\nrun-time error:\nError Code %d\n",err);
88 /*********************************************************************
89 * _assert (CRTDLL.041)
91 * Print an assertion message and call abort(). Really only present
92 * for win binaries. Winelib programs would typically use libc's
95 VOID __cdecl CRTDLL__assert(LPVOID str, LPVOID file, UINT line)
97 CRTDLL_fprintf(CRTDLL_stderr,"Assertion failed: %s, file %s, line %d\n\n",
98 (char*)str,(char*)file, line);
103 /*********************************************************************
104 * _c_exit (CRTDLL.047)
106 VOID __cdecl CRTDLL__c_exit(VOID)
108 /* All cleanup is done on DLL detach; Return to caller */
112 /*********************************************************************
113 * _cexit (CRTDLL.049)
115 VOID __cdecl CRTDLL__cexit(VOID)
117 /* All cleanup is done on DLL detach; Return to caller */
121 /*********************************************************************
124 VOID __cdecl CRTDLL__exit(LONG ret)
126 TRACE(":exit code %ld\n",ret);
131 /*********************************************************************
132 * _onexit (CRTDLL.236)
134 * Register a function to be called when the process terminates.
136 atexit_function __cdecl CRTDLL__onexit( atexit_function func)
138 TRACE("registering function (%p)\n",func);
139 if (func && atexit_registered <= CRTDLL_ATEXIT_TABLE_SIZE - 1)
141 atexit_table[atexit_registered] = (atexit_function)func;
143 return func; /* successful */
145 ERR(":Too many onexit() functions, or NULL function - not registered!\n");
150 /*********************************************************************
153 void __cdecl CRTDLL_exit(DWORD ret)
155 TRACE(":exit code %ld\n",ret);
156 __CRTDLL__call_atexit();
162 /*********************************************************************
165 * Terminate the progam with an abnormal termination message. Returns
168 VOID __cdecl CRTDLL_abort()
170 CRTDLL_fprintf(CRTDLL_stderr,"\nabnormal program termination\n");
175 /*********************************************************************
176 * atexit (CRTDLL.345)
178 * Register a function to be called when the process terminates.
180 INT __cdecl CRTDLL_atexit( atexit_function func)
182 return CRTDLL__onexit(func) == func ? 0 : -1;