logo
0
0
WeChat Login
feat: update README.md

OS Camp - Rust & OS Advanced Experiments

A Rust advanced and operating system introductory exercise repository in the style of rustlings. Learn Rust concurrency programming, async programming, no_std development, and operating system core concepts through completing code and passing tests.

Prerequisites

  • Rust toolchain (stable, >= 1.75)
  • Linux environment: most exercises target x86_64; Module 4 (context switching) only supports riscv64 and requires a riscv64 environment or QEMU user-mode emulation
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Exercise Structure

6 modules, 23 exercises in total, from easy to advanced:

Module 1: Concurrency (Synchronous) — 01_concurrency_sync/

#ExerciseConcepts
101_thread_spawnthread::spawn, move closures, join
202_mutex_counterArc<Mutex<T>>, shared state concurrency
303_channelmpsc::channel, multiple producer pattern
404_process_pipeCommand, Stdio::piped(), process pipes

Module 2: no_std Development — 02_no_std_dev/

#ExerciseConcepts
101_mem_primitivesno_std memory primitives: memcpy, memset, memmove, strlen, strcmp
202_bump_allocatorGlobalAlloc trait, Bump allocator, CAS-based thread safety
303_free_list_allocatorFree-list allocator, intrusive linked list, first-fit strategy
404_syscall_wrapperCross-arch syscall ABI (x86_64/aarch64/riscv64), inline assembly
505_fd_tableFile descriptor table, Arc<dyn File>, fd reuse strategy

Module 3: OS Concurrency Advanced — 03_os_concurrency/

#ExerciseConcepts
101_atomic_counterAtomicU64, fetch_add, CAS loop
202_atomic_orderingMemory ordering, Release-Acquire, OnceCell
303_spinlockSpinlock implementation, compare_exchange, spin_loop
404_spinlock_guardRAII guard, Deref/DerefMut/Drop
505_rwlockWriter-priority read-write lock from scratch (no std::sync::RwLock)

Module 4: Context Switching — 04_context_switch/ (riscv64 only)

#ExerciseConcepts
101_stack_coroutineCallee-saved registers, stack frames, context switching
202_green_threadsGreen thread scheduler, cooperative scheduling, yield

Module 4 only runs on riscv64. Run ./check.sh or use the oscamp CLI as with the rest of the repository — no separate scripts needed. See exercises/04_context_switch/README.md for details.

Module 5: Async Programming — 05_async_programming/

#ExerciseConcepts
101_basic_futureManual implementation of Future trait, Poll, Waker
202_tokio_taskstokio::spawn, JoinHandle, concurrent tasks
303_async_channeltokio::sync::mpsc, async producer-consumer
404_select_timeouttokio::select!, timeout control, race execution

Module 6: Page Tables — 06_page_table/

#ExerciseConcepts
101_pte_flagsSV39 PTE bit layout, bit operations to construct/parse page table entries
202_page_table_walkSingle-level page tables, VPN/offset splitting, address translation, page faults
303_multi_level_ptSV39 three-level page tables, page table walk, huge pages (2MB) mapping
404_tlb_simTLB lookup/insert/FIFO replacement, flush (all/by page/by ASID), MMU simulation

Quick Start

# 1. Clone repository git clone <repo-url> && cd oscamp-base-experiment # 2. Build interactive CLI tool cargo build -p oscamp-cli # 3. Start interactive exercise mode (recommended) ./target/debug/oscamp watch

Interactive CLI Tool (oscamp)

Built-in interactive terminal tool similar to rustlings, supporting real-time file watching and progress tracking:

oscamp # Start interactive watch mode (default) oscamp watch # Same as above oscamp list # View completion status of all exercises oscamp check # Check all exercises in batch oscamp run <pkg> # Run tests for specified exercise oscamp hint <pkg> # View exercise hint oscamp help # Show help

Watch Mode Features

  • Automatic file change detection: Automatically re-run tests after saving files
  • Auto-jump: Automatically jump to next unfinished exercise after current one passes
  • Real-time progress bar: Show overall completion progress
  • Shortcuts:
    • h — View hint for current exercise
    • l — View list of all exercises
    • n / p — Next / Previous exercise
    • r / Enter — Re-run tests
    • q / Esc — Quit

Manual Execution

# Run tests for a specific exercise cargo test -p thread_spawn # View detailed output cargo test -p thread_spawn -- --nocapture # Check all exercises cargo test --workspace

Workflow

  1. Start: Run ./target/debug/oscamp watch to enter interactive mode
  2. Read: Open current exercise file src/lib.rs, read documentation to understand concepts
  3. Code: Find todo!() markers, complete code according to comment hints
  4. Save: After saving file, CLI automatically re-runs tests
  5. Pass: After passing tests, automatically jump to next exercise; press h to view hints anytime

Submitting Scores

This repository uses a CI pipeline to automatically score your exercises and submit results to the leaderboard.

  1. Fork this repository on CNB
  2. Complete exercises locally or in the cloud-native WebIDE
  3. Push your changes to your fork
  4. Create a Pull Request to the upstream repository — this triggers the scoring pipeline
  5. The pipeline runs all tests, calculates your score (out of 100), and uploads it to the OpenCamp leaderboard

Notes

  • Some exercises (e.g., Module 2 syscall wrapper, Module 4 assembly) require a Linux environment; Module 4 only supports riscv64
  • It is recommended to complete exercises in module order; within each module, exercises progress from easy to advanced

License

MIT