From: Alex Henrie Subject: [PATCH v3] ntdll: Print a warning when LdrGetProcedureAddress fails Message-Id: <20200609034613.67229-1-alexhenrie24@gmail.com> Date: Mon, 8 Jun 2020 21:46:13 -0600 Signed-off-by: Alex Henrie --- v3: - Don't use LdrGetDllFullName - Print warning regardless of validity of function arguments (the fact that the function arguments were invalid could indicate a bug elsewhere in Wine) --- dlls/ntdll/loader.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c index 762ca22c26..4cd318395d 100644 --- a/dlls/ntdll/loader.c +++ b/dlls/ntdll/loader.c @@ -1841,6 +1841,7 @@ NTSTATUS WINAPI LdrUnlockLoaderLock( ULONG flags, ULONG_PTR magic ) NTSTATUS WINAPI LdrGetProcedureAddress(HMODULE module, const ANSI_STRING *name, ULONG ord, PVOID *address) { + WINE_MODREF *wm; IMAGE_EXPORT_DIRECTORY *exports; DWORD exp_size; NTSTATUS ret = STATUS_PROCEDURE_NOT_FOUND; @@ -1848,17 +1849,29 @@ NTSTATUS WINAPI LdrGetProcedureAddress(HMODULE module, const ANSI_STRING *name, RtlEnterCriticalSection( &loader_section ); /* check if the module itself is invalid to return the proper error */ - if (!get_modref( module )) ret = STATUS_DLL_NOT_FOUND; - else if ((exports = RtlImageDirectoryEntryToData( module, TRUE, - IMAGE_DIRECTORY_ENTRY_EXPORT, &exp_size ))) - { - LPCWSTR load_path = NtCurrentTeb()->Peb->ProcessParameters->DllPath.Buffer; - void *proc = name ? find_named_export( module, exports, exp_size, name->Buffer, -1, load_path ) - : find_ordinal_export( module, exports, exp_size, ord - exports->Base, load_path ); - if (proc) + if (!(wm = get_modref( module ))) + { + ret = STATUS_DLL_NOT_FOUND; + } + else + { + if ((exports = RtlImageDirectoryEntryToData( module, TRUE, + IMAGE_DIRECTORY_ENTRY_EXPORT, &exp_size ))) + { + const WCHAR *load_path = NtCurrentTeb()->Peb->ProcessParameters->DllPath.Buffer; + void *proc = name ? find_named_export( module, exports, exp_size, name->Buffer, -1, load_path ) + : find_ordinal_export( module, exports, exp_size, ord - exports->Base, load_path ); + if (proc) + { + *address = proc; + ret = STATUS_SUCCESS; + } + } + + if (ret == STATUS_PROCEDURE_NOT_FOUND) { - *address = proc; - ret = STATUS_SUCCESS; + WARN( "function %s (ordinal %d) not found in module %s\n", + wine_dbgstr_a(name ? name->Buffer : NULL), ord, wine_dbgstr_w(wm->ldr.FullDllName.Buffer) ); } } -- 2.27.0