Losing the magic
Losing the magic
Posted Dec 6, 2022 18:47 UTC (Tue) by khim (subscriber, #9252)In reply to: Losing the magic by Wol
Parent article: Losing the magic
> In other words, with C's assumption that UB is impossible, we now have a conundrum if we want to write Operating Systems in C!
Why would it be so? There are lots of art built around how can you avoid UBs in practice. Starting from switches which turn certain UBs into IBs (and thus make them safe to use) to sanitizers which [try to] catch UBs like race conditions or double-free or out-of-bounds array access.
If you accept the goal (ensure that your OS doesn't ever trigger UB) there are plenty of ways to achieve it. Here is an interesting article on subject.
I, personally, did something similar on smaller scale (not OS kernel, but another security-critical component of the system). Ended up with one bug in 10 years system was in use (and that was related to problem with specification of hardware).
But if you insist on your ability to predict what code with UBs would do… you can't write Operation System in C that way (or, rather, you can, it's just there are no guarantees that it will work).
> Which has been my problem ALL ALONG. I want to be able to reason, SANELY, in the face of UB without the compiler screwing me over.Not in the cards, sorry. In you code can trigger UB then the only guaranteed fix is to change code and make it stop doing that.
> If that's an O_PONY then we really are fscked.Why? Rust pushes UBs into tiny corner of your code and there are already enough research into how we can avoid UBs completely (by replacing these with markup which includes proof that your code doesn't trigger any UBs). Here is related (and very practical) project.
Of course even after all that we would have issue of bugs in hardware, but that's entirely different can of worms.
