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

Win32 cwd #267

Merged
merged 5 commits into from
Apr 8, 2021
Merged

Win32 cwd #267

merged 5 commits into from
Apr 8, 2021

Conversation

roblabla
Copy link
Contributor

@roblabla roblabla commented Sep 1, 2020

Here's my first attempt at implementing cwd for window, mostly based on the code of PSUtil.

Fixes #105

It works by parsing the PEB data structure found in each process. This data structure, along with the APIs used to acquire it, are unstable and, according to microsoft, the APIs may change. In practice, a significant amount of software is built on top of this API, and as such it is unlikely to be broken. If it does break, I expect microsoft to provide a stable API to acquire this information, like they did for the CommandLine.

I tested this with various combination on intel (x86 and x64) CPUs:

  • Host: 32-bit, Heim: 32-bit, Target: 32-bit
  • Host: 64-bit, Heim: 64-bit, Target: 64-bit
  • Host: 64-bit, Heim: 64-bit, Target: 32-bit
  • Host: 64-bit, Heim: 32-bit, Target: 32-bit

I did not implement this under ARM, as it requires using a fairly new API. We'd need to do a runtime check to see if the API is present, I'm not sure what the best way to do this is.
Furthermore, getting a 64-bit process' CWD from a 32-bit Heim is not implemented, as it requires relying on even more unstable APIs, and I don't personally need it.

@coveralls
Copy link

coveralls commented Oct 21, 2020

Coverage Status

Coverage decreased (-5.8%) to 31.284% when pulling 9aae14e on roblabla:win32-cwd into e22e235 on heim-rs:master.

@svartalf
Copy link
Member

Heads up: I know this PR was kinda abandoned, my apologies about that. I'll try to check as much as possible in a next neek.

@svartalf svartalf merged commit b1b7c9c into heim-rs:master Apr 8, 2021
@svartalf
Copy link
Member

svartalf commented Apr 8, 2021

Alright, it is really unfair from me to keep this thing in the backlog for that long; I thought that it would be better to merge it as is and mark Process::cwd for Windows as an "unstable" function somehow (probably just in the documentation, since we don't really have any better mechanisms?).

Further bug reports (if there will be any) will help us reiterate on current functionality.

Thank you, @roblabla !

@roblabla roblabla deleted the win32-cwd branch April 8, 2021 15:06
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.

process::Process::cwd for Windows
3 participants