Live data from Hacker News

Rewrite Linux Kernel in Rust?

dominuscarnufex.github.io

81–90 of 133 posts

Re: Rewrite Linux Kernel in Rust?

#81

Earlier quoted context omitted.

You need to explicitly specify what the parameter sizes and types are. Plus, the parameters are backwards compared to Intel syntax: Intel: mov eax, 5 AT&T: movl $5, %eax In basically every C-like programming language, you assign 5 to eax with `eax=5` not `5=eax`. I can also tell that I'm working with the `long` variant of `mov` just by looking at the types involved. Intel's syntax for memory access seems more natural…

Makes you wonder why not write it as e.g. "eax mov 5" or even "eax = 5".

I've seen assembly languages that do separate target and source operands with an = sign. So you would write that something like:

    mov eax = 5
and use a similar style for other things, like:

    add eax = ebx, ecx
This is very nice and clear. But it only really works for three-address assembly languages, i.e., where the target register may be different from the sources. In classical x86, the target of an add is identical to one of the operands. So you would need something like

    add eax += ebx
or

    add eax = eax, ebx
where you must duplicate a register. Presumably when these assembly languages were developed 40 years ago, this was perceived as too much syntax.

Re: Rewrite Linux Kernel in Rust?

#82

It would cease to be Linux, but by all means -- make it so! BTW Redox OS (written in rust) originally supported Linux syscalls which I thought was a super cool feature. Jorge Aparicio started steed, a libc implemented in rust for rust. It seems like a pretty interesting approach.

Author said:

Thank you. Actually, I have a series of articles about a libc written in Rust for Rust which I started writing before steed was published, and… isn’t finished yet. :-/ But maybe, I will finish and publish it eventually…

Re: Rewrite Linux Kernel in Rust?

#83

It's a fun idea and many people have had it first thing when they heard of Rust... So why did no one do it? Quite simply: No one is going to rewrite the Linux Kernel in Rust. It is far too big and also you are not solving any real issues either. Rust only protects you from a small fraction of errors and while for an application like a browser, this can be a big gain, I would argue that it is negligible for a kernel i…

Isn't that what Redox-OS [1] does? Though it is not fully POSIX compliant for decisions the development team made.

[1] https://www.redox-os.org/

Re: Rewrite Linux Kernel in Rust?

#84
post #80
post #69

Earlier quoted context omitted.

What. When did `mov` get 96 different instructions?

I think it's just a bit of hyperbole. I don't know enough of this to know whether http://c9x.me/x86/html/file_module_x86_id_176.html is complete, but it gives you a sense of it all. (also https://www.cl.cam.ac.uk/~sd601/papers/mov.pdf if you haven't seen it)

Huh, interesting.

Apparently there are 35 rows in the table at http://www.felixcloutier.com/x86/MOV.html (according to Chrome and `$0.childElementCount`). I only discovered gcc.godbolt.org links to documentation via context menu just the other day!

Regarding the PDF... ouch. Wonder if any executable obfuscators have tried that approach :P (and I also wonder what sort of overhead it has.)

Re: Rewrite Linux Kernel in Rust?

#85
I guess one of the things that always comes to mind when someone brings up "Rust all the things" is that it assumes that anything that can be expressed in C can be expressed in Rust with the safety features enabled. Rust wouldn't have a mechanism to do unsafe code otherwise, right? I think it might be more complicated than we might think initially.

I personally think that someone should probably spend some more time on GC that's performant enough for systems code. My convictions haven't driven me to do anything about it, however.

Re: Rewrite Linux Kernel in Rust?

#86

It's a fun idea and many people have had it first thing when they heard of Rust... So why did no one do it? Quite simply: No one is going to rewrite the Linux Kernel in Rust. It is far too big and also you are not solving any real issues either. Rust only protects you from a small fraction of errors and while for an application like a browser, this can be a big gain, I would argue that it is negligible for a kernel i…

Once Rust has been available as the main attack surface in a browser for several rounds of "pwn-to-own" I think people will come to grips with it not being a magic bullet.

I think you are right about the Qubes approach. Microsoft has started adopting that model in Windows. They started by moving parts of LSASS to a compartmentalized trusted code base in a VM. (Credential Guard). I think the next thing is actually running Edge with some hypervisor protections. Can't remember the feature name, though.

But that kind of thing is the future. You have to assume that things will be breached and deal with that upfront.

Re: Rewrite Linux Kernel in Rust?

#87

Earlier quoted context omitted.

Thank you. I was just reading your comments and found this one: >Erlang: the general disinterest of Ericsson and the hapless stewardship​ of Erlang Solutions. Is that related to the reason that BEAM is no longer part of your day job? The reason I ask is that I am thinking of starting a new project with BEAM, maybe some Rust or C++ and wondering whether Elixir has taken over from Erlang due to the disinterest of Erics…

Nope, not the reason. My "go-to" language when prototyping most things is still Erlang. Erlang is by far my favorite language and environment to use, and for a whole slew of things I'd still grab it for production projects/products. I moved into the world of autonomous vehicle runtime software, and tools closer to the metal with deterministic timing characteristics are a requirement.

What is it about Rust that helps with the deterministic timing thing you mentioned? Just not having a GC? Do you still use C or C++?

Re: Rewrite Linux Kernel in Rust?

#88
post #76
post #51

I'd rather see a rewrite of QNX in Rust, as open source. The QNX kernel isn't very large, but it offers most of POSIX, so you can run programs on it. (L4 is nice, but it does so little that people just use it as a hypervisor to run Linux. This doesn't simplify the problem.) If you rewrite the Linux kernel in Rust, one module at a time, you'll just end up with C written in Rust syntax, with raw pointers all over the p…

QNX is also realtime. In order to provide realtime guarantees that cover small latencies, you need infrastructure that generates as few instructions as possible. (If you have lots of instructions you can hit targets of a hundreds of microseconds since you can just wait. Start inching toward nanoseconds, though, and the scheduler's own execution will get in the way unless it's crazy compact.) The reason I mention this…

   What's Rust like in ...
Isn't that less a question of Rust (which due to its affine types, should be usable for generating code with predictable performance) but of compilers? It should be possible to write a Rust compiler that optimises for predictable performance at the cost of speed.

Re: Rewrite Linux Kernel in Rust?

#89
post #88
post #76

Earlier quoted context omitted.

QNX is also realtime. In order to provide realtime guarantees that cover small latencies, you need infrastructure that generates as few instructions as possible. (If you have lots of instructions you can hit targets of a hundreds of microseconds since you can just wait. Start inching toward nanoseconds, though, and the scheduler's own execution will get in the way unless it's crazy compact.) The reason I mention this…

What's Rust like in ... Isn't that less a question of Rust (which due to its affine types, should be usable for generating code with predictable performance) but of compilers? It should be possible to write a Rust compiler that optimises for predictable performance at the cost of speed.

That's a fair point.

I don't quite follow why speed needs to be sacrificed to get predictable performance though.

And I don't know about writing a (whole new?!) Rust compiler (!) - if the current Rust compiler wouldn't be a good fit for this purpose, well, I definitely don't have the resources to anything about that, considering the unbelievable amount of attention to detail and wrangling that's gone into getting rustc to where it is today.

Re: Rewrite Linux Kernel in Rust?

#90
>Rewrite Linux Kernel in Rust? Rust has no backward compatibility: C code compiles fine after decades. It would be a waste of time to rewrite Linux in Rust when the resulting code has a lifetime of few months until it won't compile and start breaking everywhere.
Post reply on HN