Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jobs:
mtools \
lld \
llvm \
cmake \
ninja-build \
cmake ninja-build \
curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | sh
Comment on lines +32 to +33
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Remove the trailing backslash and make the rustup install non-interactive

Line 32 keeps the line-continuation \, so the shell treats the subsequent curl … | sh as part of the apt-get install command (and even pipes apt output into sh). The step fails before rustup ever runs. Drop the trailing backslash so curl executes separately, and make the rustup install non-interactive while exporting Cargo to the PATH.

-            cmake ninja-build \
-          curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | sh
+            cmake \
+            ninja-build
+          curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal --default-toolchain stable
+          source "$HOME/.cargo/env"
+          echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
cmake ninja-build \
curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | sh
cmake \
ninja-build
curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal --default-toolchain stable
source "$HOME/.cargo/env"
echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
🤖 Prompt for AI Agents
In .github/workflows/main.yaml around lines 32-33, remove the trailing backslash
after the apt install line so the curl pipeline is not treated as part of apt,
run rustup non-interactively by invoking the installer with -s -- -y (curl
--proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | sh -s -- -y), and after
installation ensure Cargo is on PATH by sourcing $HOME/.cargo/env or adding
$HOME/.cargo/bin to the job PATH so subsequent steps can use cargo.


- name: Compile & Link (CMake)
run: |
Expand Down
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ set(EXECF_SOURCES
set(MM_SOURCES
mm/PMem.c
mm/MemOps.c
mm/KernelHeap.c
mm/VMem.c
mm/StackGuard.c
mm/MemPool.c
mm/KernelHeap.c
mm/trace/StackTrace.c
mm/security/Cerberus.c
mm/PageFaultHandler.c
Expand Down Expand Up @@ -191,6 +191,11 @@ if(NOT EXCLUDE_EXTRA_OBJECTS)
)
endif()

# ============================================================================
# Rust Memory Management
# ============================================================================
add_subdirectory(mm/rust)

# ============================================================================
# Build Include Directories
# ============================================================================
Expand Down Expand Up @@ -248,6 +253,9 @@ if(NOT EXCLUDE_EXTRA_OBJECTS)
target_sources(voidframe.krnl PRIVATE ${OBJ_SOURCES})
endif()

# Link Rust heap library
target_link_libraries(voidframe.krnl PRIVATE rust_heap)

# Configure the linker to use ld.lld with proper arguments
set_target_properties(voidframe.krnl PROPERTIES
LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/voidframe.ld"
Expand Down
21 changes: 20 additions & 1 deletion kernel/etc/Shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "sound/Generic.h"
#include "stdlib.h"
#include "xHCI/xHCI.h"
#include "KernelHeapRust.h"

#define DATE __DATE__
#define TIME __TIME__
Expand Down Expand Up @@ -363,7 +364,24 @@ static void AllocHandler(const char * args) {
KernelFree(size_str);
return;
}
KernelMemoryAlloc((uint32_t)size);
if (!KernelMemoryAlloc((uint32_t)size)) PrintKernelErrorF("Allocation for %d bytes failed\n", size);
KernelFree(size_str);
}

static void RsAllocHandler(const char * args) {
char* size_str = GetArg(args, 1);
if (!size_str) {
PrintKernel("Usage: rsalloc <size>\n");
KernelFree(size_str);
return;
}
int size = atoi(size_str);
if (size <= 0) {
PrintKernel("Usage: rsalloc <size>\n");
KernelFree(size_str);
return;
}
if (!rust_kmalloc((uint32_t)size)) PrintKernelErrorF("Allocation for %d bytes failed\n", size);
KernelFree(size_str);
}

Expand Down Expand Up @@ -1182,6 +1200,7 @@ static const ShellCommand commands[] = {\
{"mkdir", MkdirHandler},
{"touch", TouchHandler},
{"alloc", AllocHandler},
{"rsalloc", RsAllocHandler},
{"panic", PanicHandler},
{"kill", KillHandler},
{"rm", RmHandler},
Expand Down
36 changes: 36 additions & 0 deletions mm/KernelHeapRust.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef KERNEL_HEAP_RUST_H
#define KERNEL_HEAP_RUST_H

#include <stddef.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

// Core allocation functions
void* rust_kmalloc(size_t size);
void rust_kfree(void* ptr);
void* rust_krealloc(void* ptr, size_t new_size);
void* rust_kcalloc(size_t count, size_t size);

// Statistics and monitoring
typedef struct {
size_t total_allocated;
size_t peak_allocated;
uint64_t alloc_count;
uint64_t free_count;
uint64_t cache_hits;
uint64_t cache_misses;
uint64_t coalesce_count;
uint64_t corruption_count;
} HeapStats;

void rust_heap_get_stats(HeapStats* stats);
int rust_heap_validate(void);

#ifdef __cplusplus
}
#endif

#endif // KERNEL_HEAP_RUST_H
9 changes: 9 additions & 0 deletions mm/rust/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[build]
target = "x86_64-unknown-none"

[target.x86_64-unknown-none]
rustflags = [
"-C", "code-model=kernel",
"-C", "relocation-model=static",
"-C", "target-feature=-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2",
]
44 changes: 44 additions & 0 deletions mm/rust/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
cmake_minimum_required(VERSION 3.20)

# Find Rust and Cargo
find_program(CARGO_EXECUTABLE cargo REQUIRED)
find_program(RUSTC_EXECUTABLE rustc REQUIRED)

# Set target triple based on architecture
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64")
set(RUST_TARGET "x86_64-unknown-none")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64")
set(RUST_TARGET "aarch64-unknown-none")
else()
message(FATAL_ERROR "Unsupported architecture: ${CMAKE_SYSTEM_PROCESSOR}")
endif()

# Rust library target
set(RUST_LIB_NAME "voidframe_mm")
set(RUST_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/target/${RUST_TARGET}/release/lib${RUST_LIB_NAME}.a")

# Custom command to build Rust library
add_custom_command(
OUTPUT ${RUST_LIB_PATH}
COMMAND ${CARGO_EXECUTABLE} build --release --target ${RUST_TARGET}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/Cargo.toml
${CMAKE_CURRENT_SOURCE_DIR}/src/lib.rs
${CMAKE_CURRENT_SOURCE_DIR}/src/heap.rs
${CMAKE_CURRENT_SOURCE_DIR}/src/vmem_ffi.rs
COMMENT "Building Rust heap library"
)

# Create imported library target
add_custom_target(rust_heap_build DEPENDS ${RUST_LIB_PATH})

add_library(rust_heap STATIC IMPORTED GLOBAL)
set_target_properties(rust_heap PROPERTIES
IMPORTED_LOCATION ${RUST_LIB_PATH}
)

add_dependencies(rust_heap rust_heap_build)

# Install header
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/../KernelHeapRust.h
DESTINATION include/mm)
16 changes: 16 additions & 0 deletions mm/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions mm/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "voidframe-mm"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["staticlib"]

[dependencies]
spin = { version = "0.9", default-features = false, features = ["mutex", "spin_mutex"] }

[profile.release]
panic = "abort"
lto = true
codegen-units = 1
Loading
Loading