Skip to content

feat: ETL migration, MPMC logging, device framework overhaul, VFS/FatFS, and coding standards#193

Merged
MRNIU merged 3891 commits intoSimple-XX:mainfrom
MRNIU:main
Mar 18, 2026
Merged

feat: ETL migration, MPMC logging, device framework overhaul, VFS/FatFS, and coding standards#193
MRNIU merged 3891 commits intoSimple-XX:mainfrom
MRNIU:main

Conversation

@MRNIU
Copy link
Copy Markdown
Member

@MRNIU MRNIU commented Mar 18, 2026

Summary

Major refactoring and feature additions over the past month, focusing on replacing custom kernel infrastructure with the Embedded Template Library (ETL), rewriting the logging subsystem, overhauling the device framework, and adding a VFS/FatFS filesystem layer.

310 files changed, +19,521 / -12,892


Key Changes

1. ETL (Embedded Template Library) Integration

Full migration from custom sk_std containers and utilities to ETL, a production-grade embedded C++ library:

  • Containers: Replaced sk_std::static_list, sk_std::vector, sk_std::priority_queue with etl::list, etl::vector, etl::priority_queue, etl::flat_map
  • I/O Ports: Migrated io::In/Out to etl::io_port_ro/rw across APIC, GIC, and VirtIO
  • Singletons: Singleton<T>etl::singleton<T> with named aliases in kernel.h
  • Delegates: InterruptFunc pointer → etl::delegate for type-safe interrupt callbacks
  • Task FSM: TaskStatus enum → etl::fsm state machine with well-defined transitions
  • Flags: CloneFlags enum → etl::flags for type-safe bitmask operations
  • Observers: Added etl::observer-based tick and panic interfaces
  • Messages: Added etl::message_router ID registry for lifecycle and VirtIO events
  • Smart Pointers: Added sk_std::unique_ptr (with array specialization) and sk_std::shared_ptr (with atomic reference counting)
  • Removed unused sk_std implementations and their tests

2. Kernel Logging Rewrite (MPMC Lock-Free)

Complete rewrite of kernel_log.hpp:

  • MPMC queue: Lock-free multi-producer multi-consumer log queue, safe for SMP use
  • ETL format syntax: Type-safe {} placeholders replacing printf-style %d/%s
  • Per-CPU raw interfaces: klog::raw_err / LogLineRaw / LogStreamRaw for use in contexts where locking is unsafe (e.g., DumpStack)
  • Core ID in logs: Log output now includes the originating CPU core ID
  • Removed nanoprintf: Replaced entirely with ETL's print/format facilities; added etl_putchar shims for all three architectures

3. Device Framework Overhaul

Eliminated the device_framework submodule and inlined all driver code:

  • Inlined from device_framework: NS16550A, PL011, VirtIO (transport, virt_queue, device, defs), ACPI, MMIO accessor, storage, UART device, traits
  • Unified VirtioDriver: Single VirtioDriver class with runtime device-type dispatch, replacing the old per-device-type classes
  • DmaRegion abstraction: Replaced void* DMA buffers with typed DmaRegion + VirtToPhys translation
  • Driver restructuring: Reorganized src/device/ into per-driver and per-type subdirectories
  • ETL adoption in drivers: etl::optional, etl::delegate, etl::vector, etl::flat_map in driver registry and driver implementations
  • Removed dead code: Deleted CRTP ops/ layer, unused device wrappers, DriverDescriptor, DeviceStorage

4. Filesystem Layer (VFS + RamFS + FatFS)

New filesystem infrastructure:

  • VFS: Virtual filesystem layer with SpinLock-guarded operations, supporting mount/open/read/write/close
  • RamFS: In-memory filesystem using static bump pools (no heap allocation)
  • FatFS: FatFS VFS adapter with VirtIO-blk integration via block_device_provider
  • FileDescriptorTable: Per-process file descriptor management
  • System tests: RamFS and FatFS system tests via VFS API

