//! Internal management for processes

use abi::{error::Error, path::Path};
use alloc::sync::Arc;
use libk::{
    task::{binary::LoadOptions, process::Process, thread::Thread},
    vfs::IoContext,
};

/// Loads a binary and creates a process for it. See [libk_thread::binary::load].
#[inline]
pub fn load_binary<P: AsRef<Path>>(
    ioctx: &mut IoContext,
    options: &LoadOptions<P>,
) -> Result<(Arc<Process>, Arc<Thread>), Error> {
    libk::task::binary::load(ioctx, options).inspect_err(|e| {
        log::warn!("Failed to load binary: {e:?}");
    })
}
