X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;ds=inline;f=StdLib%2FLibC%2FStdLib%2FEnvirons.c;h=40807279c930c422a50b6fd7cc8e39dd457fa4f8;hb=d7ce700605e1af0e455e31ec11f19ff21d26b525;hp=8472d0ef4c95a36c01f78be1df107f45a9420959;hpb=f766dd76fde231ecd4f2e9faf99293e90902cebb;p=mirror_edk2.git diff --git a/StdLib/LibC/StdLib/Environs.c b/StdLib/LibC/StdLib/Environs.c index 8472d0ef4c..40807279c9 100644 --- a/StdLib/LibC/StdLib/Environs.c +++ b/StdLib/LibC/StdLib/Environs.c @@ -29,6 +29,10 @@ #include #include +/** Internal worker function used by exit(). +**/ +void exitCleanup(INTN ExitVal); + /* ################# Public Functions ################################### */ /** The abort function causes abnormal program termination to occur, unless @@ -92,24 +96,7 @@ atexit(void (*handler)(void)) void exit(int status) { - void (*CleanUp)(void); // Pointer to Cleanup Function - int i; - - if(gMD != NULL) { - CleanUp = gMD->cleanup; // Preserve the pointer to the Cleanup Function - - // Call all registered atexit functions in reverse order - i = gMD->num_atexit; - if( i > 0) { - do { - (gMD->atexit_handler[--i])(); - } while( i > 0); - } - - if (CleanUp != NULL) { - CleanUp(); - } - } + exitCleanup((INTN) status); _Exit(status); } @@ -129,17 +116,12 @@ exit(int status) void _Exit(int status) { - RETURN_STATUS ExitVal = (RETURN_STATUS)status; - - if( ExitVal == EXIT_FAILURE) { - ExitVal = RETURN_ABORTED; - } - - if(gMD->FinalCleanup != NULL) { - gMD->FinalCleanup(); // gMD does not exist when this returns. - } + gMD->ExitValue = status; // Save our exit status. Allows a status of 0. + longjmp(gMD->MainExit, 0x55); // Get out of here. longjmp can't return 0. Use 0x55 for a non-zero value. - gBS->Exit(gImageHandle, ExitVal, 0, NULL); /* abort() */ +#ifdef __GNUC__ + __builtin__Exit(status); /* Keep GCC happy - never reached */ +#endif } /** If string is a null pointer, the system function determines whether the