5. Memory: IoBuffer Module

  • IoBuffer: RAII-managed aligned I/O buffers for DMA and device communication
  • dma_buffer field in DeviceNode for VirtIO block driver integration
  • IoBuffer::ToDmaRegion() for zero-copy DMA submission

6. SMP & Boot

  • Working on SMP support: log with core ID, boot_task initialization, TimerInit moved to main
  • Multi-string FDT compatible matching for device discovery

7. Style & Code Quality

  • Trailing return types in .cpp and arch.h
  • #pragma once across all headers
  • [[nodiscard]], [[maybe_unused]], [[gnu::xxx]] replacing __attribute__((xxx))
  • Coding standards enforcement across src/arch/, src/filesystem/, src/memory/
  • Replaced sk_assert with standard assert
  • Removed cppcheck (replaced by clang-tidy in pre-commit)

Subsystem Diff Summary

Subsystem Files Insertions Deletions
src/arch/ 49 +4,205 -767
src/device/ 35 +4,736
src/filesystem/ 32 +4,122
src/task/ 24 +1,396 -659
src/include/ 20 +1,262 -1,037
tests/ 62 +4,172 -4,204
src/memory/ 4 +610
src/libc/ + src/libcxx/ 29 +225 -2,258
Build system 9 +153 -182

Test Plan

  • cmake --preset build_riscv64 && cd build_riscv64 && make SimpleKernel && make run
  • cmake --preset build_aarch64 && cd build_aarch64 && make SimpleKernel && make run
  • cmake --preset build_x86_64 && cd build_x86_64 && make SimpleKernel && make run
  • make unit-test on host architecture
  • pre-commit run --all-files passes

MRNIU and others added 30 commits February 27, 2026 14:00
Replace raw new TaskControlBlock with sk_std::make_unique and .release()
before passing to AddTask. Ensures exception-safe construction while
maintaining AddTask's raw pointer interface.

Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Add comprehensive ETL migration plan (Tasks 0-10) for replacing sk_std:: containers with ETL-backed kstd:: wrappers. Remove superseded unique_ptr design/implementation docs.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Add etl::etl to kernel link libraries in compile_config.cmake.
Add etl_profile.h with ETL_CPP23_SUPPORTED and ETL_NO_CHECKS defines.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Add kstd namespace wrappers around ETL containers:
- kstd_pool.hpp: Pool<T,N> and PoolRef type aliases
- kstd_vector: vector, static_vector, ivector
- kstd_list: list, static_list, list_node_t
- kstd_unique_ptr: custom unique_ptr implementation
- kstd_priority_queue: reference-based priority queue
- kstd_unordered_map: pool-backed unordered_map with std::hash

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Replace sk_std:: implementations with thin forwarding shims to kstd::
namespace. sk_vector, sk_list, sk_unique_ptr, sk_priority_queue, and
sk_unordered_map now delegate to ETL-backed kstd wrappers.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Replace sk_std:: containers with kstd:: static containers in schedulers
and task manager. Use static_vector, static_list, and static_unordered_map
with compile-time sizes. Mark scheduler copy/move as deleted since ETL
containers with internal storage are not copyable.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Delete sk_shared_ptr, sk_set, sk_rb_tree, and sk_queue which have no
remaining consumers after the ETL migration.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Remove unit and system tests for sk_queue, sk_rb_tree, sk_set, and
sk_shared_ptr. Update test CMakeLists.txt and system_test registration
to reflect 22 remaining test cases.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
…/Write helpers

Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
…Read/Write

Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
…c xAPIC branches

Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
…lkDriver::Probe

Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
…uler

Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
…nScheduler

Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
…y_queue in CfsScheduler

Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
… CpuSchedData

Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
MRNIU added 25 commits March 11, 2026 14:17
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
Copilot AI review requested due to automatic review settings March 18, 2026 02:45
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Large refactor to migrate core kernel infrastructure to ETL, introduce a new device framework, and add a VFS layer with RamFS/FatFS integration (plus build-system updates to support the new components).

