Skip to content

Comment on The next operating system: building an OS for hundreds, thousands of coresparent

Comments

Therefore you need hardware hacks (MMU) to separate processes

I cannot apprehend the confusion of ideas that would lead you to believe this is caused by C. It's assembly, not C, that runs on your machine, and assembly is not memory safe. Microsoft's Singularity runs managed code, so there's a software layer providing memory protection.

An operating system is not defined by its preferred programming language.

"I cannot apprehend the confusion of ideas that would lead you to believe this is caused by C. It's assembly, not C, that runs on your machine, and assembly is not memory safe"

There is no confusion of ideas, but I like the Babbage reference :)

In Singularity the code is compiled first to CIL, then to x86, x64, or ARM by an AOT (ahead-of-time) compiler. Now here's the thing: the OS loader does not load Assembly code, it loads CIL code, which it then compiles further down to Assembly. Since CIL is verifiably memory safe (like Java bytecode), and assuming the AOT compiler is not buggy, the OS is memory safe. Hence no need for MMU/MPU to do memory protection.

So even though you're right that Assembly is not memory safe, the final compiler stage (in this case CIL can be seen as an intermediary language) is implemented in the OS (the loader), and the OS will reject any non-memory safe code. No code that can write outside array boundaries, violates type safety, and attempts pointer arithmetic will be allowed to execute.

So no, Singularity does not provide a software layer for memory protection, it's purely an (intermediary) language feature.

The software layer for memory protection here is the AOT compiler. As you alluded to yourself, if Mark Dowd finds one of the bugs in your AOT compiler, then you are toast.

The nice thing is that these protections can be applied ahead-of-time rather than at runtime, as the MMU does.

It has been shown (see Native Client) that even a slightly restricted subset of x86 assembler can be made verifiably-safe. In principle, you could do the same thing with C - in fact, you likely wouldn't even have to change the language definition, since the egregious abuses in C mostly result in "undefined behaviour", which allows the implementation to detect and trap them rather than hose the machine. (It is a curious fact that C itself isn't inherently "memory unsafe" - merely almost every implementation of C ever written is).

People have attempted to make C memory safe (i.e. bitc, cyclone), so you could write an OS in that, I guess. My original point however was that C itself is not, and that supporting C means supporting non-memory safe drivers, services, and programs.

If you can come up with a program that verifies whether a C program is memory safe or not (without constraining the language spec), well, hats off to you sir, I think I know a couple of security experts who might want to have a word with you :)

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.