#include <stdlib.h>\r
#include <MainData.h>\r
\r
+/** Internal worker function used by exit().\r
+**/\r
+void exitCleanup(INTN ExitVal);\r
+\r
/* ################# Public Functions ################################### */\r
\r
/** The abort function causes abnormal program termination to occur, unless\r
void\r
exit(int status)\r
{\r
- void (*CleanUp)(void); // Pointer to Cleanup Function\r
- int i;\r
-\r
- if(gMD != NULL) {\r
- CleanUp = gMD->cleanup; // Preserve the pointer to the Cleanup Function\r
-\r
- // Call all registered atexit functions in reverse order\r
- i = gMD->num_atexit;\r
- if( i > 0) {\r
- do {\r
- (gMD->atexit_handler[--i])();\r
- } while( i > 0);\r
- }\r
-\r
- if (CleanUp != NULL) {\r
- CleanUp();\r
- }\r
- }\r
+ exitCleanup((INTN) status);\r
_Exit(status);\r
}\r
\r
void\r
_Exit(int status)\r
{\r
- RETURN_STATUS ExitVal = (RETURN_STATUS)status;\r
-\r
- if( ExitVal == EXIT_FAILURE) {\r
- ExitVal = RETURN_ABORTED;\r
- }\r
-\r
- if(gMD->FinalCleanup != NULL) {\r
- gMD->FinalCleanup(); // gMD does not exist when this returns.\r
- }\r
+ gMD->ExitValue = status; // Save our exit status. Allows a status of 0.\r
+ longjmp(gMD->MainExit, 0x55); // Get out of here. longjmp can't return 0. Use 0x55 for a non-zero value.\r
\r
- gBS->Exit(gImageHandle, ExitVal, 0, NULL); /* abort() */\r
+#ifdef __GNUC__\r
+ __builtin__Exit(status); /* Keep GCC happy - never reached */\r
+#endif\r
}\r
\r
/** If string is a null pointer, the system function determines whether the\r