| 1497 | } |
| 1498 | |
| 1499 | static bool |
| 1500 | malloc_init_hard(void) { |
| 1501 | tsd_t *tsd; |
| 1502 | |
| 1503 | #if defined(_WIN32) && _WIN32_WINNT < 0x0600 |
| 1504 | _init_init_lock(); |
| 1505 | #endif |
| 1506 | malloc_mutex_lock(TSDN_NULL, &init_lock); |
| 1507 | |
| 1508 | #define UNLOCK_RETURN(tsdn, ret, reentrancy) \ |
| 1509 | malloc_init_hard_cleanup(tsdn, reentrancy); \ |
| 1510 | return ret; |
| 1511 | |
| 1512 | if (!malloc_init_hard_needed()) { |
| 1513 | UNLOCK_RETURN(TSDN_NULL, false, false) |
| 1514 | } |
| 1515 | |
| 1516 | if (malloc_init_state != malloc_init_a0_initialized && |
| 1517 | malloc_init_hard_a0_locked()) { |
| 1518 | UNLOCK_RETURN(TSDN_NULL, true, false) |
| 1519 | } |
| 1520 | |
| 1521 | malloc_mutex_unlock(TSDN_NULL, &init_lock); |
| 1522 | /* Recursive allocation relies on functional tsd. */ |
| 1523 | tsd = malloc_tsd_boot0(); |
| 1524 | if (tsd == NULL) { |
| 1525 | return true; |
| 1526 | } |
| 1527 | if (malloc_init_hard_recursible()) { |
| 1528 | return true; |
| 1529 | } |
| 1530 | |
| 1531 | malloc_mutex_lock(tsd_tsdn(tsd), &init_lock); |
| 1532 | /* Set reentrancy level to 1 during init. */ |
| 1533 | pre_reentrancy(tsd, NULL); |
| 1534 | /* Initialize narenas before prof_boot2 (for allocation). */ |
| 1535 | if (malloc_init_narenas() || background_thread_boot1(tsd_tsdn(tsd))) { |
| 1536 | UNLOCK_RETURN(tsd_tsdn(tsd), true, true) |
| 1537 | } |
| 1538 | if (config_prof && prof_boot2(tsd)) { |
| 1539 | UNLOCK_RETURN(tsd_tsdn(tsd), true, true) |
| 1540 | } |
| 1541 | |
| 1542 | malloc_init_percpu(); |
| 1543 | |
| 1544 | if (malloc_init_hard_finish()) { |
| 1545 | UNLOCK_RETURN(tsd_tsdn(tsd), true, true) |
| 1546 | } |
| 1547 | post_reentrancy(tsd); |
| 1548 | malloc_mutex_unlock(tsd_tsdn(tsd), &init_lock); |
| 1549 | |
| 1550 | witness_assert_lockless(witness_tsd_tsdn( |
| 1551 | tsd_witness_tsdp_get_unsafe(tsd))); |
| 1552 | malloc_tsd_boot1(); |
| 1553 | /* Update TSD after tsd_boot1. */ |
| 1554 | tsd = tsd_fetch(); |
| 1555 | if (opt_background_thread) { |
| 1556 | assert(have_background_thread); |
no test coverage detected