7,318 karma · joined August 5, 2017
[0]: https://doc.rust-lang.org/std/cell/struct.UnsafeCell.html
rustc hello.rs -C panic=abort -C opt-level=3 -C link-args="/ENTRY:main /DEBUG:NONE /EMITPOGOPHASEINFO /EMITTOOLVERSIONINFO:NO /ALIGN:16" rustc hello.rs -C panic=abort -C opt-level=3 -C link-arg=/entry:main
Here's the program: #![no_std]
#![no_main]
#[panic_handler]
fn panic_handler(_panic: &core::panic::PanicInfo<'_>) -> ! {
unsafe { ExitProcess(111) };
}
#[no_mangle]
pub extern "C" fn main() -> u32 {
let msg = b"Hello, world!\n";
unsafe {
let stdout = GetStdHandle(-11);
let mut written = 0;
WriteFile(
stdout,
msg.as_ptr(),
msg.len() as u32,
&mut written,
core::ptr::null_mut(),
);
}
0
}
#[link(name = "kernel32")]
extern "system" {
fn ExitProcess(uExitCode: u32) -> !;
fn GetStdHandle(nStdHandle: i32) -> isize;
fn WriteFile(
hFile: isize,
lpBuffer: *const u8,
nNumberOfBytesToWrite: u32,
lpNumberOfBytesWritten: *mut u32,
lpOverlapped: *mut (),
) -> i32;
}
I didn't bother much with the panic handler because there's no reason to in hello world. Though the binary contains a fair bit of padding still so it could have a few more things added to it without increasing the size. Alternatively I could shrink it a bit further by doing crimes but I'm not sure there's much point.It may be worth noting that the associated pdb (aka debug database) is 208,896 bytes.
This can be useful up to a point. But be careful of over optimizing for the pathological case at the expense of typical usage. Most of the listed operations are usually done on a small number of files. And even when they seem a lot to the user it's still a teeny tiny fraction of one billion.
And that's before we even mention directories.
Related reading: Lexical File Names in Plan 9 or Getting Dot-Dot Right (https://9p.io/sys/doc/lexnames.html)
Yeah, if I recall, once you figure out all its mechanics you are able to hack anything in about a month of game time. This is marvelous once but obviously does hurt replayability.
It is fun to think I can never really replay uplink, short of some rather severe amnesia.
> Note that everywhere we refer to HashMap is actually an alias for fxhash::FxHashMap, which is just std::collections::HashMap with a more efficient hashing algorithm
Many OSes have file locks, though they often don't use them as liberally as Windows.
While full Unix-like behaviour is only available on Windows 10 for the past five or so years, you can still have the old win32 behaviour on older systems (delete once the last file handle is closed).
I guess they could do this more robustly. I.e pause the entire explorer process, save all its state, remotely allocate new memory to inject their code, remotely create a new thread, run only that thread using the injected code, restore all the process' state and finally start it running where it left off. A script would be easier though.
E.g. `powershell.exe -ExecutionPolicy Unrestricted`
Edit: since there still seems to be confusion I'll try to be clearer. On NTFS you can delete an open file. This is a solved problem. The DeleteFile API even does this by default now. The thing that prevents deletion is an OS lock. This lock only prevents deletion. Renames are still allowed.
[0]: https://github.com/Turbo87/rust-rfcs/blob/crates-io-policy-u...
And I think your overstating the contract argument. If `ls` changed its output format in any way (unless behind a flag) it'd break a heck of a lot of bash scripts. With a well structured output format it's better able to maintain backwards compatibility while adding new features.
The key thing is you can set the parameters so that whatever you're selling happens to fall squarely in the middle. And of course anything can be common sense so long as you can successfully ridicule the alternatives and describe your solution in a way that sounds plausible(ish).
[0]: https://stackoverflow.com/questions/23086038/what-mechanism-...
(btw most IT folks prefer powershell, if only because all the management tools are powershell modules)