devela/sys/os/linux/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// devela::sys::os::linux
//
//! Linux-specific definitions
//!
//! # Supported architectures
//!
//! Linux functionality will only be compiled in the following target architectures:
//! - `x86-64`, `x86`, `ARM`, `AArch64`, `RISC-V RV32`, `RISC-V RV64`.
//!
//! Apart from that, this module will compile without checking whether the
//! current OS is `linux`, since that would require enabling `std` and the
//! whole point is to be able to use all of this functionality from `no_std`.
//
// NOTE: doc cfg attributes for target_arch are hidden from reexports
// in order to be have a more concise documentation in the libera crate.
// This is achieved by attaching a brief version to the item itself,
// and attaching a complete version to the module that reexports them.
//
// This is so both for syscalls and safe syscall wrappers. And when more
// platforms are supported they will all need to be updated accordingly.

mod consts;
mod structs;

#[cfg(all(feature = "unsafe_syscall", not(miri)))]
#[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "unsafe_syscall")))]
mod fns;

#[cfg(all(feature = "unsafe_syscall", not(miri)))]
#[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "unsafe_syscall")))]
mod terminal;

/// Linux-specific extensions to [`std::io`].
pub mod io {
    pub use _all::*;
    pub(super) mod _all {
        #[cfg(all(
            any(
                target_arch = "x86_64",
                target_arch = "x86",
                target_arch = "arm",
                target_arch = "aarch64",
                target_arch = "riscv32",
                target_arch = "riscv64"
            ),
            feature = "unsafe_syscall",
            not(miri),
        ))]
        pub use super::super::{
            consts::termios::*,
            fns::{
                linux_eprint, linux_eprintln, linux_get_byte, linux_get_char, linux_get_dirty_char,
                linux_get_line, linux_get_str, linux_get_utf8_bytes, linux_pause_until_char,
                linux_print, linux_print_bytes, linux_println, linux_prompt, linux_random_bytes,
                linux_random_u128, linux_random_u16, linux_random_u32, linux_random_u64,
                linux_random_u8, linux_sys_getrandom, linux_sys_ioctl, linux_sys_read,
                linux_sys_write,
            },
            structs::{LinuxTerminalSize, LinuxTermios},
        };
    }
}

/// Linux-specific extensions to [`std::process`].
pub mod process {
    pub use _all::*;
    pub(super) mod _all {
        #[cfg(all(
            any(
                target_arch = "x86_64",
                target_arch = "x86",
                target_arch = "arm",
                target_arch = "aarch64",
                target_arch = "riscv32",
                target_arch = "riscv64"
            ),
            feature = "unsafe_syscall",
            not(miri),
        ))]
        pub use super::super::{
            consts::signal::*,
            fns::{linux_sig_handler_no_return, linux_sys_exit, linux_sys_rt_sigaction},
            structs::{LinuxSigaction, LinuxSigset},
        };
    }
}

/// Linux-specific extensions to [`std::thread`].
pub mod thread {
    pub use _all::*;
    pub(super) mod _all {
        #[cfg(all(
            any(
                target_arch = "x86_64",
                target_arch = "x86",
                target_arch = "arm",
                target_arch = "aarch64",
                target_arch = "riscv32",
                target_arch = "riscv64"
            ),
            feature = "unsafe_syscall",
            not(miri),
        ))]
        pub use super::super::{
            fns::{linux_getpid, linux_sleep, linux_sys_getpid, linux_sys_nanosleep},
            structs::LinuxTimespec,
        };
    }
}

crate::items! { // structural access: _mods, _pub_mods, _all
    #[allow(unused)]
    pub use _mods::*;
    #[allow(unused)] #[doc(hidden)] #[doc(no_inline)]
    pub use _pub_mods::*;

    mod _mods {
        #[cfg(all(feature = "unsafe_syscall", not(miri)))]
        pub use super::terminal::*;
    }
    mod _pub_mods { #![allow(unused)]
        pub use super::{consts::_all::*, io::_all::*, process::_all::*, thread::_all::*};
    }
    pub(super) mod _all { #![allow(unused)]
        #[doc(inline)]
        pub use super::{_mods::*, _pub_mods::*};
    }
}