by pizza234 · 4y ago · 0 comments
This is not well-written Rust; code like the below actually defeats the purpose of using Rust, and without any specific reason for doing so.
I personally discourage people from using this software.
static mut KEYBOARD_HOOKED: bool = false;
fn start_keyboard_hook(&self) {
if unsafe { KEYBOARD_HOOKED } {
return;
}
}
The build even requires an assembler (NASM), which is odd, in this context.Edit: Further, there's no such thing as "the purpose of using Rust". Different users can use the same tool for different purposes, and Rust is no different.
To keep in mind, on a pragmatic level, that this type of global can be trivially implemented, at a minimum, via atomics, so the cost to avoid the unsafe is near-zero.
Atomics are not supported by all the platforms, but based on my understanding of their targets (x86-64), they're supported.
AFAIK on any typical platform there's no way you'd have "tearing" for a single byte ie: this will never store an invalid boolean representation.