-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
32/64 bit confusion on Windows in Process.cmdline and Process.cwd #737
Comments
So what you're saying is that we have issues, for example, if we use a Python 32 installation on a Windows 64 OS? What happens in that case? How is that broken? |
At the moment if the bitness does not match the addresses given to ReadProcessMemory are incorrect. This results in an invalid value read in one case (64 bit Python, 32 bit process, cwd is incorrect - see attached test case above) and ERROR_PARTIAL_READ which gets translated to AccessDenied in others. To contain the ugliness somewhat I still want to go ahead with merging all callers of ReadProcessMemory (cmdline()/cwd()/environ()) into a single function in my implementation of Process.environ for Windows. I'm hope that if I do that in smaller commits it is easier to review and can be merged. As you suggest, I'll try to ignore the mismatched bitness problems for now and hopefully address them later. |
My main concern about your previous PR (other than being difficult to review) was that calculating 3 different things at the same time is slower (especially because environ requires constructing a big Python dict). You should calculate one at a time and put the shared code in a separate utility function (say it's called 1 - refactor cwd() / cmdline() code so that they rely on a shared/utility function using ReadProcessMemory Thoughts? |
1./2. Done -> #738 I'll try my hand at 3. now. |
BTW, https://github.com/giampaolo/psutil/files/103277/0001-test-ReadProcessMemory-functions.txt is a precious set of test cases which should definitively be integrated once this is fixed. |
Yes, I'm integrating these tests in my work for 3. |
Can be closed. |
While considering to restructure my Process.environ implementation I came across the following problem: In Process.cmdline and Process.cwd ReadProcessMemory is called to get at the RTL_USER_PROCESS_PARAMETERS structure that has the necessary information. The pointer to the environment variables is also located at the end of this structure. There are five combinations that have to be considered: the Python process can be a native 32bit (on a 32bit host OS), a WoW64 32bit process process or 64bit process and the target process can be 32bit or 64bit.
Currently only the straight cases 32->32 and 64->64 seem to work correctly. I am currently looking into fixing this but it doesn't seem straightforward and will make the current code even more complex. Please consider dropping support for these function at least on Wow64. This would leave three relatively straightforward cases. In the long run 32 bit native should probably dropped as well.
0001-test-ReadProcessMemory-functions.txt
The text was updated successfully, but these errors were encountered: