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

The registry access should probably pin intermediate values in the memory #4

Open
pavel-krivanek opened this issue Aug 4, 2023 · 0 comments

Comments

@pavel-krivanek
Copy link

We had an "interesting" issue. In our case, we needed to access the path to the Documents folder.

WinRegistryKey currentUser 
		queryValue: #Personal
		fromSubkey: 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders'.

The returned values usually have %USERPROFILE% keys so to get the full path, we had to first access the environment variable and then substitute it. We got the variable value using:

Smalltalk os environment at: 'USERPROFILE' ifAbsent: ''

And as soon as we started to do it, we got tons of strange errors related to file access to log files we create. We have proven that these errors occur only if we perform the registry access.

So, my next guess was to try to pin intermediate values during the registry access in memory because some strange memory corruption is probably happening.

In WinRegistry class>>#queryValue:fromKey:

	dwType := ByteArray new: (FFIExternalType sizeOf: DWORD).
	dwType pinInMemory.
	lSize := ByteArray new: (FFIExternalType sizeOf: LONG).
	lSize pinInMemory.
...
	buffer := ByteArray new: (lSize signedLongAt: 1).
	buffer pinInMemory.

in WinRegistryKey>>#queryValue:fromSubkey:

	hKey := self queryOpenSubkey: subkey.
	hKey pinInMemory.

It was a fully blind guess, but it seems to solve our problems. Not sure if fully. So I'm reporting it for the next discussion.

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

No branches or pull requests

1 participant