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 crate::allocator::CommonSizeClass;
use alloc::vec::Vec;
use core::{alloc::Layout, ops::Deref};
use ostd::{
Error,
cpu::{
CpuId,
local::{DynCpuLocalChunk, DynamicCpuLocal},
},
prelude::*,
sync::SpinLock,
};
/// Allocator for dynamically-alloca... | osdk/deps/heap-allocator/src/cpu_local_allocator.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
#![feature(allocator_api)]
#![no_std]
#![deny(unsafe_code)]
extern crate alloc;
mod allocator;
mod cpu_local_allocator;
mod slab_cache;
pub use allocator::{HeapAllocator, type_from_layout};
pub use cpu_local_allocator::{CpuLocalBox, alloc_cpu_local}; | osdk/deps/heap-allocator/src/lib.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! The slab cache that is composed of slabs.
use core::alloc::AllocError;
use ostd::mm::{
PAGE_SIZE, Paddr,
frame::linked_list::LinkedList,
heap::{HeapSlot, Slab, SlabMeta},
};
const EXPECTED_EMPTY_SLABS: usize = 4;
const MAX_EMPTY_SLABS: usize = 16;
/// A slab cach... | osdk/deps/heap-allocator/src/slab_cache.rs | null | null | null | null | null |
source | asterinas | # osdk-test-kernel
This is an [OSDK](https://crates.io/crates/cargo-osdk)-based kernel that solely
runs unit tests. It is shipped with [OSDK](https://crates.io/crates/cargo-osdk)
to provide default unit-test infrastructure for kernel projects based on
[OSTD](https://crates.io/crates/ostd).
This is part of the [Asteri... | osdk/deps/test-kernel/README.md | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! The OSTD unit test runner is a kernel that runs the tests defined by the
//! `#[ostd::ktest]` attribute. The kernel should be automatically selected to
//! run when OSDK is used to test a specific crate.
#![no_std]
#![forbid(unsafe_code)]
extern crate alloc;
mod path;
mod tre... | osdk/deps/test-kernel/src/lib.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use alloc::{
collections::{BTreeMap, VecDeque, vec_deque},
string::{String, ToString},
};
use core::{fmt::Display, iter::zip, ops::Deref};
pub type PathElement = String;
pub type KtestPathIter<'a> = vec_deque::Iter<'a, PathElement>;
#[derive(Debug)]
pub struct KtestPath {... | osdk/deps/test-kernel/src/path.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! The source module tree of ktests.
//!
//! In the `KtestTree`, the root is abstract, and the children of the root are the
//! crates. The leaves are the test functions. Nodes other than the root and the
//! leaves are modules.
//!
use alloc::{
collections::{BTreeMap, btree_m... | osdk/deps/test-kernel/src/tree.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use clap::{ValueEnum, builder::PossibleValue};
use std::fmt::{self, Display, Formatter};
/// Supported architectures.
///
/// The target triple for each architecture is fixed and shall not
/// be assigned by the user. This is also different from the first
/// element of the target ... | osdk/src/arch.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use std::path::PathBuf;
use clap::{Args, Parser, ValueEnum, crate_version};
use crate::{
arch::Arch,
commands::{
execute_build_command, execute_debug_command, execute_forwarded_command,
execute_forwarded_command_on_each_crate, execute_new_command, execute_p... | osdk/src/cli.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
#[repr(i32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Errno {
Cli = 1,
CreateCrate = 2,
GetMetadata = 3,
AddRustToolchain = 4,
ParseMetadata = 5,
ExecuteCommand = 6,
BuildCrate = 7,
RunBundle = 8,
BadCrateName = 9,
NoKernelCrate =... | osdk/src/error.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use env_logger::Env;
#[macro_use]
extern crate log;
#[macro_use]
extern crate serde;
mod arch;
mod base_crate;
mod bundle;
mod cli;
mod commands;
mod config;
mod error;
mod util;
fn main() {
// init logger
let env = Env::new().filter("OSDK_LOG_LEVEL");
env_logger::ini... | osdk/src/main.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use std::{
collections::HashMap,
ffi::OsStr,
fs::{self, File},
io::{BufRead, BufReader, Result, Write},
os::unix::net::UnixStream,
path::{Path, PathBuf},
process::Command,
sync::{LazyLock, Mutex},
};
use crate::{error::Errno, error_msg};
use quote::... | osdk/src/util.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! The base crate is the OSDK generated crate that is ultimately built by cargo.
//! It will depend on the to-be-built kernel crate or the to-be-tested crate.
use std::{
fs,
io::{Read, Result},
path::{Path, PathBuf},
str::FromStr,
};
use crate::util::get_cargo_met... | osdk/src/base_crate/mod.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use std::{
os::unix::fs::MetadataExt,
path::{Path, PathBuf},
time::SystemTime,
};
use super::file::BundleFile;
use crate::{arch::Arch, util::hard_link_or_copy};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct AsterBin {
path: PathBuf,
... | osdk/src/bundle/bin.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use std::{
os::unix::fs::MetadataExt,
path::{Path, PathBuf},
time::SystemTime,
};
use crate::util::hard_link_or_copy;
/// A trait for files in a bundle. The file in a bundle should have its modified time and be validatable.
pub trait BundleFile {
fn path(&self) -> ... | osdk/src/bundle/file.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
pub mod bin;
pub mod file;
pub mod vm_image;
use bin::AsterBin;
use file::{BundleFile, Initramfs};
use std::{
io::{BufRead, BufReader, Write},
os::unix::net::UnixStream,
process,
time::Duration,
};
use tempfile::NamedTempFile;
use vm_image::{AsterVmImage, AsterVmIma... | osdk/src/bundle/mod.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use std::{
os::unix::fs::MetadataExt,
path::{Path, PathBuf},
time::SystemTime,
};
use crate::util::hard_link_or_copy;
use super::file::BundleFile;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct AsterVmImage {
path: PathBuf,
typ: Aste... | osdk/src/bundle/vm_image.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use crate::{
cli::DebugArgs,
commands::util::bin_file_name,
util::{get_kernel_crate, get_target_directory, new_command_checked_exists},
};
pub fn execute_debug_command(_profile: &str, args: &DebugArgs) {
let remote = &args.remote;
let file_path = get_target_dir... | osdk/src/commands/debug.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! This module contains subcommands of cargo-osdk.
mod build;
mod debug;
mod new;
mod profile;
mod run;
mod test;
mod util;
pub use self::{
build::execute_build_command, debug::execute_debug_command, new::execute_new_command,
profile::execute_profile_command, run::execute... | osdk/src/commands/mod.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! OSDK profile command implementation.
//!
//! The profile command is used to collect stack traces when running the target
//! kernel in QEMU. It attaches to the GDB server initiated with [`super::run`]
//! and collects the stack trace periodically. The collected data can be
//! f... | osdk/src/commands/profile.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use std::process::exit;
use vsc::VscLaunchConfig;
use super::{
build::create_base_and_cached_build,
util::{DEFAULT_TARGET_RELPATH, is_tdx_enabled},
};
use crate::{
config::{Config, scheme::ActionChoice},
error::Errno,
error_msg,
util::{get_kernel_crate, get... | osdk/src/commands/run.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use std::fs;
use super::{build::do_cached_build, util::DEFAULT_TARGET_RELPATH};
use crate::{
base_crate::{BaseCrateType, new_base_crate},
cli::TestArgs,
config::{Config, scheme::ActionChoice},
error::Errno,
error_msg,
util::{DirGuard, get_current_crates, get... | osdk/src/commands/test.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use std::process::Command;
use crate::util::{get_kernel_crate, new_command_checked_exists};
pub const COMMON_CARGO_ARGS: &[&str] = &[
"-Zbuild-std=core,alloc,compiler_builtins",
"-Zbuild-std-features=compiler-builtins-mem",
];
pub const DEFAULT_TARGET_RELPATH: &str = "osd... | osdk/src/commands/util.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use std::{
fs::{File, OpenOptions},
io::{Read, Seek, SeekFrom, Write},
path::{Path, PathBuf},
};
use linux_bzimage_builder::{
BzImageType, PayloadEncoding, encode_kernel, legacy32_rust_target_json, make_bzimage,
};
use crate::{
arch::Arch,
bundle::{
... | osdk/src/commands/build/bin.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use std::{
fs,
path::{Path, PathBuf},
};
use super::bin::make_install_bzimage;
use crate::{
bundle::{
bin::AsterBin,
file::BundleFile,
vm_image::{AsterGrubIsoImageMeta, AsterVmImage, AsterVmImageType},
},
config::{
Config,
... | osdk/src/commands/build/grub.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
mod bin;
mod grub;
mod qcow2;
use std::{
ffi::OsString,
path::{Path, PathBuf},
process,
time::SystemTime,
};
use bin::make_elf_for_qemu;
use super::util::{COMMON_CARGO_ARGS, DEFAULT_TARGET_RELPATH, cargo, profile_name_adapter};
use crate::{
arch::Arch,
bas... | osdk/src/commands/build/mod.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use std::process;
use crate::{
bundle::{
file::BundleFile,
vm_image::{AsterQcow2ImageMeta, AsterVmImage, AsterVmImageType},
},
error_msg,
util::new_command_checked_exists,
};
pub fn convert_iso_to_qcow2(iso: AsterVmImage) -> AsterVmImage {
let A... | osdk/src/commands/build/qcow2.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use std::{fs, path::PathBuf, process, str::FromStr};
use crate::{
cli::NewArgs,
config::manifest::ProjectType,
error::Errno,
error_msg,
util::{cargo_new_lib, get_cargo_metadata, ostd_dep},
};
pub fn execute_new_command(args: &NewArgs) {
cargo_new_lib(&args.... | osdk/src/commands/new/mod.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use std::{
collections::HashMap,
fmt, fs,
path::{Path, PathBuf},
process,
};
use clap::ValueEnum;
use serde::{Deserialize, Deserializer, Serialize, de};
use super::scheme::Scheme;
use crate::{error::Errno, error_msg, util::get_cargo_metadata};
#[expect(dead_code)... | osdk/src/config/manifest.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! This module is responsible for parsing configuration files and combining them with command-line parameters
//! to obtain the final configuration, it will also try searching system to fill valid values for specific
//! arguments if the arguments is missing, e.g., the path of QEMU... | osdk/src/config/mod.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! This module contains utilities for manipulating common Unix command-line arguments.
use std::process;
use indexmap::{IndexMap, IndexSet};
use crate::{error::Errno, error_msg};
/// Split a string of Unix arguments into an array of key-value strings or switches.
/// Positional... | osdk/src/config/unix_args.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use linux_bzimage_builder::PayloadEncoding;
use super::{Boot, BootScheme, Grub, GrubScheme, Qemu, QemuScheme, inherit_optional};
use crate::{cli::CommonArgs, config::Arch};
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum ActionChoice {
Run,
T... | osdk/src/config/scheme/action.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use clap::ValueEnum;
use std::path::PathBuf;
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct BootScheme {
/// Command line arguments for the guest kernel
#[serde(default)]
pub kcmd_args: Vec<String>,
/// Command line arguments for... | osdk/src/config/scheme/boot.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use clap::ValueEnum;
use std::path::PathBuf;
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct GrubScheme {
/// The path of `grub_mkrecue`. Only needed if `boot.method` is `grub`
pub grub_mkrescue: Option<PathBuf>,
/// The boot protocol... | osdk/src/config/scheme/grub.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use std::path::PathBuf;
use crate::arch::Arch;
mod action;
pub use action::*;
mod boot;
pub use boot::*;
mod grub;
pub use grub::*;
mod qemu;
pub use qemu::*;
/// All the configurable fields within a scheme.
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
... | osdk/src/config/scheme/mod.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! A module about QEMU settings and arguments.
use std::{path::PathBuf, process};
use crate::{
arch::{Arch, get_default_arch},
config::unix_args::{apply_kv_array, get_key, split_to_kv_array},
error::Errno,
error_msg,
};
#[derive(Debug, Default, Clone, PartialEq, ... | osdk/src/config/scheme/qemu.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use std::{
fs::{self, File},
path::PathBuf,
};
use super::*;
#[test]
fn deserialize_toml_manifest() {
let content = include_str!("OSDK.toml.full");
let toml_manifest: manifest::TomlManifest = toml::from_str(content).unwrap();
let type_ = toml_manifest.project_t... | osdk/src/config/test/mod.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! This module contains tests that invokes the `osdk` binary and checks the output.
//! Please be sure the the `osdk` binary is built and available in the `target/debug`
//! directory before running these tests.
mod cli;
mod commands;
mod examples_in_book;
mod util; | osdk/tests/integration.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use std::fs;
use crate::util::*;
#[test]
fn cli_help_message() {
let output = cargo_osdk(["-h"]).output().unwrap();
assert_success(&output);
assert_stdout_contains_msg(&output, "cargo osdk <COMMAND>");
}
#[test]
fn cli_new_help_message() {
let output = cargo_osdk(... | osdk/tests/cli/mod.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use std::{
fs::remove_dir_all,
path::{Path, PathBuf},
};
use crate::util::*;
const KERNEL_NAME: &str = "myos";
const LIB_NAME: &str = "my_module";
#[test]
fn create_kernel_in_workspace() {
const WORKSPACE_NAME: &str = "/tmp/kernel_workspace";
if Path::new(WORKSPAC... | osdk/tests/commands/new.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! Test the `run` command
use crate::util::is_tdx_enabled;
mod basic {
use std::path::PathBuf;
use tempfile::tempdir;
use crate::util::*;
#[test]
fn new_kernel_and_run() {
const KERNEL_NAME: &str = "myos";
// Use a per-test temporary direct... | osdk/tests/commands/run.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use std::{fs, path::PathBuf};
use crate::util::{cargo_osdk, depends_on_local_ostd};
#[test]
fn create_a_kernel_project() {
let workdir = "/tmp";
let kernel = "my_foo_os";
let kernel_path = PathBuf::from(workdir).join(kernel);
if kernel_path.exists() {
fs:... | osdk/tests/examples_in_book/create_os_projects.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! This module contains the demos in OSDK section in the Asterinas Book.
mod create_os_projects;
mod test_and_run_projects;
mod work_in_workspace;
mod write_a_kernel_in_100_lines; | osdk/tests/examples_in_book/mod.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use std::{fs, path::PathBuf};
use crate::util::{cargo_osdk, edit_config_files};
#[test]
fn create_and_run_kernel() {
let work_dir = "/tmp";
let os_name = "myos";
let os_dir = PathBuf::from(work_dir).join(os_name);
if os_dir.exists() {
fs::remove_dir_all(&... | osdk/tests/examples_in_book/test_and_run_projects.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use std::{
fs::{self, OpenOptions},
io::Write,
path::PathBuf,
};
use crate::util::{add_tdx_scheme, cargo_osdk, depends_on_local_ostd, is_tdx_enabled};
#[test]
fn work_in_workspace() {
let workdir = "/tmp";
let workspace_name = "myworkspace";
// Create work... | osdk/tests/examples_in_book/work_in_workspace.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use std::{fs, path::PathBuf, process::Command};
use assert_cmd::output::OutputOkExt;
use crate::util::{cargo_osdk, edit_config_files};
#[test]
fn write_a_kernel_in_100_lines() {
let workdir = "/tmp";
let os_name = "kernel_in_100_lines";
let os_dir = PathBuf::from(wor... | osdk/tests/examples_in_book/write_a_kernel_in_100_lines.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
pub fn available_memory() -> usize {
let regions = &ostd::boot::boot_info().memory_regions;
regions.iter().map(|region| region.len()).sum()
} | osdk/tests/examples_in_book/work_in_workspace_templates/mylib/src/lib.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
#![no_std]
#![deny(unsafe_code)]
use ostd::prelude::*;
#[ostd::main]
fn kernel_main() {
let avail_mem_as_mb = mylib::available_memory() / 1_000_000;
println!("The available memory is {} MB", avail_mem_as_mb);
} | osdk/tests/examples_in_book/work_in_workspace_templates/myos/src/lib.rs | null | null | null | null | null |
source | asterinas | # SPDX-License-Identifier: MPL-2.0
.global _start # entry point
.section .text # code section
_start:
mov $1, %rax # syscall number of write
mov $1, %rdi # stdout
mov $message, %rsi # address of message
... | osdk/tests/examples_in_book/write_a_kernel_in_100_lines_templates/hello.S | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
#![no_std]
#![deny(unsafe_code)]
extern crate alloc;
use align_ext::AlignExt;
use core::str;
use alloc::sync::Arc;
use alloc::vec;
use ostd::arch::cpu::context::UserContext;
use ostd::mm::{
CachePolicy, FallibleVmRead, FrameAllocOptions, PageFlags, PageProperty, Vaddr, VmIo,... | osdk/tests/examples_in_book/write_a_kernel_in_100_lines_templates/lib.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! The common utils for crate unit test
use std::{
ffi::OsStr,
fs::{self, OpenOptions, create_dir_all},
io::Write,
path::{Path, PathBuf},
process::Output,
};
use assert_cmd::Command;
use toml::{Table, Value};
pub fn cargo_osdk<T: AsRef<OsStr>, I: IntoIterator... | osdk/tests/util/mod.rs | null | null | null | null | null |
source | asterinas | # OSDK Development Docker Images
The OSDK development Docker images provide the development environment for using and developing OSDK.
## Building Docker Images
To build an OSDK development Docker image and test it on your local machine, navigate to the root directory of the Asterinas source code tree and execute th... | osdk/tools/docker/README.md | null | null | null | null | null |
source | asterinas | # Asterinas OSTD
Asterinas OSTD is a Rust OS framework that facilitates the development of and innovation in OS kernels written in Rust.
## An overview
Asterinas OSTD provides a solid foundation for Rust developers to build their own OS kernels. While Asterinas OSTD origins from Asterinas, the first ever framekernel... | ostd/README.md | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
#![cfg_attr(not(test), no_std)]
/// An extension trait for Rust integer types, including `u8`, `u16`, `u32`,
/// `u64`, and `usize`, to provide methods to make integers aligned to a
/// power of two.
pub trait AlignExt {
/// Returns to the smallest number that is greater than o... | ostd/libs/align_ext/src/lib.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
#![cfg_attr(not(test), no_std)]
#![deny(unsafe_code)]
use core::{fmt::Debug, ops::Range};
use bitvec::prelude::BitVec;
/// An id allocator implemented by the bitmap.
/// The true bit implies that the id is allocated, and vice versa.
#[derive(Clone)]
pub struct IdAlloc {
bitse... | ostd/libs/id-alloc/src/lib.rs | null | null | null | null | null |
source | asterinas | # TryFromInt - A convenient derive macro for converting an integer to an enum
## Quick Start
To use this crate, first add this crate to your `Cargo.toml`.
```toml
[dependencies]
int-to-c-enum = "0.1.0"
```
You can use this macro for a [C-like enum](https://doc.rust-lang.org/stable/rust-by-example/custom_types/enum/c... | ostd/libs/int-to-c-enum/README.md | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use proc_macro2::{Ident, TokenStream};
use quote::{TokenStreamExt, format_ident, quote};
use syn::{Attribute, Data, DataEnum, DeriveInput, Generics, parse_macro_input};
const ALLOWED_REPRS: &[&str] = &[
"u8", "i8", "u16", "i16", "u32", "i32", "u64", "i64", "usize", "isize",
];
... | ostd/libs/int-to-c-enum/derive/src/lib.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! This crate provides a derive macro named TryFromInt. This macro can be used to automatically implement TryFrom trait
//! for [C-like enums](https://doc.rust-lang.org/stable/rust-by-example/custom_types/enum/c_like.html).
//!
//! Currently, this macro only supports enums with [ex... | ostd/libs/int-to-c-enum/src/lib.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use int_to_c_enum::TryFromInt;
#[derive(TryFromInt, Debug, PartialEq, Eq)]
#[repr(u8)]
enum Color {
Red = 1,
Blue = 2,
Green = 3,
}
#[test]
fn conversion() {
let color = Color::try_from(1).unwrap();
println!("color = {color:?}");
assert!(color == Color::Red... | ostd/libs/int-to-c-enum/tests/regression.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! The definition of Linux Boot Protocol boot_params struct.
//!
//! The bootloader will deliver the address of the `BootParams` struct
//! as the argument of the kernel entrypoint. So we must define a Linux
//! ABI compatible struct in Rust, despite that most of the fields are
//!... | ostd/libs/linux-bzimage/boot-params/src/lib.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! This module is used to compress kernel ELF.
use std::{
ffi::{OsStr, OsString},
io::Write,
str::FromStr,
};
use libflate::{gzip, zlib};
use serde::{Deserialize, Serialize};
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum PayloadEnco... | ostd/libs/linux-bzimage/builder/src/encoder.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! The linux bzImage builder.
//!
//! This crate is responsible for building the bzImage. It contains methods to build
//! the setup binary (with source provided in another crate) and methods to build the
//! bzImage from the setup binary and the kernel ELF.
//!
//! We should build... | ostd/libs/linux-bzimage/builder/src/lib.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! In the setup, VA - SETUP32_LMA == FileOffset - LEGACY_SETUP_SEC_SIZE.
//! And the addresses are specified in the ELF file.
//!
//! This module centralizes the conversion between VA and FileOffset.
use std::{
cmp::PartialOrd,
convert::From,
ops::{Add, Sub},
};
// We... | ostd/libs/linux-bzimage/builder/src/mapping.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! Big zImage PE/COFF header generation.
//!
//! The definition of the PE/COFF header is in the Microsoft PE/COFF specification:
//! <https://learn.microsoft.com/en-us/windows/win32/debug/pe-format>
//!
//! The reference to the Linux PE header definition:
//! <https://github.com/to... | ostd/libs/linux-bzimage/builder/src/pe_header.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use std::{path::PathBuf, process::Command};
fn main() {
let source_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
let payload_file = PathBuf::from(std::env::var("PAYLOAD_FILE").unwrap())... | ostd/libs/linux-bzimage/setup/build.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! A serial console.
use core::fmt::{self, Write};
use uart_16550::SerialPort;
use crate::sync::Mutex;
struct Stdout {
serial_port: SerialPort,
}
impl Stdout {
fn new() -> Self {
// FIXME: Is it safe to assume that the serial port always exists?
let mut... | ostd/libs/linux-bzimage/setup/src/console.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use xmas_elf::program::{ProgramHeader, SegmentData};
/// Load the kernel ELF payload to memory.
pub fn load_elf(file: &[u8]) {
let elf = xmas_elf::ElfFile::new(file).unwrap();
for ph in elf.program_iter() {
let ProgramHeader::Ph64(program) = ph else {
p... | ostd/libs/linux-bzimage/setup/src/loader.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! The linux bzImage setup binary.
//!
//! With respect to the format of the bzImage, we design our bzImage setup in the similar
//! role as the setup code in the linux kernel. The setup code is responsible for
//! initializing the machine state, decompressing and loading the kerne... | ostd/libs/linux-bzimage/setup/src/main.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! Synchronization primitives.
use core::cell::{RefCell, RefMut};
/// A mutex.
pub struct Mutex<T>(RefCell<T>);
// SAFETY: We're single-threaded.
unsafe impl<T: Send> Send for Mutex<T> {}
unsafe impl<T: Sync> Sync for Mutex<T> {}
/// A mutex guard.
type MutexGuard<'a, T> = RefM... | ostd/libs/linux-bzimage/setup/src/sync.rs | null | null | null | null | null |
source | asterinas | /* SPDX-License-Identifier: MPL-2.0 */
// The compatibility file for the Linux x86 Boot Protocol.
// See https://www.kernel.org/doc/html/v5.6/x86/boot.html for
// more information on the Linux x86 Boot Protocol.
// The bootloader may fill some fields at runtime, which can
// be read by the kernel (via `boot_params.hd... | ostd/libs/linux-bzimage/setup/src/x86/header.S | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use core::arch::global_asm;
cfg_if::cfg_if! {
if #[cfg(target_arch = "x86_64")] {
mod amd64_efi;
pub use amd64_efi::alloc::alloc_at;
const CFG_TARGET_ARCH_X86_64: usize = 1;
} else if #[cfg(target_arch = "x86")] {
mod legacy_i386;
... | ostd/libs/linux-bzimage/setup/src/x86/mod.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use core::mem::MaybeUninit;
use uefi::boot::AllocateType;
pub fn alloc_at(addr: usize, size: usize) -> &'static mut [MaybeUninit<u8>] {
assert_ne!(addr, 0, "the address to allocate is zero");
assert!(
addr.checked_add(size).is_some(),
"the range to allocate... | ostd/libs/linux-bzimage/setup/src/x86/amd64_efi/alloc.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! This module is used to decompress payload.
extern crate alloc;
use alloc::vec::Vec;
use core::convert::TryFrom;
use core2::io::Read;
use libflate::{gzip, zlib};
enum MagicNumber {
Elf,
Gzip,
Zlib,
}
#[derive(Debug)]
struct InvalidMagicNumber;
impl TryFrom<&[u8]... | ostd/libs/linux-bzimage/setup/src/x86/amd64_efi/decoder.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use core::{ffi::CStr, mem::MaybeUninit};
use boot::{AllocateType, open_protocol_exclusive};
use linux_boot_params::BootParams;
use uefi::{boot::exit_boot_services, mem::memory_map::MemoryMap, prelude::*};
use uefi_raw::table::system::SystemTable;
use super::decoder::decode_payload... | ostd/libs/linux-bzimage/setup/src/x86/amd64_efi/efi.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
pub(super) mod alloc;
mod decoder;
mod efi;
use core::arch::{asm, global_asm};
use linux_boot_params::BootParams;
global_asm!(include_str!("setup.S"));
const ASTER_ENTRY_POINT: *const () = 0x8001200 as _;
unsafe fn call_aster_entrypoint(entrypoint: *const (), boot_params_ptr: *... | ostd/libs/linux-bzimage/setup/src/x86/amd64_efi/mod.rs | null | null | null | null | null |
source | asterinas | /* SPDX-License-Identifier: MPL-2.0 */
// The load address of the setup section is CODE32_START (0x100000).
// See the linker script.
.section ".setup", "ax", @progbits
CODE32_START = 0x100000
.code32
.global entry_legacy32
entry_legacy32:
// This is the 32-bit Linux legacy entry point.
// Not supported. How... | ostd/libs/linux-bzimage/setup/src/x86/amd64_efi/setup.S | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use core::{mem::MaybeUninit, ops::Range};
use crate::sync::Mutex;
const NUM_USED_RANGES: usize = 16;
struct State {
e820: &'static [linux_boot_params::BootE820Entry],
used: [Range<usize>; NUM_USED_RANGES],
}
static STATE: Mutex<Option<State>> = Mutex::new(None);
/// # S... | ostd/libs/linux-bzimage/setup/src/x86/legacy_i386/alloc.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use core::arch::{asm, global_asm};
use linux_boot_params::BootParams;
pub(super) mod alloc;
global_asm!(include_str!("setup.S"));
const ASTER_ENTRY_POINT: *const () = 0x8001000 as _;
/// SAFETY: The name does not collide with other symbols.
#[unsafe(export_name = "main_legacy32... | ostd/libs/linux-bzimage/setup/src/x86/legacy_i386/mod.rs | null | null | null | null | null |
source | asterinas | /* SPDX-License-Identifier: MPL-2.0 */
// The load address of the setup section is CODE32_START (0x100000).
// See the linker script.
.section ".setup", "ax", @progbits
.code32
.global entry_legacy32
entry_legacy32:
// This is the 32-bit Linux legacy entry point.
//
// Arguments:
// RSI: struct boot_... | ostd/libs/linux-bzimage/setup/src/x86/legacy_i386/setup.S | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
#![feature(proc_macro_diagnostic)]
#![feature(proc_macro_span)]
use proc_macro::{Diagnostic, Level, Span, TokenStream};
use quote::quote;
use rand::{Rng, distr::Alphanumeric};
use syn::{Expr, Ident, ItemFn, parse_macro_input};
/// A macro attribute to mark the kernel entry point.
... | ostd/libs/ostd-macros/src/lib.rs | null | null | null | null | null |
source | asterinas | <!--
To promote a "single source of truth", the content of `README.md` is also included in `lib.rs`
as the crate-level documentation. So when writing this README, bear in mind that its content
should be recognized correctly by both a Markdown renderer and the rustdoc tool.
-->
# ostd-pod
A trait and macros for Plain ... | ostd/libs/ostd-pod/README.md | null | null | null | null | null |
source | asterinas | <!--
To promote a "single source of truth", the content of `README.md` is also included in `lib.rs`
as the crate-level documentation. So when writing this README, bear in mind that its content
should be recognized correctly by both a Markdown renderer and the rustdoc tool.
-->
# ostd-pod-macros
Procedural macros for ... | ostd/libs/ostd-pod/macros/README.md | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
#![doc = include_str!("../README.md")]
use proc_macro::TokenStream;
mod pod_derive;
mod pod_union;
/// An attribute macro that replaces `#[derive(Pod)]` with the corresponding zerocopy traits.
#[proc_macro_attribute]
pub fn derive(attrs: TokenStream, input: TokenStream) -> TokenS... | ostd/libs/ostd-pod/macros/src/lib.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use proc_macro::TokenStream;
use quote::quote;
fn push_zerocopy_derive(
derives: &mut Vec<proc_macro2::TokenTree>,
ident: &str,
trailing_comma: bool,
) {
use proc_macro2::{Ident, Punct, Spacing, Span, TokenTree};
derives.push(TokenTree::Punct(Punct::new(':', Sp... | ostd/libs/ostd-pod/macros/src/pod_derive.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use proc_macro2::TokenStream as TokenStream2;
use quote::{ToTokens, quote};
use syn::{
Attribute, Data, DeriveInput, Ident, Path, Token, Visibility, parse_quote,
punctuated::Punctuated, spanned::Spanned,
};
const DERIVE_IDENT: &str = "derive";
const REPR_IDENT: &str = "repr... | ostd/libs/ostd-pod/macros/src/pod_union.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! Aligned array helpers for Pod types.
//!
//! This module provides type-level utilities
//! for creating arrays with specific alignment requirements.
//! It's primarily used internally to support Pod unions
//! that need to maintain precise memory layouts with guaranteed alignmen... | ostd/libs/ostd-pod/src/array_helper.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
#![doc = include_str!("../README.md")]
#![no_std]
#![deny(unsafe_code)]
pub use zerocopy::{FromBytes, FromZeros, Immutable, IntoBytes, KnownLayout};
pub mod array_helper;
/// A trait for plain old data (POD).
///
/// A POD type `T: Pod` can be safely converted to and from an arbi... | ostd/libs/ostd-pod/src/lib.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
#[macro_use]
extern crate ostd_pod;
use ostd_pod::{FromZeros, IntoBytes, Pod};
#[test]
fn pod_derive_simple() {
#[repr(C)]
#[derive(Pod, Debug, Clone, Copy, PartialEq)]
struct S1 {
a: u64,
b: [u8; 8],
}
let s = S1 {
a: 42,
b: [1,... | ostd/libs/ostd-pod/tests/derive_test.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use ostd_pod::{FromZeros, IntoBytes, Pod, pod_union};
#[test]
fn union_roundtrip_from_bytes() {
#[repr(C)]
#[pod_union]
#[derive(Copy, Clone)]
union U1 {
a: u32,
b: u64,
}
let bytes: [u8; 8] = [0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11]... | ostd/libs/ostd-pod/tests/union_test.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! # The kernel mode testing framework of OSTD.
//!
//! `ostd-test` stands for kernel-mode testing framework for OSTD. Its goal is to provide a
//! `cargo test`-like experience for any `#![no_std]` bare metal crates.
//!
//! In OSTD, all the tests written in the source tree of the ... | ostd/libs/ostd-test/src/lib.rs | null | null | null | null | null |
source | asterinas | <!--
To promote a "single source of truth", the content of `README.md` is also included in `lib.rs`
as the crate-level documentation. So when writing this README, bear in mind that its content
should be recognized correctly by both a Markdown renderer and the rustdoc tool.
-->
# padding-struct
A Rust procedural macro... | ostd/libs/padding-struct/README.md | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
#![doc = include_str!("../README.md")]
use proc_macro::TokenStream;
use quote::quote;
use syn::{
Attribute, Data, DataStruct, DeriveInput, Fields, Ident, Token, parse_macro_input,
punctuated::Punctuated, spanned::Spanned,
};
/// Checks if the struct has a `#[repr(C)]` attr... | ostd/libs/padding-struct/src/lib.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use core::mem::offset_of;
use padding_struct::padding_struct;
/// Test basic padding functionality
#[test]
fn basic_padding() {
#[repr(C)]
#[padding_struct]
struct TestStruct {
a: u8,
b: u32,
c: u16,
}
// Verify reference struct exists
... | ostd/libs/padding-struct/tests/integration_test.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! Bus probe error
// TODO: Implement a bus component and move the `BusProbeError` into the module.
/// An error that occurs during bus probing.
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum BusProbeError {
/// The device does not match the expected criteria.
... | ostd/src/bus.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! Support for the code coverage feature of OSDK.
//!
//! For more information about the code coverage feature (`cargo osdk run --coverage`),
//! check out the OSDK reference manual.
use alloc::vec::Vec;
use core::mem::ManuallyDrop;
use spin::Once;
use crate::sync::SpinLock;
//... | ostd/src/coverage.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use crate::mm::page_table::PageTableError;
/// The error type which is returned from the APIs of this crate.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum Error {
/// Invalid arguments provided.
InvalidArgs,
/// Insufficient memory available.
NoMemory,
/... | ostd/src/error.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
use crate::prelude::Vaddr;
#[repr(C)]
struct ExTableItem {
inst_addr: Vaddr,
recovery_inst_addr: Vaddr,
}
unsafe extern "C" {
fn __ex_table();
fn __ex_table_end();
}
/// A structure representing the usage of exception table (ExTable).
/// This table is used for re... | ostd/src/ex_table.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! The standard library for Asterinas and other Rust OSes.
#![feature(alloc_error_handler)]
#![feature(allocator_api)]
#![feature(btree_cursors)]
#![feature(core_intrinsics)]
#![feature(iter_advance_by)]
#![feature(linkage)]
#![feature(macro_metavar_expr)]
#![feature(min_specializ... | ostd/src/lib.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! Logger injection.
//!
//! OSTD allows its client to inject a custom implementation of logger.
//! If no such logger is injected,
//! then OSTD falls back to a built-in logger that
//! simply dumps all log records with [`crate::console::early_print`].
//!
//! OSTD's logger facili... | ostd/src/logger.rs | null | null | null | null | null |
source | asterinas | // SPDX-License-Identifier: MPL-2.0
//! Panic support.
use crate::early_println;
extern crate cfg_if;
extern crate gimli;
/// The default panic handler for OSTD based kernels.
///
/// The user can override it by defining their own panic handler with the macro
/// `#[ostd::panic_handler]`.
#[linkage = "weak"]
// SAF... | ostd/src/panic.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.