Changes:

  • Replace multiple custom utilities (singletons, IO access, logging formatting) with ETL-based equivalents.
  • Add new device framework (bus enumeration + driver registry) and unified VirtIO driver with VFS block-device adapter.
  • Add VFS + RamFS + FatFS filesystem stack and update build/QEMU tooling to generate and attach a root filesystem image.

Reviewed changes

Copilot reviewed 175 out of 327 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
src/include/kernel_elf.hpp Switch to #pragma once, ETL singleton alias, log formatting updates, member renames.
src/include/kernel_config.hpp New kernel-wide sizing constants for tasks/observers.
src/include/kernel.h Add DeviceInit() / FileSystemInit() declarations and switch to trailing return style.
src/include/io_buffer.hpp New IoBuffer/DmaRegion interfaces for DMA-safe buffers.
src/include/io.hpp Remove legacy raw MMIO helpers (replaced by ETL IO ports).
src/include/interrupt_base.h Introduce etl::delegate-based handlers and external IRQ registration API.
src/include/config.h Remove legacy config include shim.
src/include/basic_info.hpp Switch to ETL singleton alias and modernize struct initialization.
src/filesystem/vfs/write.cpp New VFS write syscall entry with permission checks.
src/filesystem/vfs/vfs_internal.hpp Internal VFS helpers and global state definition.
src/filesystem/vfs/vfs.cpp Core VFS state + helper implementations + Init.
src/filesystem/vfs/unlink.cpp New unlink implementation using dentries/inode ops.
src/filesystem/vfs/seek.cpp New seek implementation with fallback default behavior.
src/filesystem/vfs/rmdir.cpp New rmdir implementation with empty-dir check.
src/filesystem/vfs/readdir.cpp New readdir wrapper enforcing directory type.
src/filesystem/vfs/read.cpp New read wrapper.
src/filesystem/vfs/open.cpp New open/create path using lookup + inode ops.
src/filesystem/vfs/mkdir.cpp New mkdir implementation building dentries from inode ops.
src/filesystem/vfs/lookup.cpp New path resolver with mount-point support and dentry caching.
src/filesystem/vfs/include/mount.hpp New mount table + mount-point structures.
src/filesystem/vfs/include/filesystem.hpp New filesystem interface for mount/sync/inode management.
src/filesystem/vfs/include/block_device.hpp New block-device abstraction for FS adapters.
src/filesystem/vfs/close.cpp New close wrapper with refcount decrement.
src/filesystem/vfs/CMakeLists.txt Build rules for VFS interface target.
src/filesystem/ramfs/CMakeLists.txt Build rules for RamFS interface target.
src/filesystem/include/file_descriptor.hpp New per-task FD table interface.
src/filesystem/filesystem.cpp FileSystemInit() mounting RamFS + optional FatFS on VirtIO blk.
src/filesystem/file_descriptor.cpp FD table implementation (alloc/free/dup/close-all).
src/filesystem/fatfs/include/ffconf.h FatFS configuration provided via forced include.
src/filesystem/fatfs/diskio.cpp FatFS disk HAL wired to vfs::BlockDevice.
src/filesystem/fatfs/CMakeLists.txt Build rules for FatFS wrapper + forced config include.
src/filesystem/CMakeLists.txt Aggregate filesystem target linking VFS/RamFS/FatFS/device.
src/filesystem/AGENTS.md Documentation for new filesystem architecture and conventions.
src/driver/pl011/pl011.cpp Remove legacy PL011 driver implementation (moved to new device framework).
src/driver/pl011/include/pl011.h Remove legacy PL011 interface.
src/driver/pl011/README.md Remove legacy PL011 docs.
src/driver/pl011/CMakeLists.txt Remove old PL011 CMake target.
src/driver/ns16550a/ns16550a.cpp Remove legacy NS16550A driver implementation (moved to new device framework).
src/driver/ns16550a/include/ns16550a.h Remove legacy NS16550A interface.
src/driver/ns16550a/README.md Remove legacy NS16550A docs.
src/driver/ns16550a/CMakeLists.txt Remove old NS16550A CMake target.
src/driver/include/driver.h Remove legacy driver entrypoint.
src/driver/driver.cpp Remove legacy driver stub.
src/driver/acpi/acpi.cpp Remove legacy ACPI stub implementation.
src/driver/acpi/README.md Remove legacy ACPI docs.
src/driver/acpi/CMakeLists.txt Remove legacy ACPI target.
src/driver/README.md Remove legacy driver directory README.
src/driver/CMakeLists.txt Remove legacy driver umbrella library.
src/device/virtio/virtio_driver.cpp New unified VirtIO probe and block-device exposure through DeviceNode.
src/device/virtio/virt_queue/virtqueue_base.hpp New virtqueue base using C++23 explicit object parameter patterns.
src/device/virtio/virt_queue/misc.hpp New virtqueue misc helpers (AlignUp, IoVec, etc.).
src/device/virtio/transport/pci.hpp Placeholder PCI transport implementation.
src/device/virtio/device/net/virtio_net.h Placeholder VirtIO net header.
src/device/virtio/device/input/virtio_input.h Placeholder VirtIO input header.
src/device/virtio/device/gpu/virtio_gpu.h Placeholder VirtIO GPU header.
src/device/virtio/device/console/virtio_console.h Placeholder VirtIO console header.
src/device/virtio/device/blk/virtio_blk_vfs_adapter.hpp Adapter exposing VirtIO blk via vfs::BlockDevice.
src/device/virtio/defs.h VirtIO device IDs and reserved feature bits.
src/device/virtio/CMakeLists.txt Build rules for VirtIO driver target.
src/device/pl011/pl011_driver.hpp New PL011 driver entry for device framework.
src/device/pl011/CMakeLists.txt Build rules for PL011 driver target.
src/device/ns16550a/ns16550a_driver.hpp New NS16550A driver entry for device framework.
src/device/ns16550a/CMakeLists.txt Build rules for NS16550A driver target.
src/device/include/platform_bus.hpp New FDT-based platform bus enumerator.
src/device/include/device_node.hpp New DeviceNode schema + bus concept.
src/device/include/device_manager.hpp New device manager singleton managing nodes and drivers.
src/device/device_manager.cpp Implement ProbeAll / lookups for device manager.
src/device/device.cpp DeviceInit() entrypoint registering drivers and enumerating platform bus.
src/device/acpi/acpi_driver.hpp New ACPI driver header placeholder.
src/device/acpi/acpi.hpp ACPI table structures migrated to new device folder + modernized packing.
src/device/acpi/CMakeLists.txt Build rules for ACPI driver target.
src/device/CMakeLists.txt Aggregate device target linking all driver targets.
src/device/AGENTS.md Documentation for new device framework architecture/conventions.
src/arch/x86_64/timer.cpp Modernize signatures and remove legacy singleton include.
src/arch/x86_64/syscall.cpp Modernize syscall handler signature.
src/arch/x86_64/sipi.h Remove duplicate SIPI header (moved under include/).
src/arch/x86_64/macro.S Remove stale brief comment.
src/arch/x86_64/include/sipi.h #pragma once, inline const, rename packed struct.
src/arch/x86_64/include/interrupt.h Update to delegate-based interrupt handlers + ETL singleton alias.
src/arch/x86_64/early_console.cpp Switch early console to ETL putchar integration.
src/arch/x86_64/backtrace.cpp Switch to new KernelElf member names + ETL singleton usage.
src/arch/x86_64/apic/io_apic.cpp Replace raw IO with ETL IO ports and new formatting.
src/arch/x86_64/apic/include/io_apic.h #pragma once, trailing returns, init defaults.
src/arch/x86_64/apic/include/apic.h Add [[nodiscard]] + trailing returns and modernize members.
src/arch/x86_64/apic/README.md Update docs to ETL singleton aliases.
src/arch/riscv64/timer.cpp Switch timer registration to delegates + singleton aliases.
src/arch/riscv64/syscall.cpp Modernize syscall handler signature.
src/arch/riscv64/include/interrupt.h Delegate-based handler arrays + external IRQ API.
src/arch/riscv64/early_console.cpp Switch early console output to etl_putchar.
src/arch/riscv64/boot.S Stack sizing based on config constant (not fixed shift).
src/arch/riscv64/backtrace.cpp Switch to new KernelElf member names + singleton usage.
src/arch/riscv64/arch_main.cpp Switch to ETL singleton creation + format-string updates.
src/arch/aarch64/timer.cpp Delegate-based timer handler + singleton usage.
src/arch/aarch64/syscall.cpp Use std::array for syscall args; update dispatcher call.
src/arch/aarch64/interrupt.cpp Add external IRQ registration + robust MMIO mapping error logs.
src/arch/aarch64/include/pl011_singleton.h New PL011 singleton alias header for early console.
src/arch/aarch64/include/interrupt.h Delegate-based IRQ handlers + expose GIC helper calls.
src/arch/aarch64/gic/README.md Fix method naming in docs (SetUp).
src/arch/aarch64/early_console.cpp Switch early console to new PL011 singleton and etl_putchar.
src/arch/aarch64/boot.S Stack sizing based on config constant (not fixed shift).
src/arch/aarch64/backtrace.cpp Switch to new KernelElf member names + singleton usage.
src/arch/aarch64/arch_main.cpp Switch to ETL singleton creation + updated logging.
src/arch/CMakeLists.txt Link arch to interrupt-controller subdirs + device drivers needed by arch.
src/arch/AGENTS.md New architecture documentation.
src/CMakeLists.txt Add memory/device/filesystem subdirectories and link targets.
docs/CMakeLists.txt Rename Doxygen project/target from doc to docs.
docs/2_调试输出.md Update docs to new singleton/console initialization.
docs/1_系统启动.md Update boot-flow docs to new singleton usage.
docs/0_工具链.md Remove cppcheck suppression mention.
doc/task_unit_test_new_design.md Remove outdated task unit test design doc.
cmake/x86_64-gcc.cmake Normalize CMake style and improve toolchain checks.
cmake/riscv64-gcc.cmake Normalize CMake style and improve toolchain checks.
cmake/project_config.cmake Add additional clean targets for bin/lib outputs.
cmake/functions.cmake Generate rootfs.img and wire into QEMU dtb generation/run targets.
cmake/compile_config.cmake Add ETL + FatFS compile defs and link dependencies; adjust -O2 in Release.
cmake/clang.cmake Remove clang toolchain file.
cmake/3rd.cmake Remove nanoprintf and cppcheck; add ETL + FatFS third-party integrations.
CMakePresets.json Add QEMU device flags and attach generated rootfs.img drives; tweak defaults.
CMakeLists.txt Switch subdirectory from doc/ to docs/.
AGENTS.md Add repository-level agent documentation and conventions.
3rd/optee/optee_os Update submodule commit.
3rd/optee/optee_client Update submodule commit.
3rd/optee/build Update submodule commit.
3rd/nanoprintf Remove nanoprintf submodule reference.
3rd/fatfs Add FatFS submodule reference.
3rd/etl Add ETL submodule reference.
3rd/dtc Update submodule commit.
3rd/cpu_io Update submodule commit.
3rd/MPMCQueue/test/test.cpp Minor include ordering/spacing.
3rd/MPMCQueue/test/CMakeLists.txt Normalize CMake style.
3rd/MPMCQueue/CMakeLists.txt Normalize CMake style.
3rd/EasyLogger Add EasyLogger submodule reference.
.gitmodules Remove nanoprintf; add fatfs/etl/EasyLogger submodules.
.github/workflows/workflow.yml Update docs target name and GitHub Pages publish directory.

