| 1443 | } |
| 1444 | |
| 1445 | static bool |
| 1446 | malloc_init_hard(void) { |
| 1447 | tsd_t *tsd; |
| 1448 | |
| 1449 | #if defined(_WIN32) && _WIN32_WINNT < 0x0600 |
| 1450 | _init_init_lock(); |
| 1451 | #endif |
| 1452 | malloc_mutex_lock(TSDN_NULL, &init_lock); |
| 1453 | |
| 1454 | #define UNLOCK_RETURN(tsdn, ret, reentrancy) \ |
| 1455 | malloc_init_hard_cleanup(tsdn, reentrancy); \ |
| 1456 | return ret; |
| 1457 | |
| 1458 | if (!malloc_init_hard_needed()) { |
| 1459 | UNLOCK_RETURN(TSDN_NULL, false, false) |
| 1460 | } |
| 1461 | |
| 1462 | if (malloc_init_state != malloc_init_a0_initialized && |
| 1463 | malloc_init_hard_a0_locked()) { |
| 1464 | UNLOCK_RETURN(TSDN_NULL, true, false) |
| 1465 | } |
| 1466 | |
| 1467 | malloc_mutex_unlock(TSDN_NULL, &init_lock); |
| 1468 | /* Recursive allocation relies on functional tsd. */ |
| 1469 | tsd = malloc_tsd_boot0(); |
| 1470 | if (tsd == NULL) { |
| 1471 | return true; |
| 1472 | } |
| 1473 | if (malloc_init_hard_recursible()) { |
| 1474 | return true; |
| 1475 | } |
| 1476 | |
| 1477 | malloc_mutex_lock(tsd_tsdn(tsd), &init_lock); |
| 1478 | /* Set reentrancy level to 1 during init. */ |
| 1479 | pre_reentrancy(tsd); |
| 1480 | /* Initialize narenas before prof_boot2 (for allocation). */ |
| 1481 | if (malloc_init_narenas() || background_thread_boot1(tsd_tsdn(tsd))) { |
| 1482 | UNLOCK_RETURN(tsd_tsdn(tsd), true, true) |
| 1483 | } |
| 1484 | if (config_prof && prof_boot2(tsd)) { |
| 1485 | UNLOCK_RETURN(tsd_tsdn(tsd), true, true) |
| 1486 | } |
| 1487 | |
| 1488 | malloc_init_percpu(); |
| 1489 | |
| 1490 | if (malloc_init_hard_finish()) { |
| 1491 | UNLOCK_RETURN(tsd_tsdn(tsd), true, true) |
| 1492 | } |
| 1493 | post_reentrancy(tsd); |
| 1494 | malloc_mutex_unlock(tsd_tsdn(tsd), &init_lock); |
| 1495 | |
| 1496 | malloc_tsd_boot1(); |
| 1497 | /* Update TSD after tsd_boot1. */ |
| 1498 | tsd = tsd_fetch(); |
| 1499 | if (opt_background_thread) { |
| 1500 | assert(have_background_thread); |
| 1501 | /* |
| 1502 | * Need to finish init & unlock first before creating background |
no test coverage detected