News for hackers. Stuff that matters.
Re:In C, how do you know if the dynamic allocation succeeded? by one_off_comment on Friday November 05, 2021 @04:03PM (#29124125)
There's gotta be some way to programmatically determine it, right? It may not be portable. It may require some system calls or something, but there's gotta be a way, right?
Re:In C, how do you know if the dynamic allocation succeeded? by wmf on Friday November 05, 2021 @04:18PM (#29124292)
I guess you could mlock() your memory and see if that succeeds or fails. When overcommit is enabled no memory is really safe.
Re:In C, how do you know if the dynamic allocation succeeded? by matheusmoreira on Friday November 05, 2021 @10:33PM (#29127016)
Maybe a system call that checks whether writing to a page would result in a fault? What if we had memory file descriptors for pages? We'd be able to use them with epoll and io_uring to asynchronously check whether it's safe to write to the pages they represent.
Re:In C, how do you know if the dynamic allocation succeeded? by yjftsjthsd-h on Friday November 05, 2021 @04:22PM (#29124335)
I'm not an expert enough to tell you; I just read the article and decided that it was too long so summarized for others. There's some discussion upthread about catching SIGSEGV and other methods, FWIW.
Re:In C, how do you know if the dynamic allocation succeeded? by TillE on Friday November 05, 2021 @07:23PM (#29125797)
The question is what problem are you actually trying to solve.

You can get away with just about anything if you do it in a child worker process which can safely crash.