Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to windows-sys #21

Merged
merged 1 commit into from
Feb 6, 2024
Merged

Switch to windows-sys #21

merged 1 commit into from
Feb 6, 2024

Conversation

CryZe
Copy link
Contributor

@CryZe CryZe commented Jul 23, 2023

These are the official bindings that are maintained by Microsoft.

src/lib.rs Outdated
/// On Windows a `ProcessHandle` is a `HANDLE`.
#[derive(Clone, Eq, PartialEq, Hash)]
pub struct ProcessHandle(Arc<ProcessHandleInner>);

impl Deref for ProcessHandle {
type Target = RawHandle;
type Target = HANDLE;
Copy link
Contributor Author

@CryZe CryZe Jul 23, 2023

Choose a reason for hiding this comment

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

This changes the deref target, which means it's a breaking change. Considering there's no clear deref target anymore (windows-sys's HANDLE doesn't match RawHandle), there's three options:

  1. Making it deref to HANDLE
  2. Keep making it deref to RawHandle (requires a bunch of unsafe code and idk if it's safe)
  3. Remove the Deref impl altogether. The other platforms don't have it either

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for working on this. I'm inclined towards option 3 if we can verify that it doesn't break crates like remoteprocess. I don't have a Windows dev environment right now and will be depending on CI for testing, which I'll try to do soon.

(To connect a few dots, there's related discussion in #16 and #17.)

Copy link
Member

Choose a reason for hiding this comment

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

Logs from a remoteprocess build with Deref removed here (type ProcessHandle cannot be dereferenced). And from a build using the branch as-is here (expected *mut c_void, found isize). The latter might be a straightforward type conversion issue -- I'll try a few things.

Copy link
Member

Choose a reason for hiding this comment

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

Made progress. remoteprocess's CI passes with these changes. The cast is a bit ugly and makes me wonder if there's a way to smooth it out on the read-process-memory end.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have to slightly be honest in that I partially did the switch to windows-sys because the previous use of raw pointers meant that read-process-memory was not thread safe, so while investigating that, I noticed that windows-sys solved these problems automatically anyway. So switching back to raw pointers would be suboptimal for those reasons. Maybe it would need manual Sync / Send impls then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated windows-sys again, added an assertion for Send / Sync and removed the Deref now.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks. I should have time in the next couple of weeks to look at this again.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, I made a fresh branch for remoteprocess here (the CI failures are safe to ignore). If anything looks odd or unnecessary, let me know.

I think we need to keep the Deref, at least for now -- remoteprocess needs access to the handle so that it can call other Windows APIs directly.

The casts still feel somewhat clunky, but I think that's a quirk of the ProcessHandle type and doesn't need to hold this up. I'll do more testing and will merge if everything looks good.

These are the official bindings that are maintained by Microsoft.
@acj
Copy link
Member

acj commented Feb 6, 2024

Thanks for your patience. I'm going to merge this, add the Deref back in (to support remoteprocess), and then work on migrating to OwnedHandle which seems like a good fit for us.

@acj acj merged commit fe93cee into rbspy:master Feb 6, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants