Take a quick_exit() patch from upstream FreeBSD.

  r325389 | kib | 2017-11-04 03:52:58 -0700 (Sat, 04 Nov 2017) | 7 lines

  C++17 requires quick_exit(3) to be async-signal safe.

  Make it safe, and update man page with the useful information.

  Sponsored by: The FreeBSD Foundation
  MFC after:  1 week

Test: treehugger
Change-Id: Idf84b1f1e360c031b0e39d5f6e80d17308db1940
diff --git a/libc/upstream-freebsd/android/include/freebsd-compat.h b/libc/upstream-freebsd/android/include/freebsd-compat.h
index 6f7a3f0..3228701 100644
--- a/libc/upstream-freebsd/android/include/freebsd-compat.h
+++ b/libc/upstream-freebsd/android/include/freebsd-compat.h
@@ -47,4 +47,6 @@
 /* FreeBSD has this, but we can't really implement it correctly on Linux. */
 #define issetugid() 0
 
+#define __compiler_membar() __asm __volatile(" " : : : "memory")
+
 #endif
diff --git a/libc/upstream-freebsd/android/include/machine/atomic.h b/libc/upstream-freebsd/android/include/machine/atomic.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/libc/upstream-freebsd/android/include/machine/atomic.h
diff --git a/libc/upstream-freebsd/lib/libc/stdlib/quick_exit.c b/libc/upstream-freebsd/lib/libc/stdlib/quick_exit.c
index ef8cdb1..9e4e79d 100644
--- a/libc/upstream-freebsd/lib/libc/stdlib/quick_exit.c
+++ b/libc/upstream-freebsd/lib/libc/stdlib/quick_exit.c
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
  * Copyright (c) 2011 David Chisnall
  * All rights reserved.
  *
@@ -23,9 +25,11 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/lib/libc/stdlib/quick_exit.c 326193 2017-11-25 17:12:48Z pfg $
  */
 
+#include <sys/types.h>
+#include <machine/atomic.h>
 #include <stdlib.h>
 #include <pthread.h>
 
@@ -60,6 +64,7 @@
 	h->cleanup = func;
 	pthread_mutex_lock(&atexit_mutex);
 	h->next = handlers;
+	__compiler_membar();
 	handlers = h;
 	pthread_mutex_unlock(&atexit_mutex);
 	return (0);
@@ -74,7 +79,9 @@
 	 * XXX: The C++ spec requires us to call std::terminate if there is an
 	 * exception here.
 	 */
-	for (h = handlers; NULL != h; h = h->next)
+	for (h = handlers; NULL != h; h = h->next) {
+		__compiler_membar();
 		h->cleanup();
+	}
 	_Exit(status);
 }