use super::AuxvType;
extern "C" {
#[cfg(target_os="linux")]
fn getauxval_wrapper(key: AuxvType, success: *mut AuxvType) -> i32;
}
#[derive(Debug, PartialEq)]
pub enum GetauxvalError {
FunctionNotAvailable,
NotFound,
UnknownError
}
pub trait Getauxval {
fn getauxval(&self, key: AuxvType) -> Result<AuxvType, GetauxvalError>;
}
pub struct NotAvailableGetauxval {}
impl Getauxval for NotAvailableGetauxval {
fn getauxval(&self, _: AuxvType) -> Result<AuxvType, GetauxvalError> {
Err(GetauxvalError::FunctionNotAvailable)
}
}
#[cfg(target_os="linux")]
pub struct NativeGetauxval {}
#[cfg(target_os="linux")]
impl Getauxval for NativeGetauxval {
fn getauxval(&self, key: AuxvType)
-> Result<AuxvType, GetauxvalError> {
let mut result = 0;
unsafe {
return match getauxval_wrapper(key, &mut result) {
1 => Ok(result),
0 => Err(GetauxvalError::NotFound),
-1 => Err(GetauxvalError::FunctionNotAvailable),
-2 => Err(GetauxvalError::UnknownError),
x => panic!("getauxval_wrapper returned an unexpected value: {}", x)
}
}
}
}