Commit 619bd16e authored by Alexandre Julliard's avatar Alexandre Julliard

kernel32: Move dll path functions to ntdll.

parent b8ba4909
......@@ -140,7 +140,7 @@
@ stdcall AddAtomW(wstr)
@ stdcall AddConsoleAliasA(str str str)
@ stdcall AddConsoleAliasW(wstr wstr wstr)
@ stdcall AddDllDirectory(wstr)
@ stdcall -import AddDllDirectory(wstr)
# @ stub AddIntegrityLabelToBoundaryDescriptor
# @ stub AddLocalAlternateComputerNameA
# @ stub AddLocalAlternateComputerNameW
......@@ -1274,7 +1274,7 @@
@ stdcall ReplaceFileW(wstr wstr wstr long ptr ptr)
# @ stub RemoveDirectoryTransactedA
# @ stub RemoveDirectoryTransactedW
@ stdcall RemoveDllDirectory(ptr)
@ stdcall -import RemoveDllDirectory(ptr)
# @ stub RemoveSecureMemoryCacheCallback
# @ stub ReplacePartitionUnit
@ stdcall RequestDeviceWakeup(long)
......@@ -1379,7 +1379,7 @@
@ stub SetDaylightFlag
@ stdcall SetDefaultCommConfigA(str ptr long)
@ stdcall SetDefaultCommConfigW(wstr ptr long)
@ stdcall SetDefaultDllDirectories(long)
@ stdcall -import SetDefaultDllDirectories(long)
@ stdcall SetDllDirectoryA(str)
@ stdcall SetDllDirectoryW(wstr)
# @ stub SetDynamicTimeZoneInformation
......
......@@ -65,9 +65,6 @@ extern void FILE_SetDosError(void) DECLSPEC_HIDDEN;
extern WCHAR *FILE_name_AtoW( LPCSTR name, BOOL alloc ) DECLSPEC_HIDDEN;
extern DWORD FILE_name_WtoA( LPCWSTR src, INT srclen, LPSTR dest, INT destlen ) DECLSPEC_HIDDEN;
/* module.c */
extern WCHAR *MODULE_get_dll_load_path( LPCWSTR module, int safe_mode ) DECLSPEC_HIDDEN;
extern BOOL NLS_IsUnicodeOnlyLcid(LCID) DECLSPEC_HIDDEN;
/* environ.c */
......
......@@ -1373,6 +1373,7 @@ void * CDECL __wine_kernel_init(void)
RTL_USER_PROCESS_PARAMETERS *params = peb->ProcessParameters;
HANDLE boot_events[2];
BOOL got_environment = TRUE;
WCHAR *load_path, *dummy;
/* Initialize everything */
......@@ -1429,8 +1430,8 @@ void * CDECL __wine_kernel_init(void)
TRACE( "starting process name=%s argv[0]=%s\n",
debugstr_w(main_exe_name), debugstr_w(__wine_main_wargv[0]) );
RtlInitUnicodeString( &NtCurrentTeb()->Peb->ProcessParameters->DllPath,
MODULE_get_dll_load_path( main_exe_name, -1 ));
LdrGetDllPath( main_exe_name, 0, &load_path, &dummy );
RtlInitUnicodeString( &NtCurrentTeb()->Peb->ProcessParameters->DllPath, load_path );
if (boot_events[0])
{
......
......@@ -73,10 +73,14 @@ static DWORD (WINAPI *pGetLongPathNameW)(LPWSTR,LPWSTR,DWORD);
static BOOL (WINAPI *pNeedCurrentDirectoryForExePathA)(LPCSTR);
static BOOL (WINAPI *pNeedCurrentDirectoryForExePathW)(LPCWSTR);
static BOOL (WINAPI *pSetSearchPathMode)(DWORD);
static BOOL (WINAPI *pSetDllDirectoryA)(LPCSTR);
static DLL_DIRECTORY_COOKIE (WINAPI *pAddDllDirectory)(const WCHAR*);
static BOOL (WINAPI *pRemoveDllDirectory)(DLL_DIRECTORY_COOKIE);
static BOOL (WINAPI *pSetSearchPathMode)(DWORD);
static BOOL (WINAPI *pSetDllDirectoryW)(LPCWSTR);
static BOOL (WINAPI *pSetDefaultDllDirectories)(DWORD);
static NTSTATUS (WINAPI *pRtlGetSearchPath)(LPWSTR*);
static void (WINAPI *pRtlReleasePath)(LPWSTR);
static void (WINAPI *pRtlReleasePath)(LPWSTR);
static NTSTATUS (WINAPI *pLdrGetDllPath)(LPCWSTR,ULONG,LPWSTR*,LPWSTR*);
static BOOL (WINAPI *pActivateActCtx)(HANDLE,ULONG_PTR*);
static HANDLE (WINAPI *pCreateActCtxW)(PCACTCTXW);
......@@ -2201,7 +2205,10 @@ static void init_pointers(void)
MAKEFUNC(NeedCurrentDirectoryForExePathA);
MAKEFUNC(NeedCurrentDirectoryForExePathW);
MAKEFUNC(SetSearchPathMode);
MAKEFUNC(SetDllDirectoryA);
MAKEFUNC(AddDllDirectory);
MAKEFUNC(RemoveDllDirectory);
MAKEFUNC(SetDllDirectoryW);
MAKEFUNC(SetDefaultDllDirectories);
MAKEFUNC(ActivateActCtx);
MAKEFUNC(CreateActCtxW);
MAKEFUNC(DeactivateActCtx);
......@@ -2210,6 +2217,7 @@ static void init_pointers(void)
MAKEFUNC(CheckNameLegalDOS8Dot3W);
MAKEFUNC(CheckNameLegalDOS8Dot3A);
mod = GetModuleHandleA("ntdll.dll");
MAKEFUNC(LdrGetDllPath);
MAKEFUNC(RtlGetSearchPath);
MAKEFUNC(RtlReleasePath);
#undef MAKEFUNC
......@@ -2470,12 +2478,23 @@ static void test_SetSearchPathMode(void)
static const WCHAR pathW[] = {'P','A','T','H',0};
static void build_search_path( WCHAR *buffer, UINT size, BOOL safe )
static void build_search_path( WCHAR *buffer, UINT size, const WCHAR *dlldir, BOOL safe )
{
WCHAR *p;
GetModuleFileNameW( NULL, buffer, size );
if (!(p = wcsrchr( buffer, '\\' ))) return;
*p++ = ';';
if (dlldir)
{
lstrcpyW( p, dlldir );
p += lstrlenW( p );
if (*dlldir) *p++ = ';';
}
else if (!safe)
{
*p++ = '.';
*p++ = ';';
}
GetSystemDirectoryW( p, buffer + size - p );
p = buffer + lstrlenW(buffer);
*p++ = ';';
......@@ -2485,7 +2504,7 @@ static void build_search_path( WCHAR *buffer, UINT size, BOOL safe )
GetWindowsDirectoryW( p, buffer + size - p );
p = buffer + lstrlenW(buffer);
*p++ = ';';
if (!safe)
if (!dlldir && safe)
{
*p++ = '.';
*p++ = ';';
......@@ -2501,7 +2520,7 @@ static BOOL path_equal( const WCHAR *path1, const WCHAR *path2 )
if (*path1 && *path1 != '\\' && *path1 != ';') return FALSE;
while (*path1 && (*path1 == '\\' || *path1 == ';')) path1++;
while (*path2 && (*path2 == '\\' || *path2 == ';')) path2++;
if (!*path1 && !*path2) return TRUE;
if (!*path1 || !*path2) return !*path1 && !*path2;
}
}
......@@ -2509,7 +2528,7 @@ static void test_RtlGetSearchPath(void)
{
NTSTATUS ret;
WCHAR *path;
WCHAR buffer[2048], old_path[2048];
WCHAR buffer[2048], old_path[2048], dlldir[4];
if (!pRtlGetSearchPath)
{
......@@ -2518,8 +2537,10 @@ static void test_RtlGetSearchPath(void)
}
GetEnvironmentVariableW( pathW, old_path, ARRAY_SIZE(old_path) );
GetWindowsDirectoryW( buffer, ARRAY_SIZE(buffer) );
lstrcpynW( dlldir, buffer, ARRAY_SIZE(dlldir) );
build_search_path( buffer, ARRAY_SIZE(buffer), FALSE );
build_search_path( buffer, ARRAY_SIZE(buffer), NULL, TRUE );
path = (WCHAR *)0xdeadbeef;
ret = pRtlGetSearchPath( &path );
ok( !ret, "RtlGetSearchPath failed %x\n", ret );
......@@ -2527,23 +2548,123 @@ static void test_RtlGetSearchPath(void)
pRtlReleasePath( path );
SetEnvironmentVariableA( "PATH", "foo" );
build_search_path( buffer, ARRAY_SIZE(buffer), FALSE );
build_search_path( buffer, ARRAY_SIZE(buffer), NULL, TRUE );
path = (WCHAR *)0xdeadbeef;
ret = pRtlGetSearchPath( &path );
ok( !ret, "RtlGetSearchPath failed %x\n", ret );
ok( path_equal( path, buffer ), "got %s expected %s\n", wine_dbgstr_w(path), wine_dbgstr_w(buffer));
pRtlReleasePath( path );
if (pSetDllDirectoryA)
if (pSetDllDirectoryW)
{
ok( pSetDllDirectoryA( "c:\\" ), "SetDllDirectoryA failed\n" );
build_search_path( buffer, ARRAY_SIZE(buffer), FALSE );
ok( pSetDllDirectoryW( dlldir ), "SetDllDirectoryW failed\n" );
build_search_path( buffer, ARRAY_SIZE(buffer), NULL, TRUE );
path = (WCHAR *)0xdeadbeef;
ret = pRtlGetSearchPath( &path );
ok( !ret, "RtlGetSearchPath failed %x\n", ret );
ok( path_equal( path, buffer ), "got %s expected %s\n", wine_dbgstr_w(path), wine_dbgstr_w(buffer));
pRtlReleasePath( path );
pSetDllDirectoryA( NULL );
pSetDllDirectoryW( NULL );
}
SetEnvironmentVariableW( pathW, old_path );
}
static void test_LdrGetDllPath(void)
{
static const WCHAR fooW[] = {'f','o','o',0};
NTSTATUS ret;
WCHAR *path, *unknown_ptr, *p;
WCHAR buffer[2048], old_path[2048], dlldir[4];
if (!pLdrGetDllPath)
{
win_skip( "LdrGetDllPath isn't available\n" );
return;
}
GetEnvironmentVariableW( pathW, old_path, ARRAY_SIZE(old_path) );
GetWindowsDirectoryW( buffer, ARRAY_SIZE(buffer) );
lstrcpynW( dlldir, buffer, ARRAY_SIZE(dlldir) );
build_search_path( buffer, ARRAY_SIZE(buffer), NULL, TRUE );
path = unknown_ptr = (WCHAR *)0xdeadbeef;
ret = pLdrGetDllPath( 0, 0, &path, &unknown_ptr );
ok( !ret, "LdrGetDllPath failed %x\n", ret );
ok( !unknown_ptr, "unknown ptr %p\n", unknown_ptr );
ok( path_equal( path, buffer ), "got %s expected %s\n", wine_dbgstr_w(path), wine_dbgstr_w(buffer));
pRtlReleasePath( path );
SetEnvironmentVariableA( "PATH", "foo" );
build_search_path( buffer, ARRAY_SIZE(buffer), NULL, TRUE );
ret = pLdrGetDllPath( 0, 0, &path, &unknown_ptr );
ok( !ret, "LdrGetDllPath failed %x\n", ret );
ok( !unknown_ptr, "unknown ptr %p\n", unknown_ptr );
ok( path_equal( path, buffer ), "got %s expected %s\n", wine_dbgstr_w(path), wine_dbgstr_w(buffer));
pRtlReleasePath( path );
if (pSetDllDirectoryW)
{
ok( pSetDllDirectoryW( dlldir ), "SetDllDirectoryW failed\n" );
build_search_path( buffer, ARRAY_SIZE(buffer), dlldir, TRUE );
ret = pLdrGetDllPath( 0, 0, &path, &unknown_ptr );
ok( !ret, "LdrGetDllPath failed %x\n", ret );
ok( !unknown_ptr, "unknown ptr %p\n", unknown_ptr );
ok( path_equal( path, buffer ), "got %s expected %s\n", wine_dbgstr_w(path), wine_dbgstr_w(buffer));
pRtlReleasePath( path );
pSetDllDirectoryW( NULL );
}
ret = pLdrGetDllPath( 0, LOAD_LIBRARY_SEARCH_SYSTEM32, &path, &unknown_ptr );
ok( !ret, "LdrGetDllPath failed %x\n", ret );
ok( !unknown_ptr, "unknown ptr %p\n", unknown_ptr );
GetSystemDirectoryW( buffer, ARRAY_SIZE(buffer) );
ok( path_equal( path, buffer ), "got %s expected %s\n", wine_dbgstr_w(path), wine_dbgstr_w(buffer));
pRtlReleasePath( path );
ret = pLdrGetDllPath( 0, LOAD_LIBRARY_SEARCH_APPLICATION_DIR, &path, &unknown_ptr );
ok( !ret, "LdrGetDllPath failed %x\n", ret );
ok( !unknown_ptr, "unknown ptr %p\n", unknown_ptr );
GetModuleFileNameW( NULL, buffer, ARRAY_SIZE(buffer) );
if ((p = wcsrchr( buffer, '\\' ))) *p = 0;
ok( path_equal( path, buffer ), "got %s expected %s\n", wine_dbgstr_w(path), wine_dbgstr_w(buffer));
pRtlReleasePath( path );
ret = pLdrGetDllPath( fooW, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR, &path, &unknown_ptr );
ok( ret == STATUS_INVALID_PARAMETER, "LdrGetDllPath failed %x\n", ret );
lstrcpyW( buffer, dlldir );
p = buffer + lstrlenW(buffer);
*p++ = '\\';
lstrcpyW( p, fooW );
ret = pLdrGetDllPath( buffer, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR, &path, &unknown_ptr );
ok( !ret, "LdrGetDllPath failed %x\n", ret );
ok( !unknown_ptr, "unknown ptr %p\n", unknown_ptr );
ok( path_equal( path, dlldir ), "got %s expected %s\n", wine_dbgstr_w(path), wine_dbgstr_w(dlldir));
pRtlReleasePath( path );
if (pAddDllDirectory)
{
DLL_DIRECTORY_COOKIE cookie = pAddDllDirectory( dlldir );
ok( !!cookie, "AddDllDirectory failed\n" );
ret = pLdrGetDllPath( 0, LOAD_LIBRARY_SEARCH_USER_DIRS, &path, &unknown_ptr );
ok( !ret, "LdrGetDllPath failed %x\n", ret );
ok( !unknown_ptr, "unknown ptr %p\n", unknown_ptr );
ok( path_equal( path, dlldir ), "got %s expected %s\n", wine_dbgstr_w(path), wine_dbgstr_w(dlldir));
pRtlReleasePath( path );
pRemoveDllDirectory( cookie );
}
if (pSetDefaultDllDirectories)
{
pSetDefaultDllDirectories( LOAD_LIBRARY_SEARCH_SYSTEM32 );
ret = pLdrGetDllPath( 0, 0, &path, &unknown_ptr );
ok( !ret, "LdrGetDllPath failed %x\n", ret );
ok( !unknown_ptr, "unknown ptr %p\n", unknown_ptr );
GetSystemDirectoryW( buffer, ARRAY_SIZE(buffer) );
ok( path_equal( path, buffer ), "got %s expected %s\n", wine_dbgstr_w(path), wine_dbgstr_w(buffer));
pRtlReleasePath( path );
pSetDefaultDllDirectories( 0 );
}
SetEnvironmentVariableW( pathW, old_path );
......@@ -2584,4 +2705,5 @@ START_TEST(path)
test_CheckNameLegalDOS8Dot3();
test_SetSearchPathMode();
test_RtlGetSearchPath();
test_LdrGetDllPath();
}
......@@ -19,7 +19,7 @@
@ stdcall AddAuditAccessAce(ptr long long ptr long long)
@ stdcall AddAuditAccessAceEx(ptr long long long ptr long long)
@ stdcall AddAuditAccessObjectAce(ptr long long long ptr ptr ptr long long)
@ stdcall AddDllDirectory(wstr) kernel32.AddDllDirectory
@ stdcall AddDllDirectory(wstr)
@ stdcall AddMandatoryAce(ptr long long long ptr)
@ stdcall AddRefActCtx(ptr)
# @ stub AddResourceAttributeAce
......@@ -1333,7 +1333,7 @@
@ stdcall RemapPredefinedHandleInternal(long long)
@ stdcall RemoveDirectoryA(str) kernel32.RemoveDirectoryA
@ stdcall RemoveDirectoryW(wstr) kernel32.RemoveDirectoryW
@ stdcall RemoveDllDirectory(ptr) kernel32.RemoveDllDirectory
@ stdcall RemoveDllDirectory(ptr)
# @ stub RemovePackageStatus
# @ stub RemovePackageStatusForUser
@ stdcall RemoveVectoredContinueHandler(ptr) ntdll.RtlRemoveVectoredContinueHandler
......@@ -1419,7 +1419,7 @@
@ stdcall SetCriticalSectionSpinCount(ptr long) ntdll.RtlSetCriticalSectionSpinCount
@ stdcall SetCurrentDirectoryA(str)
@ stdcall SetCurrentDirectoryW(wstr)
@ stdcall SetDefaultDllDirectories(long) kernel32.SetDefaultDllDirectories
@ stdcall SetDefaultDllDirectories(long)
# @ stub SetDynamicTimeZoneInformation
@ stdcall SetEndOfFile(long)
@ stub SetEnvironmentStringsW
......
......@@ -42,6 +42,20 @@ WINE_DEFAULT_DEBUG_CHANNEL(module);
***********************************************************************/
/****************************************************************************
* AddDllDirectory (kernelbase.@)
*/
DLL_DIRECTORY_COOKIE WINAPI DECLSPEC_HOTPATCH AddDllDirectory( const WCHAR *dir )
{
UNICODE_STRING str;
void *cookie;
RtlInitUnicodeString( &str, dir );
if (!set_ntstatus( LdrAddDllDirectory( &str, &cookie ))) return NULL;
return cookie;
}
/***********************************************************************
* DelayLoadFailureHook (kernelbase.@)
*/
......@@ -225,6 +239,24 @@ BOOL WINAPI DECLSPEC_HOTPATCH GetModuleHandleExW( DWORD flags, LPCWSTR name, HMO
}
/****************************************************************************
* RemoveDllDirectory (kernelbase.@)
*/
BOOL WINAPI DECLSPEC_HOTPATCH RemoveDllDirectory( DLL_DIRECTORY_COOKIE cookie )
{
return set_ntstatus( LdrRemoveDllDirectory( cookie ));
}
/*************************************************************************
* SetDefaultDllDirectories (kernelbase.@)
*/
BOOL WINAPI DECLSPEC_HOTPATCH SetDefaultDllDirectories( DWORD flags )
{
return set_ntstatus( LdrSetDefaultDllDirectories( flags ));
}
/***********************************************************************
* Resources
***********************************************************************/
......
......@@ -71,6 +71,7 @@
@ stub KiUserExceptionDispatcher
# @ stub LdrAccessOutOfProcessResource
@ stdcall LdrAccessResource(long ptr ptr ptr)
@ stdcall LdrAddDllDirectory(ptr ptr)
@ stdcall LdrAddRefDll(long ptr)
# @ stub LdrAlternateResourcesEnabled
# @ stub LdrCreateOutOfProcessImage
......@@ -84,9 +85,10 @@
# @ stub LdrFindResourceEx_U
@ stdcall LdrFindResource_U(long ptr long ptr)
@ stub LdrFlushAlternateResourceModules
@ stdcall LdrGetDllDirectory(ptr)
@ stdcall LdrGetDllHandle(wstr long ptr ptr)
# @ stub LdrGetDllHandleEx
@ stdcall LdrGetDllDirectory(ptr)
@ stdcall LdrGetDllPath(wstr long ptr ptr)
@ stdcall LdrGetProcedureAddress(ptr ptr long ptr)
# @ stub LdrHotPatchRoutine
@ stub LdrInitShimEngineDynamic
......@@ -98,8 +100,10 @@
@ stdcall LdrQueryImageFileExecutionOptions(ptr wstr long ptr long ptr)
@ stdcall LdrQueryProcessModuleInformation(ptr long ptr)
@ stdcall LdrRegisterDllNotification(long ptr ptr ptr)
@ stdcall LdrRemoveDllDirectory(ptr)
@ stdcall LdrResolveDelayLoadedAPI(ptr ptr ptr ptr ptr long)
@ stub LdrSetAppCompatDllRedirectionCallback
@ stdcall LdrSetDefaultDllDirectories(long)
@ stdcall LdrSetDllDirectory(ptr)
@ stub LdrSetDllManifestProber
@ stdcall LdrShutdownProcess()
......
......@@ -2309,6 +2309,7 @@ NTSYSAPI NTSTATUS WINAPI DbgUiIssueRemoteBreakin(HANDLE);
NTSYSAPI void WINAPI DbgUiRemoteBreakin(void*);
NTSYSAPI void WINAPI DbgUserBreakPoint(void);
NTSYSAPI NTSTATUS WINAPI LdrAccessResource(HMODULE,const IMAGE_RESOURCE_DATA_ENTRY*,void**,PULONG);
NTSYSAPI NTSTATUS WINAPI LdrAddDllDirectory(const UNICODE_STRING*,void**);
NTSYSAPI NTSTATUS WINAPI LdrAddRefDll(ULONG,HMODULE);
NTSYSAPI NTSTATUS WINAPI LdrDisableThreadCalloutsForDll(HMODULE);
NTSYSAPI NTSTATUS WINAPI LdrFindEntryForAddress(const void*, PLDR_MODULE*);
......@@ -2316,12 +2317,15 @@ NTSYSAPI NTSTATUS WINAPI LdrFindResourceDirectory_U(HMODULE,const LDR_RESOURCE_
NTSYSAPI NTSTATUS WINAPI LdrFindResource_U(HMODULE,const LDR_RESOURCE_INFO*,ULONG,const IMAGE_RESOURCE_DATA_ENTRY**);
NTSYSAPI NTSTATUS WINAPI LdrGetDllDirectory(UNICODE_STRING*);
NTSYSAPI NTSTATUS WINAPI LdrGetDllHandle(LPCWSTR, ULONG, const UNICODE_STRING*, HMODULE*);
NTSYSAPI NTSTATUS WINAPI LdrGetDllPath(PCWSTR,ULONG,PWSTR*,PWSTR*);
NTSYSAPI NTSTATUS WINAPI LdrGetProcedureAddress(HMODULE, const ANSI_STRING*, ULONG, void**);
NTSYSAPI NTSTATUS WINAPI LdrLoadDll(LPCWSTR, DWORD, const UNICODE_STRING*, HMODULE*);
NTSYSAPI NTSTATUS WINAPI LdrLockLoaderLock(ULONG,ULONG*,ULONG_PTR*);
IMAGE_BASE_RELOCATION * WINAPI LdrProcessRelocationBlock(void*,UINT,USHORT*,INT_PTR);
NTSYSAPI NTSTATUS WINAPI LdrQueryImageFileExecutionOptions(const UNICODE_STRING*,LPCWSTR,ULONG,void*,ULONG,ULONG*);
NTSYSAPI NTSTATUS WINAPI LdrQueryProcessModuleInformation(SYSTEM_MODULE_INFORMATION*, ULONG, ULONG*);
NTSYSAPI NTSTATUS WINAPI LdrRemoveDllDirectory(void*);
NTSYSAPI NTSTATUS WINAPI LdrSetDefaultDllDirectories(ULONG);
NTSYSAPI NTSTATUS WINAPI LdrSetDllDirectory(const UNICODE_STRING*);
NTSYSAPI void WINAPI LdrShutdownProcess(void);
NTSYSAPI void WINAPI LdrShutdownThread(void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment