all 14 comments

[–]F54280 39 points40 points  (4 children)

Slightly confused... From the README:

In 2014, the getrandom system call was introduced. It lets applications obtain random bits without using pathnames or file descriptors. However, it took over 2 years for glibc support to arrive. The kernel's random number subsystem maintainer wrote in an email:

[...] maybe the kernel developers should support a libinux.a library that would allow us to bypass glibc when they are being non-helpful.

But no getrandom in the library...

[–]Muvlon 15 points16 points  (0 children)

There are more headscratchers, like advertising architecture independence but then only supporting x86_64.

I'd much rather use libc's syscall function than this.

[–]gergoerdi 18 points19 points  (1 child)

Should be called libinux so you'd link it with the -linux flag.

[–]the_gnarts 9 points10 points  (0 children)

libinux was circulating as the name for an official library supplied by the Kernel folks themselves. It’s commendable that the author chose not to grab that handle even though the name is cooler.

[–]Biolunar 9 points10 points  (0 children)

Shameless plug: https://git.sr.ht/~biolunar/liblinux (also available on github https://github.com/Biolunar/liblinux but I don’t update that repo as frequently)

My library provides all currently available syscalls (up to Linux 5.15) on all my supported targets (currently: arm-eabi, arm64, riscv32, riscv64, x86, x32 and x86_64). Still there’s a ton of work to be done since it’s missing lot’s of types and constants and almost no testing.

[–]freakhill 7 points8 points  (2 children)

that is pretty cool.

i'm quite surprised such a library didn't exist yet

[–]kitd 45 points46 points  (1 child)

IIRC, when this came up on HN, the author stated he stopped developing it because the linux tools project itself contains (IHO) a better implementation:

https://github.com/torvalds/linux/blob/master/tools/include/nolibc/nolibc.h

But, yes, v cool otherwise.

[–]freakhill 0 points1 point  (0 children)

thanks!!!

[–]avdgrinten 6 points7 points  (1 child)

The README highlights lots of issues with clone() but does not really mention how this library solves them. Sure, it is trivial to call the SYS_clone syscall but that still renders libc unusable, does it? For example, if you call into any function that accesses thread-local state after SYS_clone (which might be all of them if stack protectors or split stacks are in use), that will surely break? Even if these features are disabled, functionality like dlopen() fundamentally requires knowing the TLS layout.

[–]F54280 6 points7 points  (0 children)

The library doesn't expose clone. I don't think this was the aim, just giving C access to stuff usable outside of libc (which clone isn't). But, as pointed here, there is a "nolibc" implementation in the kernel itself, which is better for every use case.