Initialize the process; called by thread_init or the process loader
| 578 | |
| 579 | // Initialize the process; called by thread_init or the process loader |
| 580 | void mi_process_init(void) mi_attr_noexcept { |
| 581 | // ensure we are called once |
| 582 | if (_mi_process_is_initialized) return; |
| 583 | _mi_verbose_message("process init: 0x%zx\n", _mi_thread_id()); |
| 584 | _mi_process_is_initialized = true; |
| 585 | mi_process_setup_auto_thread_done(); |
| 586 | |
| 587 | mi_detect_cpu_features(); |
| 588 | _mi_os_init(); |
| 589 | mi_heap_main_init(); |
| 590 | #if (MI_DEBUG) |
| 591 | _mi_verbose_message("debug level : %d\n", MI_DEBUG); |
| 592 | #endif |
| 593 | _mi_verbose_message("secure level: %d\n", MI_SECURE); |
| 594 | _mi_verbose_message("mem tracking: %s\n", MI_TRACK_TOOL); |
| 595 | mi_thread_init(); |
| 596 | |
| 597 | #if defined(_WIN32) && !defined(MI_SHARED_LIB) |
| 598 | // When building as a static lib the FLS cleanup happens to early for the main thread. |
| 599 | // To avoid this, set the FLS value for the main thread to NULL so the fls cleanup |
| 600 | // will not call _mi_thread_done on the (still executing) main thread. See issue #508. |
| 601 | FlsSetValue(mi_fls_key, NULL); |
| 602 | #endif |
| 603 | |
| 604 | mi_stats_reset(); // only call stat reset *after* thread init (or the heap tld == NULL) |
| 605 | |
| 606 | if (mi_option_is_enabled(mi_option_reserve_huge_os_pages)) { |
| 607 | size_t pages = mi_option_get_clamp(mi_option_reserve_huge_os_pages, 0, 128*1024); |
| 608 | long reserve_at = mi_option_get(mi_option_reserve_huge_os_pages_at); |
| 609 | if (reserve_at != -1) { |
| 610 | mi_reserve_huge_os_pages_at(pages, reserve_at, pages*500); |
| 611 | } else { |
| 612 | mi_reserve_huge_os_pages_interleave(pages, 0, pages*500); |
| 613 | } |
| 614 | } |
| 615 | if (mi_option_is_enabled(mi_option_reserve_os_memory)) { |
| 616 | long ksize = mi_option_get(mi_option_reserve_os_memory); |
| 617 | if (ksize > 0) { |
| 618 | mi_reserve_os_memory((size_t)ksize*MI_KiB, true /* commit? */, true /* allow large pages? */); |
| 619 | } |
| 620 | } |
| 621 | } |
| 622 | |
| 623 | // Called when the process is done (through `at_exit`) |
| 624 | static void mi_cdecl mi_process_done(void) { |
no test coverage detected