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
24 changes: 17 additions & 7 deletions kernel/src/main_aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,10 +680,10 @@ fn load_test_binaries_from_ext2() {
let mut loaded = 0;
let mut failed = 0;

for name in test_binaries {
// create_ext2_disk.sh strips the .elf extension when installing binaries
let path = format!("/bin/{}", name);
// Search paths for test binaries - try each in order
let search_dirs = ["/bin", "/usr/local/cbin", "/usr/local/test/bin", "/sbin"];

for name in test_binaries {
// Load ELF from ext2 - acquire and release lock for each binary
let elf_data = {
let fs_guard = kernel::fs::ext2::root_fs_read();
Expand All @@ -695,10 +695,20 @@ fn load_test_binaries_from_ext2() {
}
};

let inode_num = match fs.resolve_path(&path) {
Ok(num) => num,
Err(_) => {
// Binary not present in ext2 - skip silently
// Try each search directory until we find the binary
let mut found_inode = None;
for dir in &search_dirs {
let path = format!("{}/{}", dir, name);
if let Ok(num) = fs.resolve_path(&path) {
found_inode = Some(num);
break;
}
}

let inode_num = match found_inode {
Some(num) => num,
None => {
// Binary not present in any search path - skip silently
continue;
}
};
Expand Down
6 changes: 3 additions & 3 deletions kernel/src/process/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ impl ProcessManager {
// Set up argc/argv/envp/auxv on the stack following Linux ABI
// The stack is now mapped, so we can write to it via physical addresses
let default_env: [&[u8]; 5] = [
b"PATH=/bin:/sbin\0",
b"PATH=/bin:/sbin:/usr/local/cbin\0",
b"HOME=/\0",
b"TERM=vt100\0",
b"USER=root\0",
Expand Down Expand Up @@ -2585,7 +2585,7 @@ impl ProcessManager {
// Since the new page table is not active yet, we need to translate addresses
// and write via the physical frames
let default_env: [&[u8]; 5] = [
b"PATH=/bin:/sbin\0",
b"PATH=/bin:/sbin:/usr/local/cbin\0",
b"HOME=/\0",
b"TERM=vt100\0",
b"USER=root\0",
Expand Down Expand Up @@ -2829,7 +2829,7 @@ impl ProcessManager {
}

let default_env: [&[u8]; 5] = [
b"PATH=/bin:/sbin\0",
b"PATH=/bin:/sbin:/usr/local/cbin\0",
b"HOME=/\0",
b"TERM=vt100\0",
b"USER=root\0",
Expand Down
28 changes: 22 additions & 6 deletions scripts/create_ext2_disk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,23 +105,30 @@ if [[ "$(uname)" == "Darwin" ]]; then
mkdir -p /mnt/ext2
mount /work/$OUTPUT_FILENAME /mnt/ext2

# Create /bin, /sbin, and /usr/local/test/bin directories
# Create /bin, /sbin, /usr/local/test/bin, and /usr/local/cbin directories
mkdir -p /mnt/ext2/bin
mkdir -p /mnt/ext2/sbin
mkdir -p /mnt/ext2/usr/local/test/bin
mkdir -p /mnt/ext2/usr/local/cbin

# Copy ALL binaries from /binaries directory
# Routing: test binaries (*_test, test_*) -> /usr/local/test/bin
# Routing: musl C programs (*_musl*) -> /usr/local/cbin
# test binaries (*_test, test_*) -> /usr/local/test/bin
# system binaries (true, telnetd, init) -> /sbin
# everything else -> /bin
echo "Installing all binaries..."
bin_count=0
sbin_count=0
test_count=0
cbin_count=0
for elf_file in /binaries/*.elf; do
if [ -f "$elf_file" ]; then
bin_name=$(basename "$elf_file" .elf)
if echo "$bin_name" | grep -qE "_test$|^test_"; then
if echo "$bin_name" | grep -qE "_musl"; then
cp "$elf_file" /mnt/ext2/usr/local/cbin/${bin_name}
chmod 755 /mnt/ext2/usr/local/cbin/${bin_name}
cbin_count=$((cbin_count + 1))
elif echo "$bin_name" | grep -qE "_test$|^test_"; then
cp "$elf_file" /mnt/ext2/usr/local/test/bin/${bin_name}
chmod 755 /mnt/ext2/usr/local/test/bin/${bin_name}
test_count=$((test_count + 1))
Expand All @@ -138,6 +145,7 @@ if [[ "$(uname)" == "Darwin" ]]; then
done
echo " Installed $bin_count binaries in /bin"
echo " Installed $sbin_count binaries in /sbin"
echo " Installed $cbin_count C binaries in /usr/local/cbin"
echo " Installed $test_count test binaries in /usr/local/test/bin"

# Create /etc with passwd and group for musl getpwuid/getgrgid
Expand Down Expand Up @@ -231,23 +239,30 @@ else
MOUNT_DIR=$(mktemp -d)
mount "$OUTPUT_FILE" "$MOUNT_DIR"

# Create /bin, /sbin, and /usr/local/test/bin directories
# Create /bin, /sbin, /usr/local/test/bin, and /usr/local/cbin directories
mkdir -p "$MOUNT_DIR/bin"
mkdir -p "$MOUNT_DIR/sbin"
mkdir -p "$MOUNT_DIR/usr/local/test/bin"
mkdir -p "$MOUNT_DIR/usr/local/cbin"

# Copy ALL binaries from userspace directory
# Routing: test binaries (*_test, test_*) -> /usr/local/test/bin
# Routing: musl C programs (*_musl*) -> /usr/local/cbin
# test binaries (*_test, test_*) -> /usr/local/test/bin
# system binaries (true, telnetd, init) -> /sbin
# everything else -> /bin
echo "Installing all binaries..."
bin_count=0
sbin_count=0
test_count=0
cbin_count=0
for elf_file in "$USERSPACE_DIR"/*.elf; do
if [ -f "$elf_file" ]; then
bin_name=$(basename "$elf_file" .elf)
if echo "$bin_name" | grep -qE '_test$|^test_'; then
if echo "$bin_name" | grep -qE '_musl'; then
cp "$elf_file" "$MOUNT_DIR/usr/local/cbin/${bin_name}"
chmod 755 "$MOUNT_DIR/usr/local/cbin/${bin_name}"
cbin_count=$((cbin_count + 1))
elif echo "$bin_name" | grep -qE '_test$|^test_'; then
cp "$elf_file" "$MOUNT_DIR/usr/local/test/bin/${bin_name}"
chmod 755 "$MOUNT_DIR/usr/local/test/bin/${bin_name}"
test_count=$((test_count + 1))
Expand All @@ -264,6 +279,7 @@ else
done
echo " Installed $bin_count binaries in /bin"
echo " Installed $sbin_count binaries in /sbin"
echo " Installed $cbin_count C binaries in /usr/local/cbin"
echo " Installed $test_count test binaries in /usr/local/test/bin"

# Create /etc with passwd and group for musl getpwuid/getgrgid
Expand Down
Loading