kernel32: Move exe path functions to ntdll.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2019-10-03 19:26:01 +02:00
parent 619bd16e7a
commit a5d45e9ae5
5 changed files with 116 additions and 5 deletions

View File

@ -438,11 +438,18 @@ static HANDLE open_exe_file( const WCHAR *name, BOOL *is_64bit )
*/ */
static BOOL find_exe_file( const WCHAR *name, WCHAR *buffer, int buflen, HANDLE *handle ) static BOOL find_exe_file( const WCHAR *name, WCHAR *buffer, int buflen, HANDLE *handle )
{ {
TRACE("looking for %s\n", debugstr_w(name) ); WCHAR *load_path;
BOOL ret;
if (!SearchPathW( NULL, name, exeW, buflen, buffer, NULL ) && if (!set_ntstatus( RtlGetExePath( name, &load_path ))) return FALSE;
/* no builtin found, try native without extension in case it is a Unix app */
!SearchPathW( NULL, name, NULL, buflen, buffer, NULL )) return FALSE; TRACE("looking for %s in %s\n", debugstr_w(name), debugstr_w(load_path) );
ret = (SearchPathW( load_path, name, exeW, buflen, buffer, NULL ) ||
/* no builtin found, try native without extension in case it is a Unix app */
SearchPathW( load_path, name, NULL, buflen, buffer, NULL ));
RtlReleasePath( load_path );
if (!ret) return FALSE;
TRACE( "Trying native exe %s\n", debugstr_w(buffer) ); TRACE( "Trying native exe %s\n", debugstr_w(buffer) );
*handle = CreateFileW( buffer, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_DELETE, *handle = CreateFileW( buffer, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_DELETE,
@ -1412,12 +1419,14 @@ void * CDECL __wine_kernel_init(void)
{ {
BOOL is_64bit; BOOL is_64bit;
if (!SearchPathW( NULL, __wine_main_wargv[0], exeW, MAX_PATH, main_exe_name, NULL ) && RtlGetExePath( __wine_main_wargv[0], &load_path );
if (!SearchPathW( load_path, __wine_main_wargv[0], exeW, MAX_PATH, main_exe_name, NULL ) &&
!get_builtin_path( __wine_main_wargv[0], exeW, main_exe_name, MAX_PATH, &is_64bit )) !get_builtin_path( __wine_main_wargv[0], exeW, main_exe_name, MAX_PATH, &is_64bit ))
{ {
MESSAGE( "wine: cannot find '%s'\n", __wine_main_argv[0] ); MESSAGE( "wine: cannot find '%s'\n", __wine_main_argv[0] );
ExitProcess( GetLastError() ); ExitProcess( GetLastError() );
} }
RtlReleasePath( load_path );
update_library_argv0( main_exe_name ); update_library_argv0( main_exe_name );
if (!build_command_line( __wine_main_wargv )) goto error; if (!build_command_line( __wine_main_wargv )) goto error;
start_wineboot( boot_events ); start_wineboot( boot_events );

View File

@ -78,6 +78,7 @@ static BOOL (WINAPI *pRemoveDllDirectory)(DLL_DIRECTORY_COOKIE);
static BOOL (WINAPI *pSetSearchPathMode)(DWORD); static BOOL (WINAPI *pSetSearchPathMode)(DWORD);
static BOOL (WINAPI *pSetDllDirectoryW)(LPCWSTR); static BOOL (WINAPI *pSetDllDirectoryW)(LPCWSTR);
static BOOL (WINAPI *pSetDefaultDllDirectories)(DWORD); static BOOL (WINAPI *pSetDefaultDllDirectories)(DWORD);
static NTSTATUS (WINAPI *pRtlGetExePath)(LPCWSTR,LPWSTR*);
static NTSTATUS (WINAPI *pRtlGetSearchPath)(LPWSTR*); static NTSTATUS (WINAPI *pRtlGetSearchPath)(LPWSTR*);
static void (WINAPI *pRtlReleasePath)(LPWSTR); static void (WINAPI *pRtlReleasePath)(LPWSTR);
static NTSTATUS (WINAPI *pLdrGetDllPath)(LPCWSTR,ULONG,LPWSTR*,LPWSTR*); static NTSTATUS (WINAPI *pLdrGetDllPath)(LPCWSTR,ULONG,LPWSTR*,LPWSTR*);
@ -2218,6 +2219,7 @@ static void init_pointers(void)
MAKEFUNC(CheckNameLegalDOS8Dot3A); MAKEFUNC(CheckNameLegalDOS8Dot3A);
mod = GetModuleHandleA("ntdll.dll"); mod = GetModuleHandleA("ntdll.dll");
MAKEFUNC(LdrGetDllPath); MAKEFUNC(LdrGetDllPath);
MAKEFUNC(RtlGetExePath);
MAKEFUNC(RtlGetSearchPath); MAKEFUNC(RtlGetSearchPath);
MAKEFUNC(RtlReleasePath); MAKEFUNC(RtlReleasePath);
#undef MAKEFUNC #undef MAKEFUNC
@ -2570,6 +2572,78 @@ static void test_RtlGetSearchPath(void)
SetEnvironmentVariableW( pathW, old_path ); SetEnvironmentVariableW( pathW, old_path );
} }
static void test_RtlGetExePath(void)
{
static const WCHAR fooW[] = {'\\','f','o','o',0};
static const WCHAR emptyW[1];
NTSTATUS ret;
WCHAR *path;
WCHAR buffer[2048], old_path[2048], dlldir[4];
if (!pRtlGetExePath)
{
win_skip( "RtlGetExePath isn't available\n" );
return;
}
GetEnvironmentVariableW( pathW, old_path, ARRAY_SIZE(old_path) );
GetWindowsDirectoryW( buffer, ARRAY_SIZE(buffer) );
lstrcpynW( dlldir, buffer, ARRAY_SIZE(dlldir) );
SetEnvironmentVariableA( "NoDefaultCurrentDirectoryInExePath", NULL );
build_search_path( buffer, ARRAY_SIZE(buffer), NULL, FALSE );
path = (WCHAR *)0xdeadbeef;
ret = pRtlGetExePath( fooW, &path );
ok( !ret, "RtlGetExePath failed %x\n", ret );
ok( path_equal( path, buffer ), "got %s expected %s\n", wine_dbgstr_w(path), wine_dbgstr_w(buffer));
pRtlReleasePath( path );
build_search_path( buffer, ARRAY_SIZE(buffer), NULL, FALSE );
path = (WCHAR *)0xdeadbeef;
ret = pRtlGetExePath( fooW + 1, &path );
ok( !ret, "RtlGetExePath failed %x\n", ret );
ok( path_equal( path, buffer ), "got %s expected %s\n", wine_dbgstr_w(path), wine_dbgstr_w(buffer));
pRtlReleasePath( path );
SetEnvironmentVariableA( "NoDefaultCurrentDirectoryInExePath", "yes" );
build_search_path( buffer, ARRAY_SIZE(buffer), NULL, FALSE );
path = (WCHAR *)0xdeadbeef;
ret = pRtlGetExePath( fooW, &path );
ok( !ret, "RtlGetExePath failed %x\n", ret );
ok( path_equal( path, buffer ), "got %s expected %s\n", wine_dbgstr_w(path), wine_dbgstr_w(buffer));
pRtlReleasePath( path );
build_search_path( buffer, ARRAY_SIZE(buffer), emptyW, TRUE );
path = (WCHAR *)0xdeadbeef;
ret = pRtlGetExePath( fooW + 1, &path );
ok( !ret, "RtlGetExePath failed %x\n", ret );
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, FALSE );
path = (WCHAR *)0xdeadbeef;
ret = pRtlGetExePath( fooW, &path );
ok( !ret, "RtlGetExePath 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 (pSetDllDirectoryW)
{
ok( pSetDllDirectoryW( dlldir ), "SetDllDirectoryW failed\n" );
build_search_path( buffer, ARRAY_SIZE(buffer), NULL, FALSE );
path = (WCHAR *)0xdeadbeef;
ret = pRtlGetExePath( fooW, &path );
ok( !ret, "RtlGetExePath failed %x\n", ret );
ok( path_equal( path, buffer ), "got %s expected %s\n", wine_dbgstr_w(path), wine_dbgstr_w(buffer));
pRtlReleasePath( path );
pSetDllDirectoryW( NULL );
}
SetEnvironmentVariableW( pathW, old_path );
}
static void test_LdrGetDllPath(void) static void test_LdrGetDllPath(void)
{ {
static const WCHAR fooW[] = {'f','o','o',0}; static const WCHAR fooW[] = {'f','o','o',0};
@ -2705,5 +2779,6 @@ START_TEST(path)
test_CheckNameLegalDOS8Dot3(); test_CheckNameLegalDOS8Dot3();
test_SetSearchPathMode(); test_SetSearchPathMode();
test_RtlGetSearchPath(); test_RtlGetSearchPath();
test_RtlGetExePath();
test_LdrGetDllPath(); test_LdrGetDllPath();
} }

View File

@ -4132,6 +4132,31 @@ NTSTATUS WINAPI RtlSetSearchPathMode( ULONG flags )
} }
/******************************************************************
* RtlGetExePath (NTDLL.@)
*/
NTSTATUS WINAPI RtlGetExePath( PCWSTR name, PWSTR *path )
{
static const WCHAR emptyW[1];
const WCHAR *dlldir = dotW;
const WCHAR *module = NtCurrentTeb()->Peb->ProcessParameters->ImagePathName.Buffer;
/* same check as NeedCurrentDirectoryForExePathW */
if (!strchrW( name, '\\' ))
{
static const WCHAR env_name[] = {'N','o','D','e','f','a','u','l','t','C','u','r','r','e','n','t',
'D','i','r','e','c','t','o','r','y','I','n',
'E','x','e','P','a','t','h',0};
UNICODE_STRING name, value = { 0 };
RtlInitUnicodeString( &name, env_name );
if (RtlQueryEnvironmentVariable_U( NULL, &name, &value ) != STATUS_VARIABLE_NOT_FOUND)
dlldir = emptyW;
}
return get_dll_load_path( module, dlldir, FALSE, path );
}
/****************************************************************** /******************************************************************
* RtlGetSearchPath (NTDLL.@) * RtlGetSearchPath (NTDLL.@)
*/ */

View File

@ -687,6 +687,7 @@
@ stdcall RtlGetDaclSecurityDescriptor(ptr ptr ptr ptr) @ stdcall RtlGetDaclSecurityDescriptor(ptr ptr ptr ptr)
@ stub RtlGetElementGenericTable @ stub RtlGetElementGenericTable
# @ stub RtlGetElementGenericTableAvl # @ stub RtlGetElementGenericTableAvl
@ stdcall RtlGetExePath(wstr ptr)
# @ stub RtlGetFirstRange # @ stub RtlGetFirstRange
@ stdcall RtlGetFrame() @ stdcall RtlGetFrame()
@ stdcall RtlGetFullPathName_U(wstr long ptr ptr) @ stdcall RtlGetFullPathName_U(wstr long ptr ptr)

View File

@ -2724,6 +2724,7 @@ NTSYSAPI NTSTATUS WINAPI RtlGetControlSecurityDescriptor(PSECURITY_DESCRIPTOR,
NTSYSAPI ULONG WINAPI RtlGetCurrentDirectory_U(ULONG, LPWSTR); NTSYSAPI ULONG WINAPI RtlGetCurrentDirectory_U(ULONG, LPWSTR);
NTSYSAPI PEB * WINAPI RtlGetCurrentPeb(void); NTSYSAPI PEB * WINAPI RtlGetCurrentPeb(void);
NTSYSAPI NTSTATUS WINAPI RtlGetDaclSecurityDescriptor(PSECURITY_DESCRIPTOR,PBOOLEAN,PACL *,PBOOLEAN); NTSYSAPI NTSTATUS WINAPI RtlGetDaclSecurityDescriptor(PSECURITY_DESCRIPTOR,PBOOLEAN,PACL *,PBOOLEAN);
NTSYSAPI NTSTATUS WINAPI RtlGetExePath(PCWSTR,PWSTR*);
NTSYSAPI TEB_ACTIVE_FRAME * WINAPI RtlGetFrame(void); NTSYSAPI TEB_ACTIVE_FRAME * WINAPI RtlGetFrame(void);
NTSYSAPI ULONG WINAPI RtlGetFullPathName_U(PCWSTR,ULONG,PWSTR,PWSTR*); NTSYSAPI ULONG WINAPI RtlGetFullPathName_U(PCWSTR,ULONG,PWSTR,PWSTR*);
NTSYSAPI NTSTATUS WINAPI RtlGetGroupSecurityDescriptor(PSECURITY_DESCRIPTOR,PSID *,PBOOLEAN); NTSYSAPI NTSTATUS WINAPI RtlGetGroupSecurityDescriptor(PSECURITY_DESCRIPTOR,PSID *,PBOOLEAN);