From ee0d7a3fed08e9db7e692a71a3633346aedbb28e Mon Sep 17 00:00:00 2001 From: Yuekai Jia Date: Tue, 30 Jul 2024 18:24:33 +0800 Subject: [PATCH 1/2] [hal] Refactor trap handler with `linkme::distributed_slice` It allows trap handlers to be defined in any crate --- Cargo.lock | 21 ++++++ modules/axhal/Cargo.toml | 1 + modules/axhal/linker.lds.S | 17 +++-- modules/axhal/src/arch/aarch64/trap.rs | 97 ++++++++++++++++++-------- modules/axhal/src/arch/riscv/trap.rs | 31 +++++++- modules/axhal/src/arch/x86_64/trap.rs | 84 ++++++++++++++++------ modules/axhal/src/irq.rs | 13 +++- modules/axhal/src/lib.rs | 4 +- modules/axhal/src/trap.rs | 44 +++++++----- modules/axruntime/src/lib.rs | 1 - modules/axruntime/src/trap.rs | 13 ---- scripts/make/build_c.mk | 2 +- scripts/make/cargo.mk | 2 +- 13 files changed, 234 insertions(+), 96 deletions(-) delete mode 100644 modules/axruntime/src/trap.rs diff --git a/Cargo.lock b/Cargo.lock index b97000cf43..ef538ea6a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -359,6 +359,7 @@ dependencies = [ "kernel_guard", "kspin", "lazyinit", + "linkme", "log", "memory_addr", "page_table_entry", @@ -949,6 +950,26 @@ name = "linked_list" version = "0.1.0" source = "git+https://github.com/arceos-org/linked_list.git?tag=v0.1.0#34c8db301882cecfeb56df0f7c89978dbc62f49a" +[[package]] +name = "linkme" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccb76662d78edc9f9bf56360d6919bdacc8b7761227727e5082f128eeb90bbf5" +dependencies = [ + "linkme-impl", +] + +[[package]] +name = "linkme-impl" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dccda732e04fa3baf2e17cf835bfe2601c7c2edafd64417c627dabae3a8cda" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.70", +] + [[package]] name = "lock_api" version = "0.4.10" diff --git a/modules/axhal/Cargo.toml b/modules/axhal/Cargo.toml index 4680b79fbd..94256710f8 100644 --- a/modules/axhal/Cargo.toml +++ b/modules/axhal/Cargo.toml @@ -22,6 +22,7 @@ default = [] [dependencies] log = "0.4" cfg-if = "1.0" +linkme = "0.3" bitflags = "2.6" static_assertions = "1.1.0" kernel_guard = "0.1" diff --git a/modules/axhal/linker.lds.S b/modules/axhal/linker.lds.S index 73b7a7884d..2ec5f00a62 100644 --- a/modules/axhal/linker.lds.S +++ b/modules/axhal/linker.lds.S @@ -49,17 +49,14 @@ SECTIONS . = ALIGN(4K); _percpu_start = .; + _percpu_end = _percpu_start + SIZEOF(.percpu); .percpu 0x0 : AT(_percpu_start) { _percpu_load_start = .; *(.percpu .percpu.*) _percpu_load_end = .; - . = ALIGN(64); - _percpu_size_aligned = .; - - . = _percpu_load_start + _percpu_size_aligned * %SMP%; + . = _percpu_load_start + ALIGN(64) * %SMP%; } - . = _percpu_start + SIZEOF(.percpu); - _percpu_end = .; + . = _percpu_end; . = ALIGN(4K); _edata = .; @@ -84,3 +81,11 @@ SECTIONS *(.comment) *(.gnu*) *(.note*) *(.eh_frame*) } } + +SECTIONS { + linkme_IRQ : { *(linkme_IRQ) } + linkm2_IRQ : { *(linkm2_IRQ) } + linkme_PAGE_FAULT : { *(linkme_PAGE_FAULT) } + linkm2_PAGE_FAULT : { *(linkm2_PAGE_FAULT) } +} +INSERT AFTER .tbss; diff --git a/modules/axhal/src/arch/aarch64/trap.rs b/modules/axhal/src/arch/aarch64/trap.rs index 00afbe985c..c95d429845 100644 --- a/modules/axhal/src/arch/aarch64/trap.rs +++ b/modules/axhal/src/arch/aarch64/trap.rs @@ -1,6 +1,8 @@ use core::arch::global_asm; use aarch64_cpu::registers::{ESR_EL1, FAR_EL1}; +use memory_addr::VirtAddr; +use page_table_entry::MappingFlags; use tock_registers::interfaces::Readable; use super::TrapFrame; @@ -35,39 +37,79 @@ fn invalid_exception(tf: &TrapFrame, kind: TrapKind, source: TrapSource) { ); } +#[no_mangle] +fn handle_irq_exception(_tf: &TrapFrame) { + handle_trap!(IRQ, 0); +} + +fn handle_instruction_abort(tf: &TrapFrame, iss: u64, is_user: bool) { + let mut access_flags = MappingFlags::EXECUTE; + if is_user { + access_flags |= MappingFlags::USER; + } + let vaddr = VirtAddr::from(FAR_EL1.get() as usize); + + // Only handle Translation fault and Permission fault + if !matches!(iss & 0b111100, 0b0100 | 0b1100) // IFSC or DFSC bits + || !handle_trap!(PAGE_FAULT, vaddr, access_flags, is_user) + { + panic!( + "Unhandled {} Instruction Abort @ {:#x}, fault_vaddr={:#x}, ISS={:#x} ({:?}):\n{:#x?}", + if is_user { "EL0" } else { "EL1" }, + tf.elr, + vaddr, + iss, + access_flags, + tf, + ); + } +} + +fn handle_data_abort(tf: &TrapFrame, iss: u64, is_user: bool) { + let wnr = (iss & (1 << 6)) != 0; // WnR: Write not Read + let cm = (iss & (1 << 8)) != 0; // CM: Cache maintenance + let mut access_flags = if wnr & !cm { + MappingFlags::WRITE + } else { + MappingFlags::READ + }; + if is_user { + access_flags |= MappingFlags::USER; + } + let vaddr = VirtAddr::from(FAR_EL1.get() as usize); + + // Only handle Translation fault and Permission fault + if !matches!(iss & 0b111100, 0b0100 | 0b1100) // IFSC or DFSC bits + || !handle_trap!(PAGE_FAULT, vaddr, access_flags, is_user) + { + panic!( + "Unhandled {} Data Abort @ {:#x}, fault_vaddr={:#x}, ISS=0b{:08b} ({:?}):\n{:#x?}", + if is_user { "EL0" } else { "EL1" }, + tf.elr, + vaddr, + iss, + access_flags, + tf, + ); + } +} + #[no_mangle] fn handle_sync_exception(tf: &mut TrapFrame) { let esr = ESR_EL1.extract(); + let iss = esr.read(ESR_EL1::ISS); match esr.read_as_enum(ESR_EL1::EC) { + Some(ESR_EL1::EC::Value::SVC64) => { + warn!("No syscall is supported currently!"); + } + Some(ESR_EL1::EC::Value::InstrAbortLowerEL) => handle_instruction_abort(tf, iss, true), + Some(ESR_EL1::EC::Value::InstrAbortCurrentEL) => handle_instruction_abort(tf, iss, false), + Some(ESR_EL1::EC::Value::DataAbortLowerEL) => handle_data_abort(tf, iss, true), + Some(ESR_EL1::EC::Value::DataAbortCurrentEL) => handle_data_abort(tf, iss, false), Some(ESR_EL1::EC::Value::Brk64) => { - let iss = esr.read(ESR_EL1::ISS); debug!("BRK #{:#x} @ {:#x} ", iss, tf.elr); tf.elr += 4; } - Some(ESR_EL1::EC::Value::SVC64) => { - warn!("No supervisor call is supported currently!"); - } - Some(ESR_EL1::EC::Value::DataAbortLowerEL) - | Some(ESR_EL1::EC::Value::InstrAbortLowerEL) => { - let iss = esr.read(ESR_EL1::ISS); - warn!( - "EL0 Page Fault @ {:#x}, FAR={:#x}, ISS={:#x}", - tf.elr, - FAR_EL1.get(), - iss - ); - } - Some(ESR_EL1::EC::Value::DataAbortCurrentEL) - | Some(ESR_EL1::EC::Value::InstrAbortCurrentEL) => { - let iss = esr.read(ESR_EL1::ISS); - panic!( - "EL1 Page Fault @ {:#x}, FAR={:#x}, ISS={:#x}:\n{:#x?}", - tf.elr, - FAR_EL1.get(), - iss, - tf, - ); - } _ => { panic!( "Unhandled synchronous exception @ {:#x}: ESR={:#x} (EC {:#08b}, ISS {:#x})", @@ -79,8 +121,3 @@ fn handle_sync_exception(tf: &mut TrapFrame) { } } } - -#[no_mangle] -fn handle_irq_exception(_tf: &TrapFrame) { - crate::trap::handle_irq_extern(0) -} diff --git a/modules/axhal/src/arch/riscv/trap.rs b/modules/axhal/src/arch/riscv/trap.rs index 7624f25583..0e2b406bb6 100644 --- a/modules/axhal/src/arch/riscv/trap.rs +++ b/modules/axhal/src/arch/riscv/trap.rs @@ -1,4 +1,7 @@ +use memory_addr::VirtAddr; +use page_table_entry::MappingFlags; use riscv::register::scause::{self, Exception as E, Trap}; +use riscv::register::stval; use super::TrapFrame; @@ -14,12 +17,36 @@ fn handle_breakpoint(sepc: &mut usize) { *sepc += 2 } +fn handle_page_fault(tf: &TrapFrame, mut access_flags: MappingFlags, is_user: bool) { + if is_user { + access_flags |= MappingFlags::USER; + } + let vaddr = VirtAddr::from(stval::read()); + if !handle_trap!(PAGE_FAULT, vaddr, access_flags, is_user) { + panic!( + "Unhandled {} Page Fault @ {:#x}, fault_vaddr={:#x} ({:?}):\n{:#x?}", + if is_user { "User" } else { "Supervisor" }, + tf.sepc, + vaddr, + access_flags, + tf, + ); + } +} + #[no_mangle] -fn riscv_trap_handler(tf: &mut TrapFrame, _from_user: bool) { +fn riscv_trap_handler(tf: &mut TrapFrame, from_user: bool) { let scause = scause::read(); match scause.cause() { + Trap::Exception(E::LoadPageFault) => handle_page_fault(tf, MappingFlags::READ, from_user), + Trap::Exception(E::StorePageFault) => handle_page_fault(tf, MappingFlags::WRITE, from_user), + Trap::Exception(E::InstructionPageFault) => { + handle_page_fault(tf, MappingFlags::EXECUTE, from_user) + } Trap::Exception(E::Breakpoint) => handle_breakpoint(&mut tf.sepc), - Trap::Interrupt(_) => crate::trap::handle_irq_extern(scause.bits()), + Trap::Interrupt(_) => { + handle_trap!(IRQ, scause.bits()); + } _ => { panic!( "Unhandled trap {:?} @ {:#x}:\n{:#x?}", diff --git a/modules/axhal/src/arch/x86_64/trap.rs b/modules/axhal/src/arch/x86_64/trap.rs index 0f379f14b5..4d5295d62f 100644 --- a/modules/axhal/src/arch/x86_64/trap.rs +++ b/modules/axhal/src/arch/x86_64/trap.rs @@ -1,4 +1,7 @@ +use memory_addr::VirtAddr; +use page_table_entry::MappingFlags; use x86::{controlregs::cr2, irq::*}; +use x86_64::structures::idt::PageFaultErrorCode; use super::context::TrapFrame; @@ -7,27 +10,27 @@ core::arch::global_asm!(include_str!("trap.S")); const IRQ_VECTOR_START: u8 = 0x20; const IRQ_VECTOR_END: u8 = 0xff; +fn handle_page_fault(tf: &TrapFrame) { + let access_flags = err_code_to_flags(tf.error_code) + .unwrap_or_else(|e| panic!("Invalid #PF error code: {:#x}", e)); + let vaddr = VirtAddr::from(unsafe { cr2() }); + if !handle_trap!(PAGE_FAULT, vaddr, access_flags, tf.is_user()) { + panic!( + "Unhandled {} #PF @ {:#x}, fault_vaddr={:#x}, error_code={:#x} ({:?}):\n{:#x?}", + if tf.is_user() { "user" } else { "kernel" }, + tf.rip, + vaddr, + tf.error_code, + access_flags, + tf, + ); + } +} + #[no_mangle] fn x86_trap_handler(tf: &TrapFrame) { match tf.vector as u8 { - PAGE_FAULT_VECTOR => { - if tf.is_user() { - warn!( - "User #PF @ {:#x}, fault_vaddr={:#x}, error_code={:#x}", - tf.rip, - unsafe { cr2() }, - tf.error_code, - ); - } else { - panic!( - "Kernel #PF @ {:#x}, fault_vaddr={:#x}, error_code={:#x}:\n{:#x?}", - tf.rip, - unsafe { cr2() }, - tf.error_code, - tf, - ); - } - } + PAGE_FAULT_VECTOR => handle_page_fault(tf), BREAKPOINT_VECTOR => debug!("#BP @ {:#x} ", tf.rip), GENERAL_PROTECTION_FAULT_VECTOR => { panic!( @@ -35,12 +38,51 @@ fn x86_trap_handler(tf: &TrapFrame) { tf.rip, tf.error_code, tf ); } - IRQ_VECTOR_START..=IRQ_VECTOR_END => crate::trap::handle_irq_extern(tf.vector as _), + IRQ_VECTOR_START..=IRQ_VECTOR_END => { + handle_trap!(IRQ, tf.vector as _); + } _ => { panic!( - "Unhandled exception {} (error_code = {:#x}) @ {:#x}:\n{:#x?}", - tf.vector, tf.error_code, tf.rip, tf + "Unhandled exception {} ({}, error_code={:#x}) @ {:#x}:\n{:#x?}", + tf.vector, + vec_to_str(tf.vector), + tf.error_code, + tf.rip, + tf ); } } } + +fn vec_to_str(vec: u64) -> &'static str { + if vec < 32 { + EXCEPTIONS[vec as usize].mnemonic + } else { + "Unknown" + } +} + +fn err_code_to_flags(err_code: u64) -> Result { + let code = PageFaultErrorCode::from_bits_truncate(err_code); + let reserved_bits = (PageFaultErrorCode::CAUSED_BY_WRITE + | PageFaultErrorCode::USER_MODE + | PageFaultErrorCode::INSTRUCTION_FETCH) + .complement(); + if code.intersects(reserved_bits) { + Err(err_code) + } else { + let mut flags = MappingFlags::empty(); + if code.contains(PageFaultErrorCode::CAUSED_BY_WRITE) { + flags |= MappingFlags::WRITE; + } else { + flags |= MappingFlags::READ; + } + if code.contains(PageFaultErrorCode::USER_MODE) { + flags |= MappingFlags::USER; + } + if code.contains(PageFaultErrorCode::INSTRUCTION_FETCH) { + flags |= MappingFlags::EXECUTE; + } + Ok(flags) + } +} diff --git a/modules/axhal/src/irq.rs b/modules/axhal/src/irq.rs index 46160d40f1..5ba84661f6 100644 --- a/modules/axhal/src/irq.rs +++ b/modules/axhal/src/irq.rs @@ -2,9 +2,10 @@ use handler_table::HandlerTable; -use crate::platform::irq::MAX_IRQ_COUNT; +use crate::platform::irq::{dispatch_irq, MAX_IRQ_COUNT}; +use crate::trap::{reg_trap_handler, IRQ}; -pub use crate::platform::irq::{dispatch_irq, register_handler, set_enable}; +pub use crate::platform::irq::{register_handler, set_enable}; /// The type if an IRQ handler. pub type IrqHandler = handler_table::Handler; @@ -33,3 +34,11 @@ pub(crate) fn register_handler_common(irq_num: usize, handler: IrqHandler) -> bo warn!("register handler for IRQ {} failed", irq_num); false } + +#[reg_trap_handler(IRQ)] +fn handler_irq(irq_num: usize) -> bool { + let guard = kernel_guard::NoPreempt::new(); + dispatch_irq(irq_num); + drop(guard); // rescheduling may occur when preemption is re-enabled. + true +} diff --git a/modules/axhal/src/lib.rs b/modules/axhal/src/lib.rs index 076a65c253..cdfdad6776 100644 --- a/modules/axhal/src/lib.rs +++ b/modules/axhal/src/lib.rs @@ -36,11 +36,13 @@ extern crate log; mod platform; +#[macro_use] +pub mod trap; + pub mod arch; pub mod cpu; pub mod mem; pub mod time; -pub mod trap; #[cfg(feature = "tls")] pub mod tls; diff --git a/modules/axhal/src/trap.rs b/modules/axhal/src/trap.rs index 5fc9f76dcc..df23d1e64e 100644 --- a/modules/axhal/src/trap.rs +++ b/modules/axhal/src/trap.rs @@ -1,23 +1,31 @@ //! Trap handling. -use crate_interface::{call_interface, def_interface}; +use linkme::distributed_slice as def_trap_handler; +use memory_addr::VirtAddr; +use page_table_entry::MappingFlags; -/// Trap handler interface. -/// -/// This trait is defined with the [`#[def_interface]`][1] attribute. Users -/// should implement it with [`#[impl_interface]`][2] in any other crate. -/// -/// [1]: crate_interface::def_interface -/// [2]: crate_interface::impl_interface -#[def_interface] -pub trait TrapHandler { - /// Handles interrupt requests for the given IRQ number. - fn handle_irq(irq_num: usize); - // more e.g.: handle_page_fault(); -} +pub use linkme::distributed_slice as reg_trap_handler; + +/// A slice of IRQ handler functions. +#[def_trap_handler] +pub static IRQ: [fn(usize) -> bool]; + +/// A slice of page fault handler functions. +#[def_trap_handler] +pub static PAGE_FAULT: [fn(VirtAddr, MappingFlags, bool) -> bool]; -/// Call the external IRQ handler. -#[allow(dead_code)] -pub(crate) fn handle_irq_extern(irq_num: usize) { - call_interface!(TrapHandler::handle_irq, irq_num); +#[allow(unused_macros)] +macro_rules! handle_trap { + ($trap:ident, $($args:tt)*) => {{ + let mut iter = $crate::trap::$trap.iter(); + if let Some(func) = iter.next() { + if iter.next().is_some() { + warn!("Multiple handlers for trap {} are not currently supported", stringify!($trap)); + } + func($($args)*) + } else { + warn!("No registered handler for trap {}", stringify!($trap)); + false + } + }} } diff --git a/modules/axruntime/src/lib.rs b/modules/axruntime/src/lib.rs index 71bc673dda..8207ea1cab 100644 --- a/modules/axruntime/src/lib.rs +++ b/modules/axruntime/src/lib.rs @@ -24,7 +24,6 @@ extern crate axlog; #[cfg(all(target_os = "none", not(test)))] mod lang_items; -mod trap; #[cfg(feature = "smp")] mod mp; diff --git a/modules/axruntime/src/trap.rs b/modules/axruntime/src/trap.rs deleted file mode 100644 index 5a8a80d384..0000000000 --- a/modules/axruntime/src/trap.rs +++ /dev/null @@ -1,13 +0,0 @@ -struct TrapHandlerImpl; - -#[crate_interface::impl_interface] -impl axhal::trap::TrapHandler for TrapHandlerImpl { - fn handle_irq(_irq_num: usize) { - #[cfg(feature = "irq")] - { - let guard = kernel_guard::NoPreempt::new(); - axhal::irq::dispatch_irq(_irq_num); - drop(guard); // rescheduling may occur when preemption is re-enabled. - } - } -} diff --git a/scripts/make/build_c.mk b/scripts/make/build_c.mk index 1c989bf766..76064b502b 100644 --- a/scripts/make/build_c.mk +++ b/scripts/make/build_c.mk @@ -19,7 +19,7 @@ CFLAGS += -DAX_LOG_$(shell echo $(LOG) | tr 'a-z' 'A-Z') CFLAGS += -nostdinc -fno-builtin -ffreestanding -Wall CFLAGS += -I$(CURDIR)/$(inc_dir) -LDFLAGS += -nostdlib -static -no-pie --gc-sections -T$(LD_SCRIPT) +LDFLAGS += -nostdlib -static -no-pie --gc-sections -znostart-stop-gc -T$(LD_SCRIPT) ifeq ($(MODE), release) CFLAGS += -O3 diff --git a/scripts/make/cargo.mk b/scripts/make/cargo.mk index 4367aea1a9..bda44e2de4 100644 --- a/scripts/make/cargo.mk +++ b/scripts/make/cargo.mk @@ -17,7 +17,7 @@ build_args := \ $(build_args-$(MODE)) \ $(verbose) -RUSTFLAGS := -C link-arg=-T$(LD_SCRIPT) -C link-arg=-no-pie +RUSTFLAGS := -C link-arg=-T$(LD_SCRIPT) -C link-arg=-no-pie -C link-arg=-znostart-stop-gc RUSTDOCFLAGS := -Z unstable-options --enable-index-page -D rustdoc::broken_intra_doc_links ifeq ($(MAKECMDGOALS), doc_check_missing) From 1f97a03b4d302499e91eea5537e30bdd8891d125 Mon Sep 17 00:00:00 2001 From: Yuekai Jia Date: Tue, 30 Jul 2024 21:42:19 +0800 Subject: [PATCH 2/2] [api] Re-export ArceOS modules in arceos_api, update app test --- .github/workflows/test.yml | 2 +- Cargo.lock | 4 +++- api/arceos_api/Cargo.toml | 12 ++++++++---- api/arceos_api/src/lib.rs | 28 +++++++++++++++++++++++++++- modules/axhal/Cargo.toml | 1 - modules/axhal/src/irq.rs | 4 ++-- modules/axhal/src/trap.rs | 2 +- ulib/axstd/src/os.rs | 2 ++ 8 files changed, 44 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index baae1f9d86..6cc4d61536 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,7 +5,7 @@ on: [push, pull_request] env: qemu-version: 8.2.0 rust-toolchain: nightly-2024-05-02 - arceos-apps: b36b9d5 + arceos-apps: c01cd92 jobs: unit-test: diff --git a/Cargo.lock b/Cargo.lock index ef538ea6a9..f37a7859cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -84,14 +84,17 @@ dependencies = [ "axalloc", "axconfig", "axdisplay", + "axdriver", "axerrno", "axfeat", "axfs", "axhal", "axio", "axlog", + "axmm", "axnet", "axruntime", + "axsync", "axtask", ] @@ -352,7 +355,6 @@ dependencies = [ "axlog", "bitflags 2.6.0", "cfg-if", - "crate_interface", "dw_apb_uart", "handler_table", "int_ratio", diff --git a/api/arceos_api/Cargo.toml b/api/arceos_api/Cargo.toml index 979e3f6691..85ae095308 100644 --- a/api/arceos_api/Cargo.toml +++ b/api/arceos_api/Cargo.toml @@ -14,10 +14,11 @@ default = [] irq = ["axfeat/irq"] alloc = ["dep:axalloc", "axfeat/alloc"] -multitask = ["axtask/multitask", "axfeat/multitask"] -fs = ["dep:axfs", "axfeat/fs"] -net = ["dep:axnet", "axfeat/net"] -display = ["dep:axdisplay", "axfeat/display"] +paging = ["dep:axmm", "axfeat/paging"] +multitask = ["axtask/multitask", "axsync/multitask", "axfeat/multitask"] +fs = ["dep:axfs", "dep:axdriver", "axfeat/fs"] +net = ["dep:axnet", "dep:axdriver", "axfeat/net"] +display = ["dep:axdisplay", "dep:axdriver", "axfeat/display"] myfs = ["axfeat/myfs"] @@ -32,8 +33,11 @@ axruntime = { workspace = true } axconfig = { workspace = true } axlog = { workspace = true } axhal = { workspace = true } +axsync = { workspace = true } axalloc = { workspace = true, optional = true } +axmm = { workspace = true, optional = true } axtask = { workspace = true, optional = true } +axdriver = { workspace = true, optional = true } axfs = { workspace = true, optional = true } axnet = { workspace = true, optional = true } axdisplay = { workspace = true, optional = true } diff --git a/api/arceos_api/src/lib.rs b/api/arceos_api/src/lib.rs index cb15564930..a9ed39eef8 100644 --- a/api/arceos_api/src/lib.rs +++ b/api/arceos_api/src/lib.rs @@ -15,7 +15,6 @@ feature = "dummy-if-not-enabled" ))] extern crate alloc; -extern crate axruntime; #[macro_use] mod macros; @@ -339,3 +338,30 @@ pub mod io { pub type AxPollState; } } + +/// Re-exports of ArceOS modules. +/// +/// You should prefer to use other APIs rather than these modules. The modules +/// here should only be used if other APIs do not meet your requirements. +pub mod modules { + pub use axconfig; + pub use axhal; + pub use axlog; + pub use axruntime; + pub use axsync; + + #[cfg(feature = "alloc")] + pub use axalloc; + #[cfg(feature = "display")] + pub use axdisplay; + #[cfg(any(feature = "fs", feature = "net", feature = "display"))] + pub use axdriver; + #[cfg(feature = "fs")] + pub use axfs; + #[cfg(feature = "paging")] + pub use axmm; + #[cfg(feature = "net")] + pub use axnet; + #[cfg(feature = "multitask")] + pub use axtask; +} diff --git a/modules/axhal/Cargo.toml b/modules/axhal/Cargo.toml index 94256710f8..d58b8e7b3d 100644 --- a/modules/axhal/Cargo.toml +++ b/modules/axhal/Cargo.toml @@ -32,7 +32,6 @@ lazyinit = "0.2" percpu = "0.1" memory_addr = "0.2" handler_table = "0.1" -crate_interface = "0.1" page_table_entry = "0.3" page_table_multiarch = { version = "0.3", optional = true } axlog = { workspace = true } diff --git a/modules/axhal/src/irq.rs b/modules/axhal/src/irq.rs index 5ba84661f6..fdaa788462 100644 --- a/modules/axhal/src/irq.rs +++ b/modules/axhal/src/irq.rs @@ -3,7 +3,7 @@ use handler_table::HandlerTable; use crate::platform::irq::{dispatch_irq, MAX_IRQ_COUNT}; -use crate::trap::{reg_trap_handler, IRQ}; +use crate::trap::{register_trap_handler, IRQ}; pub use crate::platform::irq::{register_handler, set_enable}; @@ -35,7 +35,7 @@ pub(crate) fn register_handler_common(irq_num: usize, handler: IrqHandler) -> bo false } -#[reg_trap_handler(IRQ)] +#[register_trap_handler(IRQ)] fn handler_irq(irq_num: usize) -> bool { let guard = kernel_guard::NoPreempt::new(); dispatch_irq(irq_num); diff --git a/modules/axhal/src/trap.rs b/modules/axhal/src/trap.rs index df23d1e64e..fcf9074d96 100644 --- a/modules/axhal/src/trap.rs +++ b/modules/axhal/src/trap.rs @@ -4,7 +4,7 @@ use linkme::distributed_slice as def_trap_handler; use memory_addr::VirtAddr; use page_table_entry::MappingFlags; -pub use linkme::distributed_slice as reg_trap_handler; +pub use linkme::distributed_slice as register_trap_handler; /// A slice of IRQ handler functions. #[def_trap_handler] diff --git a/ulib/axstd/src/os.rs b/ulib/axstd/src/os.rs index d1bdf8258e..4ea01aeb00 100644 --- a/ulib/axstd/src/os.rs +++ b/ulib/axstd/src/os.rs @@ -3,4 +3,6 @@ /// ArceOS-specific definitions. pub mod arceos { pub use arceos_api as api; + #[doc(no_inline)] + pub use arceos_api::modules; }