News for hackers. Stuff that matters.
Re:In C, how do you know if the dynamic allocation succeeded? by tsimionescu on Saturday November 06, 2021 @01:06AM (#29127676)
> Don't allow it. Fork the process with read only pages except for the ranges passed to fork().

This doesn't work because of the horrible fork/exec design. If I am a huge process and I want to run `ls`, I will first have to clone myself using fork(), which may trigger an OOM, even if the first action of my clone would have been exec(), ignoring all of that memory.

I am always surprised that no one has added a sane 'spawn process' primitive to replace fork/exec. Especially since fork() without exec() only really works in single-threaded processes.

Re:In C, how do you know if the dynamic allocation succeeded? by naniwaduni on Saturday November 06, 2021 @01:22AM (#29127739)
We do have posix_spawn &c., which are expressly designed to be implementable even in situations where fork doesn't make sense.
Re:In C, how do you know if the dynamic allocation succeeded? by tsimionescu on Saturday November 06, 2021 @01:50AM (#29127857)
Interesting, I'd never learned about that. If I understand correctly, this actually used to be implemented as a fork()+exec() on many systems, though. It's actually vfork() that addressed the problem and allowed an actually useful implementation of posix_spawn in Linux at least.