Thread #108582499
File: 1741747320342433.jpg (62.4 KB)
62.4 KB JPG
previous: >>108572928#define __NR_mlock 149
#define __NR_munlock 150
#define __NR_mlockall 151
#define __NR_munlockall 152
#define __NR_mlock2 325
https://man7.org/linux/man-pages/man2/mlock.2.html
tl;dr:
lock/unlock memory
by lock, we mean keep the memory pinned into RAM and prevent it from being swapped out
for once, i'm actually really happy with these syscalls. super nice change of pace. having to have a v2 of something isn't ideal, of course, but i'm still of the opinion that these syscalls in particular are really well designed. i think the flags are clear, sane, and useful. so i'm actually quite impressed. kudos to the developers on this one
interestingly, this syscall is one of the very few realistic ways for a developer to cause calls to malloc to fail. if you've never played around with it, it's actually surprisingly difficult to make that happen lol. so that's a neat piece of trivia
the notes section is also pretty good. very nice writeup on the "why" for these syscalls, as well as potential footguns, etc.
god this really is a breath of fresh air. more syscalls need to be like this...
relevant resources:man manman syscalls
https://man7.org/linux/man-pages/
https://linux.die.net/man/
https://elixir.bootlin.com/linux/
https://elixir.bootlin.com/musl/
https://elixir.bootlin.com/glibc/
24 RepliesView Thread
>>
>>
>>108582536
oh, no, mmap has MAP_POPULATE, MAP_FIXED, etc.
https://man7.org/linux/man-pages/man2/mmap.2.html
i meant literally malloc(3) itself, not the syscalls it uses
>>
>>
>>108582644
cause malloc to fail with this?If MCL_FUTURE has been specified, then a later system call (e.g.,
mmap(2), sbrk(2), malloc(3)), may fail if it would cause the
number of locked bytes to exceed the permitted maximum (see
below). In the same circumstances, stack growth may likewise
fail: the kernel will deny stack expansion and deliver a SIGSEGV
signal to the process.
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>108584442
>>108584454
>>108584412
eBPF kernel mixer when
>>
>>
>>
>>
How is kernel and system programming in rust like compared to c #include <sys/header>?
Does it end up invoking the same syscalls in the kernel. And if that’s the case, rust essentially being a wrapper around syscalls, why should I use rust?
>>
>>108586266
>Does it end up invoking the same syscalls in the kernel.
I think the most straightforward way is to just use bindings to libc
low level rust is surprisingly similar to C
>why should I use rust?
I might be weird, but I really like sumtypes+tuples+match statement
the stdlib is also miles better than libc