A question about BSD kernel syscalls/abi reddit / BSD ---------------------------------------------------------------------- staalmannen · 2018-07-04 04:31 Dear all, I recently found the old linux-abi project [1], which basically is a syscall emulation system for Linux (2.4, 2.6 era kernels) like those found on FreeBSD and NetBSD. If I ever get time, I would like to try to get it working on a current Linux kernel. My motivation, however, would be to try to run a BSD system in a chroot on Linux. Now to my question: No BSD emulation is listed but svr4 is. Are all BSD kernels abi compatible (so you can run a static binary from one BSD on another, or running another BSD in a chroot)? If not, can you give pointers to where BSD the syscall emulations are for reference/comparisons? [1] http://linux-abi.sourceforge.net ---------------------------------------------------------------------- rectagonal · 2018-07-04 04:51 > Are all BSD kernels abi compatible (so you can run a static binary from one BSD on another, or running another BSD in a chroot) No, but I believe some have syscall emulation with each other. Like NetBSD I386 I think supports older I386 FreeBSD binaries. https://www.netbsd.org/docs/compat.html In general NetBSD/OpenBSD/FreeBSD share a lot of history, bits of design philosophy and collaborate on code but they all are developing quite differently in the various areas they specialize in. They all have their own unique kernel features with unique APIs for those differences. ---------------------------------------------------------------------- BumpitySnook · 2018-07-04 07:01 FreeBSD breaks syscall ABI compatibility with some regularity. Like Windows and unlike Linux, the compatibility layer is considered to be libc, rather than the syscall interface. ---------------------------------------------------------------------- ashemedai · 2018-07-04 11:41 Contrast e.g. [http://fxr.watson.org/fxr/source/sys/syscall.h](http:// fxr.watson.org/fxr/source/sys/syscall.h) to [http://fxr.watson.org/fxr /source/sys/syscall.h?v=OPENBSD](http://fxr.watson.org/fxr/source/sys/ syscall.h?v=OPENBSD) ---------------------------------------------------------------------- Kernigh · 2018-07-06 05:09 A file named `syscalls.master` defines the system calls in the BSD kernel. One such file in `src/sys/kern` may define the native system calls; other files may emulate systems like Linux. * [DragonFly BSD native](http://gitweb.dragonflybsd.org/dragonfly.git/ blob/HEAD:/sys/kern/syscalls.master) * [FreeBSD native](https://svnweb.freebsd.org/base/head/sys/kern/sysca lls.master?view=log) -- [emulating Linux/i386](https://svnweb.freebsd. org/base/head/sys/i386/linux/syscalls.master?view=log) * [macOS native](https://github.com/opensource- apple/xnu/blob/master/bsd/kern/syscalls.master) excluding Mach traps * [NetBSD native](http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/kern/sys calls.master?only_with_tag=MAIN) -- [emulating FreeBSD](http://cvsweb. netbsd.org/bsdweb.cgi/src/sys/compat/freebsd/syscalls.master?only_with _tag=MAIN) -- [emulating Linux/i386](http://cvsweb.netbsd.org/bsdweb.c gi/src/sys/compat/linux/arch/i386/syscalls.master?only_with_tag=MAIN) -- [emulating Linux/ppc](http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/c ompat/linux/arch/powerpc/syscalls.master?only_with_tag=MAIN) -- [emulating SVR4](http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/compat/sv r4/syscalls.master?only_with_tag=MAIN) * [OpenBSD native](http://cvsweb.openbsd.org/cgi- bin/cvsweb/src/sys/kern/syscalls.master) Different BSDs are incompatible. Newer calls like openat(2) tend to have a different number in each BSD, and thread operations are very different. Integer types like *time_t* and structures like *struct stat* can also be different. FreeBSD has more than 500 system calls, NetBSD more than 400, and OpenBSD only 330 (but OpenBSD has deleted calls and reused the numbers). You wouldn't emulate all of them; most programs don't configure network interfaces or mount filesystems. An emulation of OpenBSD would need to emulate weird calls like pledge(2) and sendsyslog(2), and handle PT_OPENBSD_RANDOMIZE segments in ELF files; an emulation of FreeBSD or NetBSD might be simpler. [An emulation of macOS](https://www.darlinghq.org/) would be difficult, needing both BSD system calls and Mach traps. ---------------------------------------------------------------------- staalmannen · 2018-07-06 05:52 awesome overview! Thanks! I think NetBSD would be the first one to try then (smaller than FreeBSD, avoiding the difficult syscalls from OpenBSD). First step is to get time enough to play with the original linux-abi and get it to work on a current kernel, however. For practice, I might then port the Plan9 syscall emulation from the glendix project to the updated linux-abi before doing something more difficult like NetBSD emulation. ---------------------------------------------------------------------- staalmannen · 2018-07-08 12:43 By the way - do you happen to have similar info for solaris/illumos? linux-abi had solaris emulation, so perhaps illumos in a chroot also would be possible :)