233 points · by 0xedb · 4y ago · 91 comments
IIRC `#[naked]` are only really guaranteed to allow inline assembly, so it's like defining a function in `global_asm!` except for monomorphization and generally interfacing better with the rest of the language.
I think the biggest missing features are the more exotic, non-register constraints, but some of the reasons those are omitted are because of unclear coordination between Rust code and the assembly language string.
It sends a signal to everybody that language correctness takes precedence over this extremely important feature that more developers depend on than the new features in the release, instead of treating the two with the same seriousness.
https://play.rust-lang.org/?version=stable&mode=debug&editio...
struct Helper<B: Buffer> { x: [u8; B::SIZE], }
http://venge.net/graydon/talks/intro-talk-2.pdf
> Rust is a language that mostly cribs from past languages. Nothing new
[…]
> Rust picks from 80s / early 90s languages
> inout(reg) a,
inout looks like a function but I don't see how that works with the `a` variable. Is this some magic specifically for asm!?
Rust's standard library provides std::fs::remove_dir_all("/some/dir"), in C++ you will find the very similar std::filesystem::remove_all("/some/dir")
As you might anticipate, these functions get rid of the directory /some/dir if necessary deleting sub-directories and files recursively in order to achieve that.
They both explain that they won't delete other things, even if there's a symlink in /some/dir or some child that points to those outside things, the symlink gets deleted but not the thing it pointed to.
What kind of terrible unsafety was discovered in CVE-2022-21658?
Until Rust 1.58.1 you could exploit a TOCTOU race condition to blow away other people's stuff using symlinks when they made this call.
And where is the CVE for the same bug in C++? There isn't one. C++ standards people argued that the C++ standard already actually says that none of their filesystem API is safe to use if you have a "concurrent environment" in which such races are possible. Standard C++ programs are only intended to run on a machine where they have exclusive control over the entire system for the entire length of their runtime and so when your C++ program deletes files you thought it couldn't delete that was actually your fault for not being familiar with every caveat and ruling in the entire C++ standard.
What should you do about that? I believe the answer is obvious: Use Rust
Regarding memory safety, C++ says: "It's your fault if you get it wrong." Rust says: "It's our fault if we get it wrong in safe code." There is an enormous qualitative difference (in terms of ease of programming) and quantitative difference (in terms of number of bugs) between the two.
Yet, here it is. I was not fooled, but the attitude left a deep impression.
It was not my proposal, and I was not persecuted, so that projection is pure fantasy.
Besides, C++ ships features at a glacial pace compared to Rust, so I'm not sure what your point is.