Skip to content

Conversation

@CraftSpider
Copy link
Contributor

No description provided.

@rustbot
Copy link
Collaborator

rustbot commented Dec 19, 2025

Thank you for contributing to Miri! A reviewer will take a look at your PR, typically within a week or two.
Please remember to not force-push to the PR branch except when you need to rebase due to a conflict or when the reviewer asks you for it.

@rustbot rustbot added the S-waiting-on-review Status: Waiting for a review to complete label Dec 19, 2025
"*const _" => $this.machine.layouts.const_raw_ptr.ty,
"*mut _" => $this.machine.layouts.mut_raw_ptr.ty,
ty if let Some(libc_ty) = ty.strip_prefix("libc::") => $this.libc_ty_layout(libc_ty).ty,
ty if let Some(win_ty) = ty.strip_prefix("winapi::") =>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is shorthand for a longer path used by the windows_ty_layout function, I thought this made usage a lot nicer and more readable.

getrandom_01::getrandom(&mut data).unwrap();

// TODO: getrandom 0.2 uses the wrong return type for BCrypteGenRandom
#[cfg(not(target_os = "windows"))]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.2 uses u32 for the return type, not i32. We now check this and report UB. Is this worth reporting upstream for a backport?

} else {
CanonAbi::C
};
// TODO: Use this in shim-sig instead of 'system'? Or is that good enough for ExternAbi?
Copy link
Contributor Author

@CraftSpider CraftSpider Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drawing attention to this - no tests are failing, but I need to double check whether this works, or if I need to make the shim_sig macro support dynamic ABIs.

let [token, buf, size] =
this.check_shim_sig_lenient(abi, sys_conv, link_name, args)?;
let [token, buf, size] = this.check_shim_sig(
shim_sig!(extern "system" fn(winapi::HANDLE, *mut _, *mut _) -> winapi::BOOL),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General note - I preferred using fundamental types in most places, but I left a couple fundamental windows API types as their winapi::* variants, for clarity or because they have somewhat odd Rust representations.

  • BOOL: Actually an i32, which is unexpected to most not familiar with it.
  • HANDLE: This has switched between isize and *mut _ in the past, and many Windows shims actually treat it as its own special thing.
  • HLOCAL and HMODULE: Aliases for HANDLE, but with the implication they represent only certain types of handle.
  • FARPROC: Actually Option<extern "C" fn()>. Much easier to load the resolved layout of that, instead of trying to add Option and fn special-cased to shim_sig_arg.

I can swap some of these to their literal representations if preferred, it may be a bit more performant, but it also may be worth adding caching to the *_ty_layout functions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add that a HLOCAL is a pointer to memory allocated by LocalAlloc and HMODULE is a pointer to a module's base address. Neither of these are handles in the same sense as HANDLE is despite being defined as a type alias (which is why they can't be passed to normal handle functions).

let [_First, _Handler] =
this.check_shim_sig_lenient(abi, sys_conv, link_name, args)?;
let [first, handler] = this.check_shim_sig(
shim_sig!(extern "system" fn(u32, *mut _) -> *mut _),
Copy link
Contributor Author

@CraftSpider CraftSpider Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I standardized all the names. I can undo this if desired, it just seemed like a good drive-by since most stuff uses Rust-style names, not the Windows API names.

@rustbot
Copy link
Collaborator

rustbot commented Dec 19, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Waiting for a review to complete

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants