| 1730 | } |
| 1731 | |
| 1732 | static bool |
| 1733 | malloc_init_hard(void) { |
| 1734 | tsd_t *tsd; |
| 1735 | |
| 1736 | #if defined(_WIN32) && _WIN32_WINNT < 0x0600 |
| 1737 | _init_init_lock(); |
| 1738 | #endif |
| 1739 | malloc_mutex_lock(TSDN_NULL, &init_lock); |
| 1740 | |
| 1741 | #define UNLOCK_RETURN(tsdn, ret, reentrancy) \ |
| 1742 | malloc_init_hard_cleanup(tsdn, reentrancy); \ |
| 1743 | return ret; |
| 1744 | |
| 1745 | if (!malloc_init_hard_needed()) { |
| 1746 | UNLOCK_RETURN(TSDN_NULL, false, false) |
| 1747 | } |
| 1748 | |
| 1749 | if (malloc_init_state != malloc_init_a0_initialized && |
| 1750 | malloc_init_hard_a0_locked()) { |
| 1751 | UNLOCK_RETURN(TSDN_NULL, true, false) |
| 1752 | } |
| 1753 | |
| 1754 | malloc_mutex_unlock(TSDN_NULL, &init_lock); |
| 1755 | /* Recursive allocation relies on functional tsd. */ |
| 1756 | tsd = malloc_tsd_boot0(); |
| 1757 | if (tsd == NULL) { |
| 1758 | return true; |
| 1759 | } |
| 1760 | if (malloc_init_hard_recursible()) { |
| 1761 | return true; |
| 1762 | } |
| 1763 | |
| 1764 | malloc_mutex_lock(tsd_tsdn(tsd), &init_lock); |
| 1765 | /* Set reentrancy level to 1 during init. */ |
| 1766 | pre_reentrancy(tsd, NULL); |
| 1767 | /* Initialize narenas before prof_boot2 (for allocation). */ |
| 1768 | if (malloc_init_narenas() || background_thread_boot1(tsd_tsdn(tsd))) { |
| 1769 | UNLOCK_RETURN(tsd_tsdn(tsd), true, true) |
| 1770 | } |
| 1771 | if (config_prof && prof_boot2(tsd)) { |
| 1772 | UNLOCK_RETURN(tsd_tsdn(tsd), true, true) |
| 1773 | } |
| 1774 | |
| 1775 | malloc_init_percpu(); |
| 1776 | |
| 1777 | if (malloc_init_hard_finish()) { |
| 1778 | UNLOCK_RETURN(tsd_tsdn(tsd), true, true) |
| 1779 | } |
| 1780 | post_reentrancy(tsd); |
| 1781 | malloc_mutex_unlock(tsd_tsdn(tsd), &init_lock); |
| 1782 | |
| 1783 | witness_assert_lockless(witness_tsd_tsdn( |
| 1784 | tsd_witness_tsdp_get_unsafe(tsd))); |
| 1785 | malloc_tsd_boot1(); |
| 1786 | /* Update TSD after tsd_boot1. */ |
| 1787 | tsd = tsd_fetch(); |
| 1788 | if (opt_background_thread) { |
| 1789 | assert(have_background_thread); |
no test coverage detected