Error 126 from RegisterServiceCtrlHandlerEx
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- java
- Domain
- operating-systems
Research direction
Start with the contrib/ntservice code and the RegisterServiceCtrlHandlerExW callback path described in the report, then reproduce the failure on the stated Windows 7 SP1 and 32-bit JVM setup. Trace the FFI callback handling and verify that service registration no longer fails with error 126.
Written by the indexing model from the issue text.
Description
I am using Windows 7SP1 64bit (but 32-bit JVM). I was trying to use ntservice from the contrib directory, but couldn't get it to work. So I modified it slightly - added "throw LastErrorException" to all the API calls, and added some code to open a logfile and redirect stderr/stdout to it (since otherwise you can't get the output of the service). And I discovered that RegisterServiceCtrlHandlerEx fails with error 126 (The specified module could not be found). Investigating further, I believe what is happening is as follows:
- RegisterServiceCtrlHandlerExW calls GetModuleHandleExW on the function pointer passed in
-- I guess, for some unknown reason, it wants to know what DLL/EXE the pointer belongs to - With a normal service, this will return the module handle for some DLL or EXE
- But with a JNA callback, this points to a memory buffer VirtualAlloc-allocated by FFI
- So GetModuleHandleExW fails with 126 and RegisterServiceCtrlHandlerExW as a whole fails
Solution: It is a hard one. I guess the only way forward would be to modify FFI to write out the trampoline code to a DLL in a temporary directory, and then load that into memory. From reading the FFI code, it looks like it actually does this on some other platforms, but not windows. Obviously you would not want it to do this for every callback, but only for ones like this where the VirtualAlloc issue is a problem. But making modifications to the FFI code like this is a bit beyond me - maybe someone else will feel sufficiently inclined?
Since it looks like others have got this working before, maybe RegisterServiceCtrlHandlerExW calling GetModuleHandleExW is new code in some new versions of Windows.
- Dominant language
- Java
- Stars
- 8.9k
- Forks
- 1.7k
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from java-native-access/jna
-
Difficulty 4/5 3-5 days Newbie friendliness 66/100
java-native-access/jna#1738 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
java-native-access/jna#1736 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 65/100
java-native-access/jna#1717 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
java-native-access/jna#1700 · 11 comments ·
-
feature request
Difficulty 4/5 3-5 days Newbie friendliness 35/100
java-native-access/jna#1698 · 1 comment ·
All issues in java-native-access/jna
Similar issues
-
Bug Java Platform: Java
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
getsentry/sentry-java#6138 · 1 comment ·
-
bug needs triage p2
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
GoogleCloudPlatform/DataflowTemplates#4273 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
bug needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100