(runtime_dir: &Path)
| 118 | |
| 119 | impl LibKrun { |
| 120 | fn load(runtime_dir: &Path) -> Result<Self, String> { |
| 121 | let libkrun_path = runtime_dir.join(required_runtime_lib_name()); |
| 122 | preload_runtime_support_libraries(runtime_dir)?; |
| 123 | |
| 124 | let library = Box::leak(Box::new(unsafe { |
| 125 | Library::new(&libkrun_path) |
| 126 | .map_err(|e| format!("load libkrun from {}: {e}", libkrun_path.display()))? |
| 127 | })); |
| 128 | |
| 129 | Ok(Self { |
| 130 | krun_init_log: load_symbol(library, b"krun_init_log\0", &libkrun_path)?, |
| 131 | krun_create_ctx: load_symbol(library, b"krun_create_ctx\0", &libkrun_path)?, |
| 132 | krun_free_ctx: load_symbol(library, b"krun_free_ctx\0", &libkrun_path)?, |
| 133 | krun_set_vm_config: load_symbol(library, b"krun_set_vm_config\0", &libkrun_path)?, |
| 134 | krun_add_disk: load_symbol(library, b"krun_add_disk\0", &libkrun_path)?, |
| 135 | krun_set_root_disk_remount: load_symbol( |
| 136 | library, |
| 137 | b"krun_set_root_disk_remount\0", |
| 138 | &libkrun_path, |
| 139 | )?, |
| 140 | krun_set_workdir: load_symbol(library, b"krun_set_workdir\0", &libkrun_path)?, |
| 141 | krun_set_exec: load_symbol(library, b"krun_set_exec\0", &libkrun_path)?, |
| 142 | krun_set_console_output: load_symbol( |
| 143 | library, |
| 144 | b"krun_set_console_output\0", |
| 145 | &libkrun_path, |
| 146 | )?, |
| 147 | krun_start_enter: load_symbol(library, b"krun_start_enter\0", &libkrun_path)?, |
| 148 | krun_disable_implicit_vsock: load_symbol( |
| 149 | library, |
| 150 | b"krun_disable_implicit_vsock\0", |
| 151 | &libkrun_path, |
| 152 | )?, |
| 153 | krun_add_vsock: load_symbol(library, b"krun_add_vsock\0", &libkrun_path)?, |
| 154 | #[cfg(target_os = "macos")] |
| 155 | krun_add_net_unixgram: load_symbol(library, b"krun_add_net_unixgram\0", &libkrun_path)?, |
| 156 | krun_add_net_unixstream: load_symbol( |
| 157 | library, |
| 158 | b"krun_add_net_unixstream\0", |
| 159 | &libkrun_path, |
| 160 | )?, |
| 161 | }) |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | fn preload_runtime_support_libraries(runtime_dir: &Path) -> Result<Vec<PathBuf>, String> { |
no test coverage detected