Fix bootstrapping crash.

If a custom small_size2bin table was required due to non-default size
class settings, memory allocation prior to initializing chunk parameters
would cause a crash due to division by 0.  The fix re-orders the various
*_boot() function calls.

Bootstrapping is simpler now than it was before the base allocator
started just using the chunk allocator directly.  This allows
arena_boot[01]() to be combined.

Add error detection for pthread_atfork() and atexit() function calls.
diff --git a/jemalloc/src/internal/jemalloc_arena.h b/jemalloc/src/internal/jemalloc_arena.h
index 3c1947d..610735d 100644
--- a/jemalloc/src/internal/jemalloc_arena.h
+++ b/jemalloc/src/internal/jemalloc_arena.h
@@ -412,8 +412,7 @@
 #endif
 void	*arena_ralloc(void *ptr, size_t size, size_t oldsize);
 bool	arena_new(arena_t *arena, unsigned ind);
-bool	arena_boot0(void);
-void	arena_boot1(void);
+bool	arena_boot(void);
 
 #endif /* JEMALLOC_H_EXTERNS */
 /******************************************************************************/
diff --git a/jemalloc/src/jemalloc.c b/jemalloc/src/jemalloc.c
index 885209b..55c77ed 100644
--- a/jemalloc/src/jemalloc.c
+++ b/jemalloc/src/jemalloc.c
@@ -702,6 +702,15 @@
 		}
 	}
 
+	/* Register fork handlers. */
+	if (pthread_atfork(jemalloc_prefork, jemalloc_postfork,
+	    jemalloc_postfork) != 0) {
+		malloc_write4("<jemalloc>", ": Error in pthread_atfork()\n", "",
+		    "");
+		if (opt_abort)
+			abort();
+	}
+
 	if (ctl_boot()) {
 		malloc_mutex_unlock(&init_lock);
 		return (true);
@@ -717,18 +726,25 @@
 #endif
 	if (opt_stats_print) {
 		/* Print statistics at exit. */
-		atexit(stats_print_atexit);
+		if (atexit(stats_print_atexit) != 0) {
+			malloc_write4("<jemalloc>", ": Error in atexit()\n", "",
+			    "");
+			if (opt_abort)
+				abort();
+		}
 	}
 
-	/* Register fork handlers. */
-	pthread_atfork(jemalloc_prefork, jemalloc_postfork, jemalloc_postfork);
+	if (chunk_boot()) {
+		malloc_mutex_unlock(&init_lock);
+		return (true);
+	}
 
 	if (base_boot()) {
 		malloc_mutex_unlock(&init_lock);
 		return (true);
 	}
 
-	if (arena_boot0()) {
+	if (arena_boot()) {
 		malloc_mutex_unlock(&init_lock);
 		return (true);
 	}
@@ -737,12 +753,6 @@
 	tcache_boot();
 #endif
 
-	if (chunk_boot()) {
-		malloc_mutex_unlock(&init_lock);
-		return (true);
-	}
-	arena_boot1();
-
 	if (huge_boot()) {
 		malloc_mutex_unlock(&init_lock);
 		return (true);
diff --git a/jemalloc/src/jemalloc_arena.c b/jemalloc/src/jemalloc_arena.c
index e1e1b8f..e1970c8 100644
--- a/jemalloc/src/jemalloc_arena.c
+++ b/jemalloc/src/jemalloc_arena.c
@@ -2156,8 +2156,9 @@
 }
 
 bool
-arena_boot0(void)
+arena_boot(void)
 {
+	size_t header_size;
 
 	/* Set variables according to the value of opt_lg_[qc]space_max. */
 	qspace_max = (1U << opt_lg_qspace_max);
@@ -2214,14 +2215,6 @@
 	if (small_size2bin_init())
 		return (true);
 
-	return (false);
-}
-
-void
-arena_boot1(void)
-{
-	size_t header_size;
-
 	/*
 	 * Compute the header size such that it is large enough to contain the
 	 * page map.
@@ -2231,4 +2224,6 @@
 	arena_chunk_header_npages = (header_size >> PAGE_SHIFT) +
 	    ((header_size & PAGE_MASK) != 0);
 	arena_maxclass = chunksize - (arena_chunk_header_npages << PAGE_SHIFT);
+
+	return (false);
 }
diff --git a/jemalloc/src/jemalloc_trace.c b/jemalloc/src/jemalloc_trace.c
index 89d30a7..f1e2a61 100644
--- a/jemalloc/src/jemalloc_trace.c
+++ b/jemalloc/src/jemalloc_trace.c
@@ -262,7 +262,11 @@
 		return (true);
 
 	/* Flush trace buffers at exit. */
-	atexit(malloc_trace_flush_all);
+	if (atexit(malloc_trace_flush_all) != 0) {
+		malloc_write4("<jemalloc>", ": Error in atexit()\n", "", "");
+		if (opt_abort)
+			abort();
+	}
 	/* Receive thread exit notifications. */
 	if (pthread_key_create(&trace_tsd, trace_thread_cleanup) != 0) {
 		malloc_write4("<jemalloc>",