]> git.proxmox.com Git - mirror_edk2.git/blobdiff - StdLib/LibC/StdLib/Environs.c
Add Socket Libraries.
[mirror_edk2.git] / StdLib / LibC / StdLib / Environs.c
index 8472d0ef4c95a36c01f78be1df107f45a9420959..40807279c930c422a50b6fd7cc8e39dd457fa4f8 100644 (file)
 #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
@@ -92,24 +96,7 @@ atexit(void (*handler)(void))
 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
@@ -129,17 +116,12 @@ exit(int status)
 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