Comment on lines 25 to 29
// 检查 IRQ 是否在有效范围内
auto max_entries = GetMaxRedirectionEntries();
if (irq >= max_entries) {
klog::Err("IRQ %u exceeds maximum entries %u\n", irq, max_entries);
return;
klog::Err("IRQ {} exceeds maximum entries {}", irq, max_entries);
}
Comment on lines +26 to 32
auto TimerInitSMP() -> void {
// 开启时钟中断
cpu_io::Sie::Stie::Set();

// 设置初次时钟中断时间
sbi_set_timer(interval);
}
Comment on lines +23 to +25
if (strlen(path) >= kMaxPathLength) {
return std::unexpected(Error(ErrorCode::kFsInvalidPath));
}
Comment on lines +40 to +55
char parent_path[512];
char file_name[256];
const char* last_slash = strrchr(path, '/');
if (last_slash == nullptr || last_slash == path) {
strncpy(parent_path, "/", sizeof(parent_path));
strncpy(file_name, path[0] == '/' ? path + 1 : path, sizeof(file_name));
} else {
size_t parent_len = last_slash - path;
if (parent_len >= sizeof(parent_path)) {
parent_len = sizeof(parent_path) - 1;
}
strncpy(parent_path, path, parent_len);
parent_path[parent_len] = '\0';
strncpy(file_name, last_slash + 1, sizeof(file_name));
}
file_name[sizeof(file_name) - 1] = '\0';
return std::unexpected(Error(ErrorCode::kOutOfMemory));
}

