Skip to content

Add userland exec path: ELF VFS loader, stack/auxv/TLS setup, and related filesystem/paging fixes#29

Merged
pradosh-arduino merged 2 commits intomainfrom
codex/fix-elf-execution-error-in-fsh-4mkmu5
Mar 22, 2026
Merged

Add userland exec path: ELF VFS loader, stack/auxv/TLS setup, and related filesystem/paging fixes#29
pradosh-arduino merged 2 commits intomainfrom
codex/fix-elf-execution-error-in-fsh-4mkmu5

Conversation

@pradosh-arduino
Copy link
Copy Markdown
Collaborator

Motivation

  • Provide a proper userland exec path that can load ELF binaries directly from the VFS and start them in ring 3 with correct arguments, environment and auxiliary vector metadata.
  • Ensure ELF program headers can be staged or mapped into user space without requiring a single monolithic file image in memory, to support constrained/streaming VFS backends.
  • Improve filesystem robustness (FAT16/FAT32 reads/seeking) and observability for page faults and kernel panics to aid debugging when running user processes.

Description

  • Introduced elf_image_info_t and extended ELF APIs with elf_load_from_memory_ex and elf_load_from_vfs_ex to return entry and PHDR metadata, plus helpers for reading program headers from VFS and staging PHDRs into user memory.
  • Added VFS-aware ELF helpers (elf_vfs_seek, elf_vfs_read_exact, elf_vfs_read_exact_path) and a streaming mapper elf_map_program_header_from_vfs to map and copy PT_LOAD segments without requiring the whole image buffer.
  • Implemented userland process start pipeline: userland_exec, stack/argv/env building including auxv entries (PHDR/PHNUM/PHENT/PAGESZ/ENTRY/RANDOM/PLATFORM/EXECFN), TLS initialization at USER_TLS_VADDR with glibc-compatible TCB layout, and updated enter_userland_at to zero registers before iretq.
  • Updated syscall and shell code to support the new exec path: sys_execve now copies argv/envp and calls userland_exec, cmd_exec forwards arguments to userland_exec (with a busybox default), and helpers to copy/free user string arrays were added.
  • Filesystem and paging tweaks: added prototype fat32_read_fat, improved FAT16 cluster walking with fat16_next_cluster_with_fallback and robust fat16_read seeking, added fast_virt_to_phys and virt_to_phys alias, and minor paging mapping/flag adjustments to support user mappings.
  • Debugging and logging improvements: enhanced page fault logging in isr.c and richer meltdown logging in meltdown.c to include interrupt/error codes and register snapshots.

Testing

  • No automated tests were executed for this change (no CI test outputs were provided).

Codex Task

@pradosh-arduino pradosh-arduino merged commit cefe916 into main Mar 22, 2026
0 of 2 checks passed
@pradosh-arduino pradosh-arduino deleted the codex/fix-elf-execution-error-in-fsh-4mkmu5 branch April 2, 2026 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant