Skip to content

Mach-O loading in kernel #364

Description

@LubosD

In relation to #304 (getting LLDB working under Darling), we need to move Mach-O loading to the kernel.

This has several benefits:

And disadvantages:

  • We'll have to redo our approach to calling ELF APIs.

Steps - Mach-O

  • Load Mach-Os in kernel. See if we can adapt Wenqi's code for this.
  • Move commpage generation into the kernel.
  • Hide /dev/mach from userspace. Open devmach fd inside the kernel Mach-O loader (and make it O_CLOEXEC).
  • Provide information to dyld_info in the XNU task (needed for debuggers).
  • Remove /dev/mach opening from libsystem_kernel. Maybe we could get the fd number via apple[] args to entry point?

Steps - ELF

  • Introduce a library for loading ELF files...:
  • Create a simple ELF loader (similar to the kernel ELF loader - no dynamic library loading).
  • Create an ELF stub that gets jumped into by the loader (dynamic loader) and returns control back into Mach-O (while passing along fnptrs to dlopen() and friends). We could pass a function pointer via argv[] and this function would longjmp() back in order to rewind the stack.
  • Modify libsystem_kernel to access our ELF wrapper for bsdthread_* syscall implementation.

More Ideas

  • Provide commpage contents as a mmap from the devmach fd. The devmach fd would then be closed before jumping to the entry point. This way we'd avoid polluting the fd table, but still learn about process termination (the memory mapping destruction would close the struct file*).
  • Register an IDT entry (e.g. 0x83) for using for LKM calls instead of ioctl() and do int 0x83 to make LKM calls.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

EnhancementA way Darling can be improved

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions