8 ms·
System programming in Rust: beyond safety
- rnestler 9y agoThere was a small discussion about it on the Rust reddit: https://www.reddit.com/r/rust/comments/6h5mht/system_programming_in_rust_beyond_safety_the/ https://www.reddit.com/r/rust/comments/6h5mht/system_program...
- tom_mellior 9y ago... a large part of which was just responses to one person who said "OMG, you can't write a kernel in Haskell, it uses malloc", as if (a) Linux didn't have its own kmalloc, and (b) a hypothetical Rust kernel wouldn't use malloc.
- frankmcsherry 9y agoIn the event that anyone isn't clear on the relative quality of discussions across various websites, please click the reddit link and observe someone asking a sincere question and getting specific and helpful responses, with no attempt to score points by misrepresenting the position of the others.
- nickpsecurity 9y agoInspired by that response, I shared a Haskell OS and Ocaml on PIC microcontrollers. https://www.reddit.com/r/rust/comments/6h5mht/system_programming_in_rust_beyond_safety_the/dixwwz7/?st=j3yku1pg&sh=ba31b3dd https://www.reddit.com/r/rust/comments/6h5mht/system_program... Not a wasted question after all given prior, positive feedback on those projects.
- hashhar 9y agoThat is a very good question for someone new to the field and the answer is really well detailed. Honestly, as of right now the discussion there is more enlightening than here.
- tom_mellior 9y agoI agree that in a thread about Rust systems programming, asking how Rust (and, come to think of it, Haskell) can do dynamic allocation on the bare metal is a good question. I think the good underlying question was devalued by what I think was the poster's lack of reflection. Obviously Rust can do it because Rust is magical, but Haskell? How would that ever work? Your interpretation may vary.
- hashhar 9y agoWith the added context your original comment makes more sense to me. Also, now this thread is better than the one over on Reddit.
- empath75 9y agoThis is more interesting than the standard Rust article about borrowing and lifetimes, and is more about how linear types can be used to enable new safety features easily.
- doody12 9y agoI think one of the big issues with Rust is that it isn't as portable as C. Bootstrapping Rust is hard, doing the same for C is simple. I could create a simple C compiler just to bootstrap the real C compiler, something I have actually done once or twice before. That's not something you do with Rust, at least from the limited experience I have with Rust.
- jjnoakes 9y agoI agree, and this is the only thing stopping me from putting rust into production. I have high hopes for something like https://github.com/thepowersgang/mrustc https://github.com/thepowersgang/mrustc
- steveklabnik 9y agoWhat architectures matter to you?
- jjnoakes 9y agoOf all the architectures I contract for, I think AIX is the one furthest behind as far as LLVM and Rust support goes.
- nickpsecurity 9y agoIs there an ISA call AIX or did you mean platform support for AIX operating system on POWER?
- jjnoakes 9y agoI mean AIX on Power (BE).
- steveklabnik 9y agoCool thanks, always trying to hear what we need to work on.
- 9y ago
- gens 9y agoC is not only better for performance, but also because you simply can not do some things in most other languages. Rust lacks bitfields, for one. But the bigger thing are pointers. AFAIK you can not do type punning in rust, and i don't know if you can do other pointer plays. (note that pointers are barely even mentioned in this blog post) IMO rust is a replacement for C++, not for C. C is much closer to assembly then most all other languages, especially those that deal with memory allocation natively.
- steveklabnik 9y agohttps://crates.io/crates/bitflags https://crates.io/crates/bitflags Rust's raw pointers have equivalent power to C's pointers.
- gens 9y ago>https://crates.io/crates/bitflags https://crates.io/crates/bitflags Not native, see C. >Rust's raw pointers have equivalent power to C's pointers. Again, AFAIK you can't do type punning. That wasn't even my point, that was that C gives you almost everything a cpu does and not much more.
- steveklabnik 9y agoWhat does "native" mean, built into the language? Why does it matter? I suspect it's the same with type punning (though also, to some degree because we're still working out the details of what exactly the semantics of unsafe are.) In the end, you can always cast stuff to bytes and then cast those bytes to something else. I don't take (too much) objection to that, and little with "not much more", but that doesn't mean that C has some secret stuff that only C can do, which it feels like you're implying.
- gens 9y ago>What does "native" mean, built into the language? Why does it matter? I don't know how that macro works, but in kernel C bitfields are used in structs that map to device registers (that are mapped to memory). >I suspect it's the same with type punning (though also, to some degree because we're still working out the details of what exactly the semantics of unsafe are.) In the end, you can always cast stuff to bytes and then cast those bytes to something else. So if i want to store a series of things with random (length) types in a single array, i can ? Sounds like i can, even though you explained the simpler case. >I don't take (too much) objection to that, and little with "not much more", but that doesn't mean that C has some secret stuff that only C can do, which it feels like you're implying. And for the third (edit:second) time, that is not my point. Thing is that C does not have "secret stuff" and rust does. In C you get what you wrote, and not much more. There is no need for telling the compiler to not do some checking or to not make a copy of something. (edit2: granted, bitfields are not native to cpus as type punning is) Rust, IMO, is more for the C++ crowd then C. And those two are very different.
- verytrivial 9y agoI look forward to more "Rust proved to be great to implement this real feature/system/OS, here it is!" posts and fewer "Why you/someone else should use Rust for feature/system/OS instead of your awful and dangerous language, sneer!" (The people at redox-os.org are doing great work here I think)
- maxxxxx 9y agoThat would help a lot. I agree.
- Ar-Curunir 9y agoThis post is exactly the kind of post you're looking for then?
- bluejekyll 9y agoIf you're interested in seeing a lot of posts about projects people are working on in Rust, I highly recommend https://www.reddit.com/r/rust/ https://www.reddit.com/r/rust/ Lots of great discussion on new tools, libraries, etc.
- dbaupp 9y agoGenuine question: when was the last article to "sneer" on HN? There was the Linux kernel one a few weeks ago, but the meat of that that was more actual code proving that Rust worked in practice to replace a section of a large existing code base, rather than abstract sneering. It seems like the thing that happens most often is people complaining about "RiiR" and "RESF" etc, rather than the actual annoying things those refer to, so much so that it has become a self-perpetuating meme seizing upon the smallest hint of the bad behaviour.
- jeffdavis 9y agoRust actually seems to have a healthy balance of "this is promising" and "this actually works", especially given the age of the language. Just experimenting myself, but I've had a positive experience so far.