News for hackers. Stuff that matters.
Re:liblinux: Architecture-independent access to Linux system... by matheusmoreira on Tuesday November 09, 2021 @08:47AM (#29161634)
With Linux, you can! I started this project years ago just to prove to myself that it was possible.

Every Linux process interfaces through the kernel via the system call interface. It is stable and language agnostic. The interface is defined at the processor architecture level.

https://github.com/torvalds/linux/blob/master/Documentation/...

https://man7.org/linux/man-pages/man2/syscall.2.html

Any compiler can emit this sort of code, including JIT compilers! It's possible to discard the entire C user space and rewrite everything in Rust. Would be a monumental effort but still.

Note that no matter what there will be at least one C library remaining: the vDSO the kernel maps into the address space of every process.

https://github.com/torvalds/linux/blob/master/Documentation/...

Re:liblinux: Architecture-independent access to Linux system... by remram on Tuesday November 09, 2021 @11:21AM (#29163743)
Isn't this the route Golang famously went, with poor results?

https://news.ycombinator.com/item?id=25997506

Apparently for BSD, the ABI is not that stable, glibc works around bugs on some platforms (adding memory barriers etc), and there are security features that check the origin of syscalls. I wonder whether this is truly acceptable on Linux...

Re:liblinux: Architecture-independent access to Linux system... by matheusmoreira on Tuesday November 09, 2021 @01:30PM (#29165413)
It is my understanding that Go attempted to perform direct system calls on systems where it was never supported. As a result, Go programs stopped working when the binary interface changed.

This is not a problem on Linux.

> glibc works around bugs on some platforms (adding memory barriers etc)

That's really interesting. Do you have examples of such fixes? I'm more familiar with musl sources, glibc proved to be somewhat difficult to navigate.

Re:liblinux: Architecture-independent access to Linux system... by lelanthran on Wednesday November 10, 2021 @01:44AM (#29171807)
> Any compiler can emit this sort of code, including JIT compilers! It's possible to discard the entire C user space and rewrite everything in Rust.

Well, yeah, but that's a tautology, no?

A willingness to discard everything indicates a willingness to rewrite everything. So, yeah, it is possible to rewrite everything if you are willing to rewrite everything.

Re:liblinux: Architecture-independent access to Linux system... by matheusmoreira on Wednesday November 10, 2021 @09:51AM (#29175187)
A willingness to discard everything doesn't mean you can actually do that though. Windows, for example, simply doesn't let you get rid of the Microsoft DLLs. You can't talk to the kernel directly, the interface will change and break your program. The BSDs and macOS all do the same thing.

Linux lets you do this. The interface is stable. People can build their custom user space on top of it and enjoy a great kernel full of drivers. Wouldn't it be amazing if someone came up with a 100% Lisp user space? A 100% Rust user space?

Re:liblinux: Architecture-independent access to Linux system... by lelanthran on Thursday November 11, 2021 @05:37AM (#29186529)
> Linux lets you do this. The interface is stable. People can build their custom user space on top of it and enjoy a great kernel full of drivers. Wouldn't it be amazing if someone came up with a 100% Lisp user space? A 100% Rust user space?

Great indeed (I like Lisp!), but I have to question how useful that would be in practice.

Let's take Lisp as an example: I can now program only in Lisp and talk to the OS in native Lisp only (including POSIX calls). The downsides are that I cannot call any existing library; my 100% Lisp environment cannot use libzip, or libffmpeg/libavutil, or libSDL, etc.

In order to make that 100% Lisp environment actually useful it's going to be doing FFI calls anyway into a C ABI. That makes the OS-interface redundant.

Python is as popular as it is purely because it made calling into the C ABI easy: existing libraries were made instantly useful in Python, not unnecessarily hard.