darlinghq / darling

Darwin/macOS emulation layer for Linux
http://www.darlinghq.org
GNU General Public License v3.0
11.37k stars 440 forks source link

Syscall User Dispatch - Linux 5.11 #944

Open JCWasmx86 opened 3 years ago

JCWasmx86 commented 3 years ago

With the version 5.11 of the linux kernel came a feature called Syscall User Dispatch.

Syscall User Dispatch brings the filtering of the syscall dispatcher address back to userspace. The application is in control of a flip switch, indicating the current personality of the process. A multiple-personality application can then flip the switch without invoking the kernel, when crossing the compatibility layer API boundaries, to enable/disable the syscall redirection and execute syscalls directly (disabled) or send them to be emulated in userspace through a SIGSYS. The goal of this design is to provide very quick compatibility layer boundary crosses, which is achieved by not executing a syscall to change personality every time the compatibility layer executes. Instead, a userspace memory region exposed to the kernel indicates the current personality, and the application simply modifies that variable to configure the mechanism.

If I understand correctly, this allows a more efficient redirection of syscalls (E.g. windows syscalls to wine).

Is it planned to use this in darling, potentially improving performance?

izzimat commented 3 years ago

As demonstrated here by a somewhat similar project.

https://github.com/meme/limbo

facekapow commented 3 years ago

Well, this wouldn't really be a performance enhancement, but more of a compatibility enhancement, allowing (insane) applications that don't use libSystem to do kernel calls to work under Darling. Right now, the only syscall handling we do is through libSystem. If an app tries to perform direct syscalls, they end up calling into the Linux kernel. See #193.

HinTak commented 3 years ago

Does launchd recursively wipe /run via libSystem or via direct system calls? I am still thinking about the incidents of darling wiping my external hard disks under /run/media/MyName/diskname on Linux https://github.com/darlinghq/darling/issues/848 , and two different drives. :(

facekapow commented 3 years ago

All the software Darling ships (including launchd) uses libSystem, not direct syscalls.

CuriousTommy commented 7 months ago

So I looked into this, and there are two blockers that prevent us from adopting Syscall User Dispatch for Darling: