std_detect/detect/os/linux/
mod.rs1use alloc::vec::Vec;
4
5mod auxvec;
6
7fn read_file(orig_path: &str) -> Result<Vec<u8>, alloc::string::String> {
8 use alloc::format;
9
10 let mut path = Vec::from(orig_path.as_bytes());
11 path.push(0);
12
13 unsafe {
14 let file = libc::open(path.as_ptr() as *const libc::c_char, libc::O_RDONLY);
15 if file == -1 {
16 return Err(format!("Cannot open file at {orig_path}"));
17 }
18
19 let mut data = Vec::new();
20 loop {
21 data.reserve(4096);
22 let spare = data.spare_capacity_mut();
23 match libc::read(file, spare.as_mut_ptr() as *mut _, spare.len()) {
24 -1 => {
25 libc::close(file);
26 return Err(format!("Error while reading from file at {orig_path}"));
27 }
28 0 => break,
29 n => data.set_len(data.len() + n as usize),
30 }
31 }
32
33 libc::close(file);
34 Ok(data)
35 }
36}
37
38cfg_select! {
39 target_arch = "aarch64" => {
40 mod aarch64;
41 pub(crate) use self::aarch64::detect_features;
42 }
43 target_arch = "arm" => {
44 mod arm;
45 pub(crate) use self::arm::detect_features;
46 }
47 any(target_arch = "riscv32", target_arch = "riscv64") => {
48 mod riscv;
49 pub(crate) use self::riscv::detect_features;
50 }
51 any(target_arch = "mips", target_arch = "mips64") => {
52 mod mips;
53 pub(crate) use self::mips::detect_features;
54 }
55 any(target_arch = "powerpc", target_arch = "powerpc64") => {
56 mod powerpc;
57 pub(crate) use self::powerpc::detect_features;
58 }
59 any(target_arch = "loongarch32", target_arch = "loongarch64") => {
60 mod loongarch;
61 pub(crate) use self::loongarch::detect_features;
62 }
63 target_arch = "s390x" => {
64 mod s390x;
65 pub(crate) use self::s390x::detect_features;
66 }
67 _ => {
68 use crate::detect::cache;
69 pub(crate) fn detect_features() -> cache::Initializer {
71 cache::Initializer::default()
72 }
73 }
74}