https://bugs.winehq.org/show_bug.cgi?id=49344
Bug ID: 49344 Summary: Implement kernelbase.GetModuleFileNameW using ntdll.LdrGetDllFullName Product: Wine Version: 5.10 Hardware: x86-64 OS: Linux Status: NEW Severity: enhancement Priority: P2 Component: kernelbase Assignee: wine-bugs@winehq.org Reporter: focht@gmx.net Distribution: ---
Hello folks,
saw this patchset:
https://www.winehq.org/pipermail/wine-devel/2020-June/thread.html#167607
--- quote --- This will help tremendously with debugging null pointer segfaults. --- quote ---
to be used in ntdll.LdrGetProcedureAddress() for diagnostics.
According to:
https://www.geoffchappell.com/studies/windows/win32/ntdll/history/names62.ht...
this API function was added in Windows 8.
Actually the real benefactor could be kernelbase.GetModuleFileNameW(). It would avoid unnecessary code duplication and streamlines with general usage of native API.
Wine source:
https://source.winehq.org/git/wine.git/blob/3cc3b445752902e07231900befc296f7...
--- snip --- 297 /*********************************************************************** 298 * GetModuleFileNameW (kernelbase.@) 299 */ 300 DWORD WINAPI DECLSPEC_HOTPATCH GetModuleFileNameW( HMODULE module, LPWSTR filename, DWORD size ) 301 { 302 ULONG len = 0; 303 ULONG_PTR magic; 304 LDR_DATA_TABLE_ENTRY *pldr; 305 WIN16_SUBSYSTEM_TIB *win16_tib; 306 307 if (!module && ((win16_tib = NtCurrentTeb()->Tib.SubSystemTib)) && win16_tib->exe_name) 308 { 309 len = min( size, win16_tib->exe_name->Length / sizeof(WCHAR) ); 310 memcpy( filename, win16_tib->exe_name->Buffer, len * sizeof(WCHAR) ); 311 if (len < size) filename[len] = 0; 312 goto done; 313 } 314 315 LdrLockLoaderLock( 0, NULL, &magic ); 316 317 if (!module) module = NtCurrentTeb()->Peb->ImageBaseAddress; 318 if (set_ntstatus( LdrFindEntryForAddress( module, &pldr ))) 319 { 320 len = min( size, pldr->FullDllName.Length / sizeof(WCHAR) ); 321 memcpy( filename, pldr->FullDllName.Buffer, len * sizeof(WCHAR) ); 322 if (len < size) 323 { 324 filename[len] = 0; 325 SetLastError( 0 ); 326 } 327 else SetLastError( ERROR_INSUFFICIENT_BUFFER ); 328 } 329 330 LdrUnlockLoaderLock( 0, magic ); 331 done: 332 TRACE( "%s\n", debugstr_wn(filename, len) ); 333 return len; 334 } --- snip ---
$ wine --version wine-5.10
Regards
https://bugs.winehq.org/show_bug.cgi?id=49344
Zebediah Figura z.figura12@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Component|kernelbase |kernel32
https://bugs.winehq.org/show_bug.cgi?id=49344
Alex Henrie alexhenrie24@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |FIXED CC| |alexhenrie24@gmail.com Fixed by SHA1| |43d14fd808bb965762bb6c76027 | |bbe26ba936f82 Status|NEW |RESOLVED
--- Comment #1 from Alex Henrie alexhenrie24@gmail.com --- Fixed by https://source.winehq.org/git/wine.git/commitdiff/43d14fd808bb965762bb6c7602...
https://bugs.winehq.org/show_bug.cgi?id=49344
Arne de Bruijn wine@2ar.nl changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |wine@2ar.nl
--- Comment #2 from Arne de Bruijn wine@2ar.nl --- This change broke passing large buffers (>=32768 characters) to GetModuleFileNameW, as done by cygwin.
Possible fix:
name.MaximumLength = (size < 0xffff / sizeof(WCHAR) ? size : 0xffff / sizeof(WCHAR)) * sizeof(WCHAR);
https://bugs.winehq.org/show_bug.cgi?id=49344
--- Comment #3 from Nikolay Sivov bunglehead@gmail.com --- (In reply to Arne de Bruijn from comment #2)
This change broke passing large buffers (>=32768 characters) to GetModuleFileNameW, as done by cygwin.
Possible fix:
name.MaximumLength = (size < 0xffff / sizeof(WCHAR) ? size : 0xffff /
sizeof(WCHAR)) * sizeof(WCHAR);
Please file a bug report for that, we could probably min() it in ints, to avoid this 16bit overflow.
https://bugs.winehq.org/show_bug.cgi?id=49344
--- Comment #4 from Arne de Bruijn wine@2ar.nl --- I've created bug 51833: GetModuleFileNameW no longer works with large buffers
https://bugs.winehq.org/show_bug.cgi?id=49344
Alex Henrie alexhenrie24@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://bugs.winehq.org/sho | |w_bug.cgi?id=51833
https://bugs.winehq.org/show_bug.cgi?id=49344
Alexandre Julliard julliard@winehq.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |CLOSED
--- Comment #5 from Alexandre Julliard julliard@winehq.org --- Closing bugs fixed in 6.19.