use super::Error;
use std::ffi::{CStr, c_char, c_void};
#[link(name = "System")]
unsafe extern "C" {
fn dlsym(handle: *mut c_void, symbol: *const c_char) -> *mut c_void;
}
fn integer_constant(symbols: &[&CStr]) -> Result<isize, Error> {
let handle = (-2_isize) as *mut c_void;
for symbol in symbols {
let address = unsafe { dlsym(handle, symbol.as_ptr()) };
if !address.is_null() {
return Ok(unsafe { address.cast::<isize>().read() });
}
}
Err(Error::unsupported(format!(
"runtime constant {:?} is unavailable",
symbols[0]
)))
}
pub fn device_certification_iphone_performance_gaming() -> Result<isize, Error> {
integer_constant(&[
c"NSDeviceCertificationiPhonePerformanceGaming",
c"MTLDeviceCertificationiPhonePerformanceGaming",
])
}
pub fn process_performance_profile_default() -> Result<isize, Error> {
integer_constant(&[
c"NSProcessPerformanceProfileDefault",
c"MTLProcessPerformanceProfileDefault",
])
}
pub fn process_performance_profile_sustained() -> Result<isize, Error> {
integer_constant(&[
c"NSProcessPerformanceProfileSustained",
c"MTLProcessPerformanceProfileSustained",
])
}