/*
 * Copyright 2011 The Native Client Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can
 * be found in the LICENSE file.
 */

#include <stdlib.h>
#include <stdio.h>

#include "native_client/src/include/portability.h"
#include "native_client/src/shared/platform/nacl_exit.h"
#include "native_client/src/trusted/service_runtime/nacl_signal.h"


void NaClAbort(void) {
  NaClExit(-SIGABRT);
}

void NaClExit(int err_code) {
#ifdef COVERAGE
  /* Give coverage runs a chance to flush coverage data */
  exit(err_code);
#else
  /* If the process is scheduled for termination, wait for it.*/
  if (TerminateProcess(GetCurrentProcess(), err_code)) {
    printf("Terminate passed, but returned.\n");
    while(1);
  }
  printf("Terminate failed with %d.\n", GetLastError());

  /* Otherwise use the standard C process exit to bybass destructors. */
  ExitProcess(err_code);
#endif
}


/*
 * Copyright 2011 The Native Client Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can
 * be found in the LICENSE file.
 */

#include <stdlib.h>

#include "native_client/src/include/portability.h"
#include "native_client/src/shared/platform/nacl_exit.h"
#include "native_client/src/trusted/service_runtime/nacl_signal.h"


void NaClAbort(void) {
#ifdef COVERAGE
  /* Give coverage runs a chance to flush coverage data */
  exit((-SIGABRT) & 0xFF);
#else
  /* Return an 8 bit value for SIGABRT */
  TerminateProcess(GetCurrentProcess(),(-SIGABRT) & 0xFF);
#endif
}

void NaClExit(int err_code) {
#ifdef COVERAGE
  /* Give coverage runs a chance to flush coverage data */
  exit(err_code);
#else
  TerminateProcess(GetCurrentProcess(), err_code);
#endif
}


--- 
+++ 
@@ -5,6 +5,7 @@
  */
 
 #include <stdlib.h>
+#include <stdio.h>
 
 #include "native_client/src/include/portability.h"
 #include "native_client/src/shared/platform/nacl_exit.h"
@@ -12,13 +13,7 @@
 
 
 void NaClAbort(void) {
-#ifdef COVERAGE
-  /* Give coverage runs a chance to flush coverage data */
-  exit((-SIGABRT) & 0xFF);
-#else
-  /* Return an 8 bit value for SIGABRT */
-  TerminateProcess(GetCurrentProcess(),(-SIGABRT) & 0xFF);
-#endif
+  NaClExit(-SIGABRT);
 }
 
 void NaClExit(int err_code) {
@@ -26,7 +21,15 @@
   /* Give coverage runs a chance to flush coverage data */
   exit(err_code);
 #else
-  TerminateProcess(GetCurrentProcess(), err_code);
+  /* If the process is scheduled for termination, wait for it.*/
+  if (TerminateProcess(GetCurrentProcess(), err_code)) {
+    printf("Terminate passed, but returned.\n");
+    while(1);
+  }
+  printf("Terminate failed with %d.\n", GetLastError());
+
+  /* Otherwise use the standard C process exit to bybass destructors. */
+  ExitProcess(err_code);
 #endif
 }
 
Fix exit issue on Vista/Win7Atom

TerminateProcess returns causing "exit" to fall through.   This is causing the buildbots
to go red.  To fix this, We must add a check to verify termination was scheduled, then
loop.  As a seperate CL we should find a way to do this without allowing a return
on an untrusted stack.

BUG= nacl1618
TEST= buildbot
Review URL: http://codereview.chromium.org/6804029

git-svn-id: 721b910a23eff8a86f00c8fd261a7587cddf18f8@4774 fcba33aa-ac0c-11dd-b9e7-8d5594d729c2
