data_type large_stringclasses 3
values | source large_stringclasses 29
values | code large_stringlengths 98 49.4M | filepath large_stringlengths 5 161 ⌀ | message large_stringclasses 234
values | commit large_stringclasses 234
values | subject large_stringclasses 418
values | critique large_stringlengths 101 1.26M ⌀ | metadata dict |
|---|---|---|---|---|---|---|---|---|
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use super::SyscallReturn;
use crate::{
fs,
fs::{
file_table::FileDesc,
path::{AT_FDCWD, FsPath},
utils::{InodeType, mkmod},
},
prelude::*,
syscall::constants::MAX_FILENAME_LEN,
};
pub fn sys_symlinkat(
target_addr: Vaddr,
dirfd: F... | kernel/src/syscall/symlink.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use super::SyscallReturn;
use crate::{
fs::file_table::{FileDesc, get_file_fast},
prelude::*,
};
pub fn sys_sync(ctx: &Context) -> Result<SyscallReturn> {
let current_ns_proxy = ctx.thread_local.borrow_ns_proxy();
let current_mnt_ns = current_ns_proxy.unwrap().mnt_n... | kernel/src/syscall/sync.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use aster_time::read_monotonic_time;
use ostd::mm::VmIo;
use super::SyscallReturn;
use crate::{prelude::*, process::process_table};
#[repr(C)]
#[padding_struct]
#[derive(Debug, Default, Clone, Copy, Pod)]
struct SysInfo {
uptime: i64, /* Seconds since boot */
loads: [u... | kernel/src/syscall/sysinfo.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use super::SyscallReturn;
use crate::{
prelude::*,
process::{
Pid,
signal::{
sig_num::SigNum,
signals::{
Signal,
user::{UserSignal, UserSignalKind},
},
},
tgkill,
},
t... | kernel/src/syscall/tgkill.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use ostd::mm::VmIo;
use super::SyscallReturn;
use crate::{prelude::*, time::SystemTime};
pub fn sys_time(tloc: Vaddr, ctx: &Context) -> Result<SyscallReturn> {
debug!("tloc = 0x{tloc:x}");
let now_as_secs = {
let now = SystemTime::now();
now.duration_since... | kernel/src/syscall/time.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use ostd::mm::VmIo;
use super::{
SyscallReturn,
clock_gettime::{DynamicClockIdInfo, DynamicClockType},
};
use crate::{
prelude::*,
process::{
posix_thread::{AsPosixThread, thread_table},
process_table,
signal::{
c_types::{SigNotif... | kernel/src/syscall/timer_create.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use core::time::Duration;
use ostd::mm::VmIo;
use super::SyscallReturn;
use crate::{
prelude::*,
time::{TIMER_ABSTIME, itimerspec_t, timer::Timeout, timespec_t},
};
pub fn sys_timer_settime(
timer_id: usize,
flags: i32,
new_itimerspec_addr: Vaddr,
old_itim... | kernel/src/syscall/timer_settime.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use super::SyscallReturn;
use crate::{
fs::file_table::FdFlags,
prelude::*,
time::{
clockid_t,
timerfd::{TFDFlags, TimerfdFile},
},
};
pub fn sys_timerfd_create(clockid: clockid_t, flags: i32, ctx: &Context) -> Result<SyscallReturn> {
let flags =... | kernel/src/syscall/timerfd_create.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use ostd::mm::VmIo;
use super::SyscallReturn;
use crate::{
fs::file_table::FileDesc,
prelude::*,
time::{itimerspec_t, timerfd::TimerfdFile, timespec_t},
};
pub fn sys_timerfd_gettime(
fd: FileDesc,
itimerspec_addr: Vaddr,
ctx: &Context,
) -> Result<SyscallR... | kernel/src/syscall/timerfd_gettime.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use core::time::Duration;
use ostd::mm::VmIo;
use super::SyscallReturn;
use crate::{
fs::file_table::FileDesc,
prelude::*,
time::{
itimerspec_t,
timerfd::{TFDSetTimeFlags, TimerfdFile},
timespec_t,
},
};
pub fn sys_timerfd_settime(
fd: ... | kernel/src/syscall/timerfd_settime.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use super::SyscallReturn;
use crate::{
fs,
fs::{
file_table::{FileDesc, get_file_fast},
path::{AT_FDCWD, FsPath},
utils::PATH_MAX,
},
prelude::*,
process::ResourceType,
};
pub fn sys_ftruncate(fd: FileDesc, len: isize, ctx: &Context) -> R... | kernel/src/syscall/truncate.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use super::SyscallReturn;
use crate::prelude::*;
pub fn sys_umask(mask: u16, ctx: &Context) -> Result<SyscallReturn> {
debug!("mask = 0o{:o}", mask);
let old_mask = ctx.thread_local.borrow_fs().swap_umask(mask.try_into()?);
Ok(SyscallReturn::Return(old_mask.get() as _))... | kernel/src/syscall/umask.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use super::SyscallReturn;
use crate::{
fs::path::{AT_FDCWD, FsPath},
prelude::*,
syscall::constants::MAX_FILENAME_LEN,
};
pub fn sys_umount(path_addr: Vaddr, flags: u64, ctx: &Context) -> Result<SyscallReturn> {
let path_name = ctx.user_space().read_cstring(path_add... | kernel/src/syscall/umount.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use ostd::mm::VmIo;
use super::SyscallReturn;
use crate::prelude::*;
pub fn sys_uname(old_uname_addr: Vaddr, ctx: &Context) -> Result<SyscallReturn> {
debug!("old uname addr = 0x{:x}", old_uname_addr);
let ns_proxy = ctx.thread_local.borrow_ns_proxy();
let uts_name = ns... | kernel/src/syscall/uname.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use super::SyscallReturn;
use crate::{
fs::{
file_table::FileDesc,
path::{AT_FDCWD, FsPath, SplitPath},
},
prelude::*,
syscall::constants::MAX_FILENAME_LEN,
};
pub fn sys_unlinkat(
dirfd: FileDesc,
path_addr: Vaddr,
flags: u32,
ctx: &... | kernel/src/syscall/unlink.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use crate::{
prelude::*,
process::{CloneFlags, ContextUnshareAdminApi},
syscall::SyscallReturn,
};
pub fn sys_unshare(unshare_flags: u32, ctx: &Context) -> Result<SyscallReturn> {
let mut flags = CloneFlags::from_bits(unshare_flags)
.ok_or_else(|| Error::wit... | kernel/src/syscall/unshare.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use core::time::Duration;
use ostd::mm::VmIo;
use super::{SyscallReturn, constants::MAX_FILENAME_LEN};
use crate::{
fs,
fs::{
file_table::FileDesc,
path::{AT_FDCWD, FsPath, Path},
},
prelude::*,
time::{clocks::RealTimeCoarseClock, timespec_t, ti... | kernel/src/syscall/utimens.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use ostd::mm::VmIo;
use super::{SyscallReturn, getrusage::rusage_t};
use crate::{
prelude::*,
process::{ProcessFilter, WaitOptions, WaitStatus, do_wait},
};
pub fn sys_wait4(
wait_pid: u64,
status_ptr: u64,
wait_options: u32,
rusage_addr: Vaddr,
ctx: &C... | kernel/src/syscall/wait4.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use ostd::mm::VmIo;
use super::SyscallReturn;
use crate::{
prelude::*,
process::{
ProcessFilter, WaitOptions, WaitStatus, do_wait,
signal::{
c_types::siginfo_t,
constants::{CLD_CONTINUED, CLD_EXITED, CLD_KILLED, CLD_STOPPED, SIGCHLD, ... | kernel/src/syscall/waitid.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use super::SyscallReturn;
use crate::{
fs,
fs::file_table::{FileDesc, get_file_fast},
prelude::*,
};
pub fn sys_write(
fd: FileDesc,
user_buf_ptr: Vaddr,
user_buf_len: usize,
ctx: &Context,
) -> Result<SyscallReturn> {
debug!(
"fd = {}, user_... | kernel/src/syscall/write.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
/// Imports all generic syscall entries.
///
/// This macro is intended solely for internal use within [macro@define_syscalls_with_generic_syscall_table].
///
/// The primary reason for this macro's existence is to facilitate code formatting.
/// The macro, [macro@define_syscalls_wi... | kernel/src/syscall/arch/generic.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! System call dispatch in the LoongArch architecture.
#[path = "./generic.rs"]
mod generic;
generic::define_syscalls_with_generic_syscall_table! {
// TODO: Add LoongArch specific syscalls here.
} | kernel/src/syscall/arch/loongarch.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! System call dispatch in the RISC-V architecture.
#[path = "./generic.rs"]
mod generic;
generic::define_syscalls_with_generic_syscall_table! {
// TODO: Add RISC-V specific syscalls here.
} | kernel/src/syscall/arch/riscv.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! System call dispatch in the x86 architecture.
use super::{
accept::{sys_accept, sys_accept4},
access::{sys_access, sys_faccessat, sys_faccessat2},
alarm::sys_alarm,
arch_prctl::sys_arch_prctl,
bind::sys_bind,
brk::sys_brk,
capget::sys_capget,
cap... | kernel/src/syscall/arch/x86.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
#![expect(unused_variables)]
#[cfg(target_arch = "x86_64")]
use ostd::arch::cpu::context::CpuException;
#[cfg(target_arch = "riscv64")]
use ostd::arch::cpu::context::CpuException;
#[cfg(target_arch = "loongarch64")]
use ostd::arch::cpu::context::CpuExceptionInfo as CpuException;
us... | kernel/src/thread/exception.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use ostd::{
cpu::CpuSet,
task::{Task, TaskOptions},
};
use super::{AsThread, Thread, oops};
use crate::{
prelude::*,
sched::{Nice, SchedPolicy},
};
/// The inner data of a kernel thread.
struct KernelThread;
/// Options to create or spawn a new kernel thread.
pub ... | kernel/src/thread/kernel_thread.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! Posix thread implementation
use core::sync::atomic::{AtomicBool, Ordering};
use aster_util::per_cpu_counter::PerCpuCounter;
use ostd::{
cpu::{AtomicCpuSet, CpuId, CpuSet},
task::Task,
};
use crate::{
prelude::*,
sched::{SchedAttr, SchedPolicy},
};
mod stats;
u... | kernel/src/thread/mod.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! Kernel "oops" handling.
//!
//! In Asterinas, a Rust panic leads to a kernel "oops". A kernel oops behaves
//! as an exceptional control flow event. If kernel oopses happened too many
//! times, the kernel panics and the system gets halted. Kernel oops are per-
//! thread, so on... | kernel/src/thread/oops.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use aster_util::per_cpu_counter::PerCpuCounter;
use spin::Once;
pub(super) static CONTEXT_SWITCH_COUNTER: Once<PerCpuCounter> = Once::new();
/// Counts the number of context switches ever happened across all CPUs.
pub fn collect_context_switch_count() -> usize {
CONTEXT_SWITCH... | kernel/src/thread/stats.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use ostd::{
arch::cpu::context::UserContext,
mm::VmIo,
sync::Waiter,
task::{Task, TaskOptions},
user::{ReturnReason, UserContextApi, UserMode},
};
use super::{Thread, oops};
use crate::{
cpu::LinuxAbi,
current_userspace,
prelude::*,
process::{
... | kernel/src/thread/task.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
#![expect(dead_code)]
//! Work queue mechanism.
//!
//! # Overview
//!
//! A `workqueue` is a kernel-level mechanism used to schedule and execute deferred work.
//! Deferred work refers to tasks that need to be executed at some point in the future,
//! but not necessarily immediate... | kernel/src/thread/work_queue/mod.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use alloc::sync::Weak;
use super::worker_pool::{WorkerPool, WorkerScheduler};
/// SimpleScheduler is the simplest scheduling implementation.
/// Only when there is a liveness problem in the workerpool, increase the workers,
/// set the upper limit of the workers, and do not active... | kernel/src/thread/work_queue/simple_scheduler.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
#![expect(dead_code)]
use core::sync::atomic::{AtomicBool, Ordering};
use intrusive_collections::{LinkedListAtomicLink, intrusive_adapter};
use ostd::cpu::{CpuId, CpuSet};
use crate::prelude::*;
/// A task to be executed by a worker thread.
pub struct WorkItem {
work_func: B... | kernel/src/thread/work_queue/work_item.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
#![expect(dead_code)]
use ostd::{
cpu::{CpuId, CpuSet},
task::Task,
};
use super::worker_pool::WorkerPool;
use crate::{
prelude::*,
sched::{Nice, SchedPolicy},
thread::{AsThread, kernel_thread::ThreadOptions},
};
/// A worker thread. A `Worker` will attempt to... | kernel/src/thread/work_queue/worker.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
#![expect(dead_code)]
use core::{
sync::atomic::{AtomicBool, Ordering},
time::Duration,
};
use ostd::{
cpu::{CpuId, CpuSet},
sync::WaitQueue,
task::Task,
};
use super::{WorkItem, WorkPriority, WorkQueue, simple_scheduler::SimpleScheduler, worker::Worker};
use ... | kernel/src/thread/work_queue/worker_pool.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use aster_util::per_cpu_counter::PerCpuCounter;
use ostd::{
cpu::{CpuId, PrivilegeLevel},
irq::InterruptLevel,
timer::Jiffies,
};
use spin::Once;
use crate::{sched::SchedPolicy, thread::Thread};
/// Represents CPU usage statistics for a system.
///
/// This structure co... | kernel/src/time/cpu_time_stats.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
#![expect(non_camel_case_types)]
pub use core::{Clock, timer};
use ::core::time::Duration;
pub use system_time::{START_TIME, SystemTime};
pub use timer::{Timer, TimerManager};
use crate::prelude::*;
pub mod clocks;
mod core;
pub mod cpu_time_stats;
mod softirq;
mod system_time;
... | kernel/src/time/mod.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use alloc::{boxed::Box, vec, vec::Vec};
use aster_softirq::{SoftIrqLine, softirq_id::TIMER_SOFTIRQ_ID};
use ostd::{sync::RcuOption, timer};
#[expect(clippy::type_complexity)]
static TIMER_SOFTIRQ_CALLBACKS: RcuOption<Box<Vec<fn()>>> = RcuOption::new_none();
pub(super) fn init() {... | kernel/src/time/softirq.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use core::time::Duration;
use aster_time::{read_monotonic_time, read_start_time};
use spin::Once;
use time::{Date, Month, PrimitiveDateTime, Time};
use crate::prelude::*;
/// This struct corresponds to `SystemTime` in Rust std.
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
pub... | kernel/src/time/system_time.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use core::{
fmt::Display,
sync::atomic::{AtomicU32, AtomicU64, Ordering},
time::Duration,
};
use atomic_integer_wrapper::define_atomic_version_of_integer_like_type;
use super::clockid_t;
use crate::{
events::IoEvents,
fs::{
file_handle::FileLike,
... | kernel/src/time/timerfd.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use core::time::Duration;
use ostd::sync::{WaitQueue, Waiter};
use super::{Timer, TimerManager, clocks::JIFFIES_TIMER_MANAGER, timer::Timeout};
use crate::{prelude::*, time::timer::TimerGuard};
/// A trait that provide the timeout related function for [`Waiter`] and [`WaitQueue`]... | kernel/src/time/wait.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use alloc::sync::Arc;
use core::time::Duration;
use ostd::{
sync::{LocalIrqDisabled, SpinLock},
timer::Jiffies,
};
use crate::time::Clock;
/// A clock used to record the CPU time for processes and threads.
pub struct CpuClock {
time: SpinLock<Jiffies, LocalIrqDisabled... | kernel/src/time/clocks/cpu_clock.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
pub use cpu_clock::*;
pub use system_wide::*;
mod cpu_clock;
mod system_wide;
pub(super) fn init() {
system_wide::init();
} | kernel/src/time/clocks/mod.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use alloc::sync::Arc;
use core::time::Duration;
use aster_time::read_monotonic_time;
use ostd::{cpu::PinCurrentCpu, cpu_local, sync::SpinLock, task::disable_preempt, timer::Jiffies};
use paste::paste;
use spin::Once;
use crate::time::{
self, Clock, SystemTime, system_time::STA... | kernel/src/time/clocks/system_wide.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use core::time::Duration;
pub mod timer;
/// A trait that can abstract clocks which have the ability to read time,
/// and has a fixed resolution.
pub trait Clock: Send + Sync {
/// Read the current time of this clock.
fn read_time(&self) -> Duration;
} | kernel/src/time/core/mod.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use alloc::{
boxed::Box,
collections::BinaryHeap,
sync::{Arc, Weak},
vec::Vec,
};
use core::{
sync::atomic::{AtomicBool, Ordering},
time::Duration,
};
use ostd::sync::{LocalIrqDisabled, SpinLock, SpinLockGuard};
use super::Clock;
/// A timeout, represented... | kernel/src/time/core/timer.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use crate::prelude::*;
/// A trait that can copies structures from/to the user space in a backward-compatible way.
pub trait CopyCompat {
/// Reads a POD structure from the user space in a backward-compatible way.
///
/// The method's behavior is described below to ensu... | kernel/src/util/copy_compact.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use ostd::mm::{Infallible, VmSpace};
use crate::prelude::*;
/// A kernel space I/O vector.
#[derive(Debug, Clone, Copy)]
struct IoVec {
base: Vaddr,
len: usize,
}
/// A user space I/O vector.
///
/// The difference between `IoVec` and `UserIoVec`
/// is that `UserIoVec` u... | kernel/src/util/iovec.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
mod copy_compact;
pub mod ioctl;
mod iovec;
pub mod net;
mod padded;
pub mod random;
mod read_cstring;
pub mod ring_buffer;
pub use copy_compact::CopyCompat;
pub use iovec::{MultiRead, MultiWrite, VmReaderArray, VmWriterArray};
pub use padded::padded;
pub use read_cstring::ReadCStr... | kernel/src/util/mod.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
/// Creates a fixed-size byte array out of a byte slice.
///
/// # Example
///
/// ```
/// let fixed_size_text: [u8; 128] = padded(b"Hello World");
/// ```
///
/// Without this `padded` utility function,
/// one would have to write a more lengthy but less efficient version.
///
/// ... | kernel/src/util/padded.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use rand::{RngCore, SeedableRng, rngs::StdRng};
use spin::Once;
use crate::prelude::*;
static RNG: Once<SpinLock<StdRng>> = Once::new();
/// Fill `dest` with random bytes.
///
/// It's cryptographically secure, as documented in [`rand::rngs::StdRng`].
pub fn getrandom(dst: &mut [... | kernel/src/util/random.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use ostd::mm::Fallible;
use super::VmReaderArray;
use crate::prelude::*;
/// A trait providing the ability to read a C string from the user space.
pub trait ReadCString {
/// Reads bytes until the first nul byte and creates a C string.
///
/// This method reads up to `... | kernel/src/util/read_cstring.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use core::{
marker::PhantomData,
num::Wrapping,
ops::Deref,
sync::atomic::{AtomicUsize, Ordering},
};
use inherit_methods_macro::inherit_methods;
use ostd::mm::{FrameAllocOptions, Segment, VmIo, io_util::HasVmReaderWriter};
use super::{MultiRead, MultiWrite};
use c... | kernel/src/util/ring_buffer.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! Decoding and dispatching ioctl commands.
//!
//! When the system call layer handles an ioctl system call, it creates a [`RawIoctl`], which is
//! basically the numeric ioctl command and argument.
//!
//! The component that handles the specific ioctl logic should first convert th... | kernel/src/util/ioctl/mod.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use int_to_c_enum::TryFromInt;
/// An ioctl command that follows Linux-style encoding.
///
/// Layout (from LSB to MSB):
/// - bits 0..=7 : command number (nr)
/// - bits 8..=15 : type / magic
/// - bits 16..=29 : size (in bytes)
/// - bits 30..=31 : direction
///
/// Reference:... | kernel/src/util/ioctl/sealed.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
mod addr;
mod options;
mod socket;
pub use addr::{
CSocketAddrFamily, read_socket_addr_from_user, write_socket_addr_to_user,
write_socket_addr_with_max_len,
};
pub use options::{CSocketOptionLevel, new_raw_socket_option};
pub use socket::{CUserMsgHdr, Protocol, SOCK_TYPE_MA... | kernel/src/util/net/mod.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use super::read_socket_addr_from_user;
use crate::{
net::socket::util::{ControlMessage, SocketAddr},
prelude::*,
util::{
VmReaderArray, VmWriterArray, iovec::MAX_IO_VECTOR_LENGTH,
net::write_socket_addr_with_max_len,
},
};
/// Standard well-defined I... | kernel/src/util/net/socket.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use core::cmp::min;
use ostd::{mm::VmIo, task::Task};
use super::{ip::CSocketAddrInet, netlink::CSocketAddrNetlink, unix, vsock::CSocketAddrVm};
use crate::{current_userspace, net::socket::util::SocketAddr, prelude::*};
/// Address family.
///
/// See <https://elixir.bootlin.com/... | kernel/src/util/net/addr/family.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use aster_bigtcp::wire::{Ipv4Address, PortNum};
use super::family::CSocketAddrFamily;
use crate::prelude::*;
/// IPv4 socket address.
///
/// See <https://www.man7.org/linux/man-pages/man7/ip.7.html>.
///
/// The pad bytes (namely `sin_zero`) do not appear in the man pages, but ar... | kernel/src/util/net/addr/ip.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
pub use family::{
CSocketAddrFamily, read_socket_addr_from_user, write_socket_addr_to_user,
write_socket_addr_with_max_len,
};
mod family;
mod ip;
mod netlink;
mod unix;
mod vsock; | kernel/src/util/net/addr/mod.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use super::CSocketAddrFamily;
use crate::{
net::socket::netlink::{GroupIdSet, NetlinkSocketAddr},
prelude::*,
};
/// Netlink socket address.
#[repr(C)]
#[derive(Debug, Clone, Copy, Pod)]
pub struct CSocketAddrNetlink {
/// Address family (AF_NETLINK).
nl_family: u16... | kernel/src/util/net/addr/netlink.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use core::{ffi::CStr, mem::offset_of};
use super::family::CSocketAddrFamily;
use crate::{net::socket::unix::UnixSocketAddr, prelude::*};
/// UNIX domain socket address.
///
/// See <https://www.man7.org/linux/man-pages/man7/unix.7.html>.
#[repr(C)]
#[derive(Debug, Clone, Copy, Pod... | kernel/src/util/net/addr/unix.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use super::family::CSocketAddrFamily;
use crate::{net::socket::vsock::VsockSocketAddr, prelude::*};
/// VSOCK socket address.
#[repr(C)]
#[derive(Debug, Clone, Copy, Pod)]
pub(super) struct CSocketAddrVm {
/// Address family (AF_VSOCK).
svm_family: u16,
/// Reserved (al... | kernel/src/util/net/addr/vsock.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use int_to_c_enum::TryFromInt;
use super::RawSocketOption;
use crate::{
impl_raw_socket_option,
net::socket::ip::options::{Hdrincl, Recverr, Tos, Ttl},
prelude::*,
util::net::options::SocketOption,
};
/// Socket options for IP socket.
///
/// The raw definitions ca... | kernel/src/util/net/options/ip.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! This module introduces utilities to support Linux get/setsockopt syscalls.
//!
//! These two syscalls are used to get/set options for a socket. These options can be at different
//! socket levels and of different types. To provide a unified interface, the `Socket` trait accepts
... | kernel/src/util/net/options/mod.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use super::RawSocketOption;
use crate::{
impl_raw_sock_option_set_only,
net::socket::netlink::{AddMembership, DropMembership},
prelude::*,
util::net::options::SocketOption,
};
/// Socket options for netlink socket.
///
/// Reference: <https://elixir.bootlin.com/linu... | kernel/src/util/net/options/netlink.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use ostd::mm::VmIo;
use super::RawSocketOption;
use crate::{
current_userspace, impl_raw_sock_option_get_only, impl_raw_socket_option,
net::socket::options::{
AcceptConn, Broadcast, Error, KeepAlive, Linger, PassCred, PeerCred, PeerGroups, Priority,
RecvBuf,... | kernel/src/util/net/options/socket.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use super::RawSocketOption;
use crate::{
impl_raw_socket_option,
net::socket::ip::stream_options::{
Congestion, DeferAccept, Inq, KeepIdle, MaxSegment, NoDelay, SynCnt, UserTimeout,
WindowClamp,
},
prelude::*,
util::net::options::SocketOption,
};
... | kernel/src/util/net/options/tcp.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use core::{num::NonZeroU8, time::Duration};
use ostd::mm::VmIo;
use crate::{
current_userspace,
net::socket::{
ip::{options::IpTtl, stream_options::CongestionControl},
unix::CUserCred,
util::LingerOption,
},
prelude::*,
};
/// Create an obj... | kernel/src/util/net/options/utils.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! Virtual memory (VM).
//!
//! There are two primary VM abstractions:
//! * The VMAR (used to be Virtual Memory Address Region, now an orphan
//! initialism) represents the entire virtual address space of a process;
//! * The VMO (Virtual Memory Object) is a set of logically ... | kernel/src/vm/mod.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use aster_rights::Rights;
use bitflags::bitflags;
use ostd::mm::PageFlags;
use crate::prelude::*;
bitflags! {
/// The memory access permissions of memory mappings.
// NOTE: `check` hardcodes `MAY_READ >> 3 == READ`, and so for r/w/x bits.
pub struct VmPerms: u32 {
... | kernel/src/vm/perms.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! Intervals and interval sets used in VMARs.
use alloc::collections::btree_map::{BTreeMap, Cursor, CursorMut};
use core::ops::Range;
/// The interval of an item in an interval set.
///
/// All items in the interval set must have a range.
pub trait Interval<K: Clone> {
/// Re... | kernel/src/vm/vmar/interval_set.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! User address space management.
mod interval_set;
mod util;
mod vm_mapping;
mod vmar_impls;
use ostd::mm::Vaddr;
pub use vmar_impls::{RssType, Vmar};
pub const VMAR_LOWEST_ADDR: Vaddr = 0x001_0000; // 64 KiB is the Linux configurable default
pub const VMAR_CAP_ADDR: Vaddr = o... | kernel/src/vm/vmar/mod.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use core::ops::Range;
/// Determines whether two ranges are intersected.
/// returns false if one of the ranges has a length of 0
pub fn is_intersected(range1: &Range<usize>, range2: &Range<usize>) -> bool {
range1.start.max(range2.start) < range1.end.min(range2.end)
}
/// Get... | kernel/src/vm/vmar/util.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use alloc::{borrow::Cow, format};
use core::{
cmp::{max, min},
num::NonZeroUsize,
ops::Range,
};
use align_ext::AlignExt;
use aster_util::printer::VmPrinter;
use ostd::{
io::IoMem,
mm::{
CachePolicy, Frame, FrameAllocOptions, PageFlags, PageProperty, UFr... | kernel/src/vm/vmar/vm_mapping.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use align_ext::AlignExt;
use ostd::{
mm::{PAGE_SIZE, PageFlags, UFrame, io_util::HasVmReaderWriter, vm_space::VmQueriedItem},
task::disable_preempt,
};
use super::{Vmar, is_userspace_vaddr};
use crate::{prelude::*, thread::exception::PageFaultInfo, vm::vmar::is_userspace_va... | kernel/src/vm/vmar/vmar_impls/access_remote.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use core::array;
use aster_util::per_cpu_counter::PerCpuCounter;
use ostd::{
mm::{
CachePolicy, PageFlags, VmSpace,
tlb::TlbFlushOp,
vm_space::{CursorMut, VmQueriedItem},
},
task::disable_preempt,
};
use super::{RssDelta, VMAR_CAP_ADDR, VMAR_LOW... | kernel/src/vm/vmar/vmar_impls/fork.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use core::num::NonZeroUsize;
use super::{MappedMemory, MappedVmo, RssDelta, VmMapping, Vmar};
use crate::{
fs::{
file_handle::{FileLike, Mappable},
path::Path,
ramfs::memfd::MemfdInode,
},
prelude::*,
vm::{perms::VmPerms, vmo::Vmo},
};
impl ... | kernel/src/vm/vmar/vmar_impls/map.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
mod access_remote;
mod fork;
mod map;
mod page_fault;
mod protect;
mod query;
mod remap;
mod unmap;
use core::{array, ops::Range};
use align_ext::AlignExt;
use aster_util::per_cpu_counter::PerCpuCounter;
use ostd::{cpu::CpuId, mm::VmSpace};
use super::{
VMAR_CAP_ADDR, VMAR_LO... | kernel/src/vm/vmar/vmar_impls/mod.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use super::{Interval, RssDelta, Vmar};
use crate::{prelude::*, thread::exception::PageFaultInfo};
impl Vmar {
pub fn handle_page_fault(&self, page_fault_info: &PageFaultInfo) -> Result<()> {
let inner = self.inner.read();
let address = page_fault_info.address;
... | kernel/src/vm/vmar/vmar_impls/page_fault.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use core::ops::Range;
use super::{Interval, Vmar, util::get_intersected_range};
use crate::{prelude::*, vm::perms::VmPerms};
impl Vmar {
/// Change the permissions of the memory mappings in the specified range.
///
/// The range's start and end addresses must be page-a... | kernel/src/vm/vmar/vmar_impls/protect.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use core::ops::Range;
use ostd::sync::RwMutexReadGuard;
use super::{VmMapping, Vmar, VmarInner};
impl Vmar {
/// Finds all the mapped regions that intersect with the specified range.
pub fn query(&self, range: Range<usize>) -> VmarQueryGuard<'_> {
VmarQueryGuard {... | kernel/src/vm/vmar/vmar_impls/query.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use ostd::{mm::vm_space::VmQueriedItem, task::disable_preempt};
use super::{RssDelta, Vmar, util::is_intersected};
use crate::{prelude::*, vm::vmar::is_userspace_vaddr_range};
impl Vmar {
/// Resizes the original mapping.
///
/// The range of the mapping goes from `map... | kernel/src/vm/vmar/vmar_impls/remap.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use core::ops::Range;
use ostd::task::disable_preempt;
use super::{RssDelta, Vmar};
use crate::{
prelude::*,
vm::vmar::{VMAR_CAP_ADDR, interval_set::Interval, util::get_intersected_range},
};
impl Vmar {
/// Clears all mappings.
///
/// After being cleared, th... | kernel/src/vm/vmar/vmar_impls/unmap.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
#![expect(dead_code)]
#![expect(unused_variables)]
//! Virtual Memory Objects (VMOs).
use core::{
ops::Range,
sync::atomic::{AtomicIsize, AtomicUsize, Ordering},
};
use align_ext::AlignExt;
use ostd::{
mm::{
FrameAllocOptions, UFrame, VmIo, VmIoFill, VmReader,... | kernel/src/vm/vmo/mod.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! Options for allocating root and child VMOs.
use core::sync::atomic::AtomicUsize;
use align_ext::AlignExt;
use ostd::mm::{FrameAllocOptions, UFrame, USegment};
use xarray::XArray;
use super::{Pager, Vmo, VmoFlags, WritableMappingStatus};
use crate::prelude::*;
/// Options for... | kernel/src/vm/vmo/options.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use ostd::mm::UFrame;
use crate::prelude::*;
/// Pagers provide frame to a VMO.
///
/// A `Pager` object can be attached to a VMO. Whenever the
/// VMO needs more frames (i.e., on commits), it will turn to the pager,
/// which should then provide frames whose data have been initia... | kernel/src/vm/vmo/pager.rs | null | null | null | null | null |
source | asterinas | # Accelerate OS development with Asterinas OSDK
[](https://crates.io/crates/cargo-osdk)
[](https://github.com/asterinas/asterinas/actions/workflows/osdk_t... | osdk/README.md | null | null | null | null | null |
source | asterinas | # OSDK deps
This directory contains libraries or kernels that depends on OSTD, independent
to OSTD but by-default shipped with OSDK. | osdk/deps/README.md | null | null | null | null | null |
source | asterinas | # osdk-frame-allocator
This is the default buddy system frame allocator shipped with
[OSDK](https://crates.io/crates/cargo-osdk). It relies on the physical frame
metadata system in [OSTD](https://crates.io/crates/ostd) to provide a heap-free
implementation of a buddy system allocator for OS kernels. It also features
p... | osdk/deps/frame-allocator/README.md | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! A fixed-size local cache for frame allocation.
use core::{alloc::Layout, cell::RefCell};
use ostd::{
cpu_local,
irq::DisabledLocalIrqGuard,
mm::{PAGE_SIZE, Paddr},
};
cpu_local! {
static CACHE: RefCell<CacheOfSizes> = RefCell::new(CacheOfSizes::new());
}
stru... | osdk/deps/frame-allocator/src/cache.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use ostd::{
impl_frame_meta_for,
mm::{HasPaddr, PAGE_SIZE, Paddr, UniqueFrame, frame::linked_list::Link},
};
/// The order of a buddy chunk.
///
/// The size of a buddy chunk is `(1 << order) * PAGE_SIZE`.
pub(crate) type BuddyOrder = usize;
/// Returns the size of a buddy... | osdk/deps/frame-allocator/src/chunk.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
#![no_std]
#![deny(unsafe_code)]
//! An implementation of the global physical memory frame allocator for
//! [OSTD](https://crates.io/crates/ostd) based kernels.
//!
//! # Background
//!
//! `OSTD` has provided a page allocator interface, namely [`GlobalFrameAllocator`]
//! and [`g... | osdk/deps/frame-allocator/src/lib.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use ostd::mm::{HasPaddr, Paddr, frame::linked_list::LinkedList};
use crate::chunk::{BuddyOrder, FreeChunk, FreeHeadMeta, size_of_order};
/// A set of free buddy chunks.
pub(crate) struct BuddySet<const MAX_ORDER: BuddyOrder> {
/// The sum of the sizes of all free chunks.
t... | osdk/deps/frame-allocator/src/set.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! A fast and scalable SMP counter.
use ostd::cpu::{CpuId, all_cpus, local::StaticCpuLocal};
use core::sync::atomic::{AtomicIsize, Ordering};
/// Defines a static fast SMP counter.
//
// See `FastSmpCounter` for more details.
#[macro_export]
macro_rules! fast_smp_counter {
(... | osdk/deps/frame-allocator/src/smp_counter.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! Providing test utilities and high-level test cases for the frame allocator.
use core::alloc::Layout;
use ostd::{
mm::{
FrameAllocOptions, HasPaddr, PAGE_SIZE, Paddr, Segment, UniqueFrame,
frame::GlobalFrameAllocator,
},
prelude::ktest,
};
use super... | osdk/deps/frame-allocator/src/test.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! Controlling the balancing between CPU-local free pools and the global free pool.
use ostd::cpu::num_cpus;
use super::{BuddyOrder, BuddySet, MAX_LOCAL_BUDDY_ORDER, OnDemandGlobalLock, lesser_order_of};
use crate::chunk::split_to_order;
/// Controls the expected size of cache ... | osdk/deps/frame-allocator/src/pools/balancing.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
mod balancing;
use core::{
alloc::Layout,
cell::RefCell,
ops::DerefMut,
sync::atomic::{AtomicUsize, Ordering},
};
use ostd::{
cpu_local,
irq::DisabledLocalIrqGuard,
mm::Paddr,
sync::{LocalIrqDisabled, SpinLock, SpinLockGuard},
};
use crate::chunk::... | osdk/deps/frame-allocator/src/pools/mod.rs | null | null | null | null | null |
source | asterinas | # osdk-heap-allocator
This is the default slab-based global heap allocator shipped with
[OSDK](https://crates.io/crates/cargo-osdk). It relies on the slab mechanism in
[OSTD](https://crates.io/crates/ostd) to provide a fast, memory-efficient
implementation of a global heap allocator for OS kernels. It also features
pe... | osdk/deps/heap-allocator/README.md | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! A global allocator implementation of many slab caches.
use core::{
alloc::{AllocError, Layout},
cell::RefCell,
};
use ostd::{
cpu_local, irq,
mm::{
PAGE_SIZE,
heap::{GlobalHeapAllocator, HeapSlot, SlabSlotList, SlotInfo},
},
sync::{Local... | osdk/deps/heap-allocator/src/allocator.rs | null | null | null | null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.