use alloc::string::String;
use alloc::vec::Vec;
#[path = "linux_disp.rs"]
mod disp;
pub use disp::*;
#[path = "linux_wl.rs"]
mod wl;
pub use wl::*;
#[path = "linux_x11.rs"]
mod x11;
pub use x11::*;
#[path = "linux_portal.rs"]
mod portal;
pub use portal::*;
#[path = "linux_tray.rs"]
pub(crate) mod linux_tray;
#[path = "linux_dbus.rs"]
pub(crate) mod linux_dbus;
#[path = "linux_docs.rs"]
pub(crate) mod linux_docs;
#[path = "linux_atspi.rs"]
pub(crate) mod linux_atspi;
#[path = "linux_ibus.rs"]
mod linux_ibus;
#[path = "linux_life.rs"]
mod linux_life;
#[path = "linux_screen.rs"]
pub(crate) mod linux_screen;
#[path = "linux_hotkey.rs"]
pub(crate) mod linux_hotkey;
#[path = "linux_settings.rs"]
pub(crate) mod linux_settings;
pub(crate) use linux_settings::sys_settings_os;
pub use linux_life::{life_poll, life_start};
pub use linux_ibus::{IBUS_RELEASE, ibus_available, ibus_focus, ibus_key, ibus_ready};
#[path = "linux_sys.rs"]
mod sys;
pub use sys::*;
#[path = "linux_thread.rs"]
mod thread;
pub use thread::*;
#[path = "linux_crash.rs"]
mod crash;
#[path = "linux_print.rs"]
mod lprint;
pub use lprint::*;
#[path = "linux_elfload.rs"]
mod elfload;
pub use elfload::*;
#[path = "linux_guard.rs"]
mod guard;
pub(crate) use guard::*;
use rt::os::*;
static mut START_SP: *const usize = core::ptr::null();
unsafe extern "Rust" {
fn jfgui_main() -> i32;
}
#[cfg(not(any(jfgui_glibc, feature = "std")))] core::arch::global_asm!(
".globl _start",
"_start:",
" xor ebp, ebp",
" mov rdi, rsp",
" and rsp, -16",
" call {entry}",
" ud2",
entry = sym linux_entry,
);
#[cfg(not(any(jfgui_glibc, feature = "std")))] extern "C" fn linux_entry(sp: *const usize) -> ! {
unsafe { START_SP = sp };
crash::crash_init();
thread::wake_init();
crate::cpu::simd_override();
rt::boot::set_handler(crate::boot::start); let code = unsafe { jfgui_main() };
rt::os::exit(code)
}
pub fn time_us() -> u64 {
let mut ts = [0i64; 2];
unsafe { syscall3(SYS_CLOCK_GETTIME, 1, ts.as_mut_ptr() as usize, 0) };
ts[0] as u64 * 1_000_000 + ts[1] as u64 / 1000
}
pub fn unix_time_ns() -> i64 {
let mut ts = [0i64; 2];
unsafe { syscall3(SYS_CLOCK_GETTIME, 0, ts.as_mut_ptr() as usize, 0) };
ts[0].wrapping_mul(1_000_000_000).wrapping_add(ts[1])
}
unsafe fn cstr(p: *const u8) -> String {
let mut n = 0;
while unsafe { *p.add(n) } != 0 {
n += 1;
}
String::from_utf8_lossy(unsafe { core::slice::from_raw_parts(p, n) }).into_owned()
}
pub fn args() -> Vec<String> {
let mut v = Vec::new();
unsafe {
let sp = START_SP;
if sp.is_null() {
return v;
}
let argc = *sp;
for i in 0..argc {
v.push(cstr(*sp.add(1 + i) as *const u8));
}
}
v
}
static ENV: rt::sync::SpinLock<Option<Vec<Vec<u8>>>> = rt::sync::SpinLock::new(None);
pub(crate) fn process_environment() -> Vec<Vec<u8>> {
env_list(&mut ENV.lock()).clone()
}
fn env_list(g: &mut Option<Vec<Vec<u8>>>) -> &mut Vec<Vec<u8>> {
g.get_or_insert_with(|| {
let mut v = Vec::new();
unsafe {
let sp = START_SP;
if !sp.is_null() {
let argc = *sp;
let mut e = sp.add(argc + 2);
while *e != 0 {
let p = *e as *const u8;
let mut n = 0;
while *p.add(n) != 0 {
n += 1;
}
v.push(core::slice::from_raw_parts(p, n).to_vec());
e = e.add(1);
}
}
}
v
})
}
pub fn env(name: &str) -> Option<String> {
let mut g = ENV.lock();
let n = name.as_bytes();
env_list(&mut g)
.iter()
.find(|e| e.len() > n.len() && e.starts_with(n) && e[n.len()] == b'=')
.map(|e| String::from_utf8_lossy(&e[n.len() + 1..]).into_owned())
}
pub fn getenv(name: &str) -> Option<String> {
env(name)
}
pub fn setenv(name: &str, value: Option<&str>) -> bool {
let mut g = ENV.lock();
let list = env_list(&mut g);
let n = name.as_bytes();
list.retain(|e| !(e.len() > n.len() && e.starts_with(n) && e[n.len()] == b'='));
if let Some(v) = value {
let mut e = n.to_vec();
e.push(b'=');
e.extend_from_slice(v.as_bytes());
list.push(e);
}
true
}
pub fn sleep_ms(ms: u32) {
unsafe { rt::os::poll(0, 0, ms as i32) };
}
#[cfg(jfgui_glibc)]
#[path = "linux_glibc.rs"]
mod glibc;
#[cfg(jfgui_glibc)]
pub use glibc::{at_exit, dl_close, dl_error, dl_open, dl_sym, glibc_thread_ids, glibc_version};
#[cfg(all(jfgui_glibc, not(feature = "std")))]
pub use glibc::exit;
#[cfg(feature = "std")]
pub use glibc::std_start; #[cfg(jfgui_glibc)] #[path = "linux_gpuout.rs"] pub(crate) mod gpuout; #[cfg(jfgui_glibc)] pub use gpuout::*;