* <!-- description --> * @brief This function contains all of the code that is common between * all archiectures and all platforms that is needed for initializing * the loader. This function will call platform and architecture specific * functions as needed. * * <!-- inputs/outputs --> * @return LOADER_SUCCESS on success, LOADER_FAILURE on failure. */
| 49 | * @return LOADER_SUCCESS on success, LOADER_FAILURE on failure. |
| 50 | */ |
| 51 | NODISCARD int64_t |
| 52 | loader_init(void) NOEXCEPT |
| 53 | { |
| 54 | if (VMM_STATUS_CORRUPT == g_mut_vmm_status) { |
| 55 | bferror("Unable to init, previous VMM failed to properly stop"); |
| 56 | return LOADER_FAILURE; |
| 57 | } |
| 58 | |
| 59 | if (alloc_mk_debug_ring(&g_pmut_mut_mk_debug_ring)) { |
| 60 | bferror("alloc_mk_debug_ring failed"); |
| 61 | goto alloc_mk_debug_ring_failed; |
| 62 | } |
| 63 | |
| 64 | if (alloc_and_copy_mk_code_aliases(&g_mut_mk_code_aliases)) { |
| 65 | bferror("alloc_and_copy_mk_code_aliases failed"); |
| 66 | goto alloc_and_copy_mk_code_aliases_failed; |
| 67 | } |
| 68 | |
| 69 | #ifdef DEBUG_LOADER |
| 70 | dump_mk_debug_ring(g_pmut_mut_mk_debug_ring); |
| 71 | dump_mk_code_aliases(&g_mut_mk_code_aliases); |
| 72 | #endif |
| 73 | |
| 74 | return LOADER_SUCCESS; |
| 75 | |
| 76 | alloc_and_copy_mk_code_aliases_failed: |
| 77 | alloc_mk_debug_ring_failed: |
| 78 | |
| 79 | (void)loader_fini(); |
| 80 | return LOADER_FAILURE; |
| 81 | } |