strncpy(new_dentry->name, dir_name, sizeof(new_dentry->name) - 1);
Comment thread src/device/virtio/virtio_driver.cpp Outdated
// Allocate slot DMA buffer
auto [slot_size, slot_align] =
virtio::blk::VirtioBlk<>::GetRequiredSlotMemSize();
slot_buffers_[idx] = kstd::make_unique<IoBuffer>(slot_size);
Comment on lines +44 to +61
auto* ptr = static_cast<uint8_t*>(buf);
for (uint32_t i = 0; i < count; ++i) {
auto result = dev_->Read(lba + i, ptr + i * kSectorSize);
if (!result) {
return std::unexpected(Error(result.error().code));
}
}
return static_cast<size_t>(count) * kSectorSize;
}

auto WriteSectors(uint64_t lba, uint32_t count, const void* buf)
-> Expected<size_t> override {
const auto* ptr = static_cast<const uint8_t*>(buf);
for (uint32_t i = 0; i < count; ++i) {
auto result = dev_->Write(lba + i, ptr + i * kSectorSize);
if (!result) {
return std::unexpected(Error(result.error().code));
}
Comment on lines +118 to +123
case GET_SECTOR_COUNT:
static_cast<LBA_t*>(buff)[0] = static_cast<LBA_t>(dev->GetSectorCount());
return RES_OK;
case GET_SECTOR_SIZE:
static_cast<WORD*>(buff)[0] = static_cast<WORD>(dev->GetSectorSize());
return RES_OK;
Comment thread src/include/io_buffer.hpp
Comment on lines +67 to +75
-> Expected<DmaRegion> {
if (offset + len > size) {
return std::unexpected(Error{ErrorCode::kInvalidArgument});
}
return DmaRegion{
.virt = static_cast<uint8_t*>(virt) + offset,
.phys = phys + offset,
.size = len,
};
Comment on lines +42 to +46
const char* last_slash = strrchr(path, '/');
if (last_slash == nullptr || last_slash == path) {
strncpy(parent_path, "/", sizeof(parent_path));
strncpy(file_name, path[0] == '/' ? path + 1 : path, sizeof(file_name));
} else {
MRNIU added 2 commits March 18, 2026 11:09
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
…ce, and DMA

- io_apic: add early return after OOB IRQ check in SetIrqRedirection/MaskIrq/UnmaskIrq
- mkdir: add NUL-termination after strncpy on dentry name
- lookup: replace broken mount-point loop with FindByMountDentry
- file_descriptor: fix open_count_ over-counting in SetupStandardFiles
- io_buffer: fix size_t overflow in SubRegion bounds check
- open/mkdir: reject path components exceeding buffer sizes
- file_descriptor: use address-based lock ordering in move-assignment
- virtio_driver: pass slot_align to IoBuffer for consistency
- diskio: add nullptr guard for buff in disk_ioctl

Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>
@MRNIU MRNIU merged commit fab4dba into Simple-XX:main Mar 18, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants