[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology

Name
Options
Comment
Verification
4chan Pass users can bypass this verification. [Learn More] [Login]
File
  • Please read the Rules and FAQ before posting.
  • You may highlight syntax and preserve whitespace by using [code] tags.

08/21/20New boards added: /vrpg/, /vmg/, /vst/ and /vm/
05/04/17New trial board added: /bant/ - International/Random
10/04/16New board for 4chan Pass users: /vip/ - Very Important Posts
[Hide] [Show All]


[Advertise on 4chan]


File: 1741747320342433.jpg (62 KB, 736x540)
62 KB
62 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 man

man 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/
>>
>>108582499
>interestingly, this syscall is one of the very few realistic ways for a developer to cause calls to malloc to fail
There's no equivalent of VirtualAlloc with MEM_COMMIT on Linux?
>>
>>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
>>
>>108582561
Oh, okay. How do you do it?
>>
>>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.
>>
>>108582499
>v2 of something isn't ideal
BSDs wouldn't have messed up the first time btw
>>
>>108582702
>then a later system call
>e.g. malloc(3)
That's a strange thing to write in a man page. Is this glibc-specific?
>>
>>108582742
i also noticed that lol
it's technically slightly incorrect, but malloc calls one of the first two under the hood, so i can forgive it
>>
No usecase.
>>
>>108583191
cryptography
>>
>>108583264
Encrypt your swap.
>>
>>108582536
You could enable overcommit and then use PROT_NONE to reserve VAS without your commit charge going up.
>>
>>108583369
>enable
Errr, disable.
>>
>>108582499
me on the right



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.