#![no_std]
#![feature(linkage)]
#[macro_use]
pub mod error;
pub use error::*;
#[doc(hidden)]
pub const MOTO_SYS_CUSTOM_USERSPACE_REGION_START: u64 = (1_u64 << 45) + (1_u64 << 40);
#[doc(hidden)]
const MOTO_SYS_CUSTOM_USERSPACE_REGION_END: u64 =
MOTO_SYS_CUSTOM_USERSPACE_REGION_START + (1_u64 << 40);
#[doc(hidden)]
const MOTO_SYS_PAGE_SIZE_SMALL: u64 = 4096;
#[doc(hidden)]
pub const RT_VDSO_START: u64 = MOTO_SYS_CUSTOM_USERSPACE_REGION_END - (1_u64 << 32);
#[doc(hidden)]
pub const RT_VDSO_BYTES_ADDR: u64 = RT_VDSO_START - (1_u64 << 32);
#[doc(hidden)]
pub const RT_VDSO_VTABLE_VADDR: u64 = RT_VDSO_START - MOTO_SYS_PAGE_SIZE_SMALL;
#[cfg(feature = "libc")]
pub mod libc;
#[cfg(not(feature = "base"))]
pub mod alloc;
#[cfg(not(feature = "base"))]
pub mod fs;
#[cfg(not(feature = "base"))]
pub mod futex;
#[cfg(not(feature = "base"))]
pub mod mutex;
#[cfg(not(feature = "base"))]
pub mod net;
#[cfg(not(feature = "base"))]
#[allow(nonstandard_style)]
pub mod netc;
#[cfg(not(feature = "base"))]
pub mod poll;
#[cfg(not(feature = "base"))]
pub mod process;
#[cfg(not(feature = "base"))]
pub mod thread;
#[cfg(not(feature = "base"))]
pub mod time;
#[cfg(not(feature = "base"))]
pub mod tls;
pub mod spinlock;
#[cfg(not(feature = "base"))]
pub use futex::*;
#[cfg(not(feature = "base"))]
use core::sync::atomic::{AtomicU64, Ordering};
#[cfg(not(feature = "base"))]
pub type RtFd = i32;
#[cfg(not(feature = "base"))]
pub const FD_STDIN: RtFd = 0;
#[cfg(not(feature = "base"))]
pub const FD_STDOUT: RtFd = 1;
#[cfg(not(feature = "base"))]
pub const FD_STDERR: RtFd = 2;
#[cfg(not(feature = "base"))]
pub const RT_VERSION: u64 = 15;
#[cfg(not(feature = "base"))]
#[doc(hidden)]
#[repr(C)]
pub struct RtVdsoVtable {
pub vdso_entry: AtomicU64,
pub vdso_bytes_sz: AtomicU64,
pub alloc: AtomicU64,
pub alloc_zeroed: AtomicU64,
pub realloc: AtomicU64,
pub dealloc: AtomicU64,
pub release_handle: AtomicU64,
pub time_instant_now: AtomicU64,
pub time_ticks_to_nanos: AtomicU64,
pub time_nanos_to_ticks: AtomicU64,
pub time_ticks_in_sec: AtomicU64,
pub time_abs_ticks_to_nanos: AtomicU64,
pub futex_wait: AtomicU64,
pub futex_wake: AtomicU64,
pub futex_wake_all: AtomicU64,
pub proc_args: AtomicU64,
pub proc_get_full_env: AtomicU64,
pub proc_getenv: AtomicU64,
pub proc_setenv: AtomicU64,
pub proc_spawn: AtomicU64,
pub proc_kill: AtomicU64,
pub proc_wait: AtomicU64,
pub proc_status: AtomicU64,
pub proc_exit: AtomicU64,
pub tls_create: AtomicU64,
pub tls_set: AtomicU64,
pub tls_get: AtomicU64,
pub tls_destroy: AtomicU64,
pub thread_spawn: AtomicU64,
pub thread_sleep: AtomicU64,
pub thread_yield: AtomicU64,
pub thread_set_name: AtomicU64,
pub thread_join: AtomicU64,
pub fs_is_terminal: AtomicU64,
pub fs_open: AtomicU64,
pub fs_close: AtomicU64,
pub fs_get_file_attr: AtomicU64,
pub fs_fsync: AtomicU64,
pub fs_datasync: AtomicU64,
pub fs_truncate: AtomicU64,
pub fs_read: AtomicU64,
pub fs_read_vectored: AtomicU64,
pub fs_write: AtomicU64,
pub fs_write_vectored: AtomicU64,
pub fs_flush: AtomicU64,
pub fs_seek: AtomicU64,
pub fs_mkdir: AtomicU64,
pub fs_unlink: AtomicU64,
pub fs_rename: AtomicU64,
pub fs_rmdir: AtomicU64,
pub fs_rmdir_all: AtomicU64,
pub fs_set_perm: AtomicU64,
pub fs_set_file_perm: AtomicU64,
pub fs_stat: AtomicU64,
pub fs_canonicalize: AtomicU64,
pub fs_copy: AtomicU64,
pub fs_opendir: AtomicU64,
pub fs_closedir: AtomicU64,
pub fs_readdir: AtomicU64,
pub fs_getcwd: AtomicU64,
pub fs_chdir: AtomicU64,
pub fs_duplicate: AtomicU64,
pub dns_lookup: AtomicU64,
pub net_bind: AtomicU64,
pub net_listen: AtomicU64,
pub net_accept: AtomicU64,
pub net_tcp_connect: AtomicU64,
pub net_udp_connect: AtomicU64,
pub net_socket_addr: AtomicU64,
pub net_peer_addr: AtomicU64,
pub net_setsockopt: AtomicU64,
pub net_getsockopt: AtomicU64,
pub net_peek: AtomicU64,
pub net_udp_recv_from: AtomicU64,
pub net_udp_peek_from: AtomicU64,
pub net_udp_send_to: AtomicU64,
pub net_udp_multicast_op_v4: AtomicU64,
pub net_udp_multicast_op_v6: AtomicU64,
pub poll_new: AtomicU64,
pub poll_add: AtomicU64,
pub poll_set: AtomicU64,
pub poll_del: AtomicU64,
pub poll_wait: AtomicU64,
pub poll_wake: AtomicU64,
pub log_to_kernel: AtomicU64,
pub log_backtrace: AtomicU64,
pub fill_random_bytes: AtomicU64,
pub num_cpus: AtomicU64,
pub internal_helper: AtomicU64,
pub current_exe: AtomicU64,
}
#[cfg(not(feature = "base"))]
const _SIZE_CHECK: () = assert!(size_of::<RtVdsoVtable>() <= 4096);
#[cfg(not(feature = "base"))]
#[doc(hidden)]
impl RtVdsoVtable {
pub fn get() -> &'static Self {
unsafe {
(RT_VDSO_VTABLE_VADDR as usize as *const RtVdsoVtable)
.as_ref()
.unwrap_unchecked()
}
}
}
#[cfg(not(feature = "base"))]
#[doc(hidden)]
pub fn init() {
assert_ne!(0, RtVdsoVtable::get().vdso_entry.load(Ordering::Acquire));
let vdso_entry: extern "C" fn(u64) = unsafe {
core::mem::transmute(
RtVdsoVtable::get().vdso_entry.load(Ordering::Relaxed) as usize as *const (),
)
};
vdso_entry(RT_VERSION)
}
#[cfg(not(feature = "base"))]
#[linkage = "weak"]
#[unsafe(no_mangle)]
pub extern "C" fn motor_runtime_start() {
init();
}
#[cfg(not(feature = "base"))]
#[doc(hidden)]
pub fn start() {
motor_runtime_start();
}
#[cfg(not(feature = "base"))]
pub fn fill_random_bytes(bytes: &mut [u8]) {
let vdso_fill_random_bytes: extern "C" fn(*mut u8, usize) = unsafe {
core::mem::transmute(
RtVdsoVtable::get()
.fill_random_bytes
.load(Ordering::Relaxed) as usize as *const (),
)
};
vdso_fill_random_bytes(bytes.as_mut_ptr(), bytes.len())
}
#[cfg(not(feature = "base"))]
pub fn num_cpus() -> usize {
let vdso_num_cpus: extern "C" fn() -> usize = unsafe {
core::mem::transmute(
RtVdsoVtable::get().num_cpus.load(Ordering::Relaxed) as usize as *const (),
)
};
vdso_num_cpus()
}
#[cfg(not(feature = "base"))]
#[doc(hidden)]
pub fn internal_helper(a0: u64, a1: u64, a2: u64, a3: u64, a4: u64, a5: u64) -> u64 {
let vdso_internal_helper: extern "C" fn(u64, u64, u64, u64, u64, u64) -> u64 = unsafe {
core::mem::transmute(
RtVdsoVtable::get().internal_helper.load(Ordering::Relaxed) as usize as *const (),
)
};
vdso_internal_helper(a0, a1, a2, a3, a4, a5)
}