diff --git a/reactos/dll/win32/kernel32/file/curdir.c b/reactos/dll/win32/kernel32/file/curdir.c index 8c74fbe11a1..42ae057f054 100644 --- a/reactos/dll/win32/kernel32/file/curdir.c +++ b/reactos/dll/win32/kernel32/file/curdir.c @@ -28,6 +28,8 @@ DEBUG_CHANNEL(kernel32file); UNICODE_STRING SystemDirectory; UNICODE_STRING WindowsDirectory; +UNICODE_STRING BaseDefaultPathAppend; +UNICODE_STRING BaseDefaultPath; /* FUNCTIONS *****************************************************************/ diff --git a/reactos/dll/win32/kernel32/file/dir.c b/reactos/dll/win32/kernel32/file/dir.c index a364e6a1f46..184403912f3 100644 --- a/reactos/dll/win32/kernel32/file/dir.c +++ b/reactos/dll/win32/kernel32/file/dir.c @@ -20,7 +20,7 @@ #include DEBUG_CHANNEL(kernel32file); -UNICODE_STRING DllDirectory = {0, 0, NULL}; +UNICODE_STRING BaseDllDirectory = {0, 0, NULL}; /* FUNCTIONS *****************************************************************/ @@ -1079,35 +1079,35 @@ SetDllDirectoryW( RtlInitUnicodeString(&PathName, lpPathName); - RtlEnterCriticalSection(&DllLock); + RtlEnterCriticalSection(&BaseDllDirectoryLock); if(PathName.Length > 0) { - if(PathName.Length + sizeof(WCHAR) <= DllDirectory.MaximumLength) + if(PathName.Length + sizeof(WCHAR) <= BaseDllDirectory.MaximumLength) { - RtlCopyUnicodeString(&DllDirectory, &PathName); + RtlCopyUnicodeString(&BaseDllDirectory, &PathName); } else { - RtlFreeUnicodeString(&DllDirectory); - if(!(DllDirectory.Buffer = (PWSTR)RtlAllocateHeap(RtlGetProcessHeap(), - 0, - PathName.Length + sizeof(WCHAR)))) + RtlFreeUnicodeString(&BaseDllDirectory); + if(!(BaseDllDirectory.Buffer = (PWSTR)RtlAllocateHeap(RtlGetProcessHeap(), + 0, + PathName.Length + sizeof(WCHAR)))) { - RtlLeaveCriticalSection(&DllLock); + RtlLeaveCriticalSection(&BaseDllDirectoryLock); SetLastError(ERROR_NOT_ENOUGH_MEMORY); return FALSE; } - DllDirectory.Length = 0; - DllDirectory.MaximumLength = PathName.Length + sizeof(WCHAR); + BaseDllDirectory.Length = 0; + BaseDllDirectory.MaximumLength = PathName.Length + sizeof(WCHAR); - RtlCopyUnicodeString(&DllDirectory, &PathName); + RtlCopyUnicodeString(&BaseDllDirectory, &PathName); } } else { - RtlFreeUnicodeString(&DllDirectory); + RtlFreeUnicodeString(&BaseDllDirectory); } - RtlLeaveCriticalSection(&DllLock); + RtlLeaveCriticalSection(&BaseDllDirectoryLock); return TRUE; } @@ -1144,10 +1144,10 @@ GetDllDirectoryW( { DWORD Ret; - RtlEnterCriticalSection(&DllLock); + RtlEnterCriticalSection(&BaseDllDirectoryLock); if(nBufferLength > 0) { - Ret = DllDirectory.Length / sizeof(WCHAR); + Ret = BaseDllDirectory.Length / sizeof(WCHAR); if(Ret > nBufferLength - 1) { Ret = nBufferLength - 1; @@ -1155,16 +1155,16 @@ GetDllDirectoryW( if(Ret > 0) { - RtlCopyMemory(lpBuffer, DllDirectory.Buffer, Ret * sizeof(WCHAR)); + RtlCopyMemory(lpBuffer, BaseDllDirectory.Buffer, Ret * sizeof(WCHAR)); } lpBuffer[Ret] = L'\0'; } else { /* include termination character, even if the string is empty! */ - Ret = (DllDirectory.Length / sizeof(WCHAR)) + 1; + Ret = (BaseDllDirectory.Length / sizeof(WCHAR)) + 1; } - RtlLeaveCriticalSection(&DllLock); + RtlLeaveCriticalSection(&BaseDllDirectoryLock); return Ret; } diff --git a/reactos/dll/win32/kernel32/include/kernel32.h b/reactos/dll/win32/kernel32/include/kernel32.h index 747c8b1b664..d6361b3bdfe 100755 --- a/reactos/dll/win32/kernel32/include/kernel32.h +++ b/reactos/dll/win32/kernel32/include/kernel32.h @@ -91,9 +91,9 @@ extern HANDLE hProcessHeap; extern HANDLE hBaseDir; extern HMODULE hCurrentModule; -extern RTL_CRITICAL_SECTION DllLock; +extern RTL_CRITICAL_SECTION BaseDllDirectoryLock; -extern UNICODE_STRING DllDirectory; +extern UNICODE_STRING BaseDllDirectory; extern LPTOP_LEVEL_EXCEPTION_FILTER GlobalTopLevelExceptionFilter; @@ -211,6 +211,12 @@ BasepMapFile(IN LPCWSTR lpApplicationName, OUT PHANDLE hSection, IN PUNICODE_STRING ApplicationName); +LPWSTR +WINAPI +BasepGetDllPath(LPWSTR FullPath, + PVOID Environment); + + PCODEPAGE_ENTRY FASTCALL IntGetCodePageEntry(UINT CodePage); diff --git a/reactos/dll/win32/kernel32/misc/console.c b/reactos/dll/win32/kernel32/misc/console.c index 2b0d253b23e..2fc95b58d5f 100644 --- a/reactos/dll/win32/kernel32/misc/console.c +++ b/reactos/dll/win32/kernel32/misc/console.c @@ -3524,7 +3524,7 @@ SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine, { BOOL Ret; - RtlEnterCriticalSection(&DllLock); + RtlEnterCriticalSection(&BaseDllDirectoryLock); if (Add) { Ret = AddConsoleCtrlHandler(HandlerRoutine); @@ -3534,7 +3534,7 @@ SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine, Ret = RemoveConsoleCtrlHandler(HandlerRoutine); } - RtlLeaveCriticalSection(&DllLock); + RtlLeaveCriticalSection(&BaseDllDirectoryLock); return(Ret); } diff --git a/reactos/dll/win32/kernel32/misc/dllmain.c b/reactos/dll/win32/kernel32/misc/dllmain.c index ae0ada2e85c..f43b9b27b69 100644 --- a/reactos/dll/win32/kernel32/misc/dllmain.c +++ b/reactos/dll/win32/kernel32/misc/dllmain.c @@ -5,6 +5,7 @@ * FILE: lib/kernel32/misc/dllmain.c * PURPOSE: Initialization * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) + * Aleksey Bragin (aleksey@reactos.org) * UPDATE HISTORY: * Created 01/11/98 */ @@ -20,6 +21,10 @@ extern UNICODE_STRING SystemDirectory; extern UNICODE_STRING WindowsDirectory; +extern UNICODE_STRING BaseDefaultPath; +extern UNICODE_STRING BaseDefaultPathAppend; + +WCHAR BaseDefaultPathBuffer[6140]; HANDLE hProcessHeap = NULL; HMODULE hCurrentModule = NULL; @@ -36,7 +41,7 @@ DllMain(HANDLE hInst, LPVOID lpReserved); /* Critical section for various kernel32 data structures */ -RTL_CRITICAL_SECTION DllLock; +RTL_CRITICAL_SECTION BaseDllDirectoryLock; RTL_CRITICAL_SECTION ConsoleLock; extern BOOL WINAPI DefaultConsoleCtrlHandler(DWORD Event); @@ -275,6 +280,9 @@ DllMain(HANDLE hDll, /* Don't bother us for each thread */ LdrDisableThreadCalloutsForDll((PVOID)hDll); + /* Initialize default path to NULL */ + RtlInitUnicodeString(&BaseDefaultPath, NULL); + /* Setup the right Object Directory path */ if (!SessionId) { @@ -332,11 +340,25 @@ DllMain(HANDLE hDll, SystemDirectory.MaximumLength); if(SystemDirectory.Buffer == NULL) { + DPRINT1("Failure allocating SystemDirectory buffer\n"); return FALSE; } wcscpy(SystemDirectory.Buffer, WindowsDirectory.Buffer); wcscat(SystemDirectory.Buffer, L"\\System32"); + /* Construct the default path (using the static buffer) */ + _snwprintf(BaseDefaultPathBuffer, sizeof(BaseDefaultPathBuffer) / sizeof(WCHAR), + L".;%wZ;%wZ\\system;%wZ;", &SystemDirectory, &WindowsDirectory, &WindowsDirectory); + + BaseDefaultPath.Buffer = BaseDefaultPathBuffer; + BaseDefaultPath.Length = wcslen(BaseDefaultPathBuffer) * sizeof(WCHAR); + BaseDefaultPath.MaximumLength = sizeof(BaseDefaultPathBuffer); + + /* Use remaining part of the default path buffer for the append path */ + BaseDefaultPathAppend.Buffer = (PWSTR)((ULONG_PTR)BaseDefaultPathBuffer + BaseDefaultPath.Length); + BaseDefaultPathAppend.Length = 0; + BaseDefaultPathAppend.MaximumLength = BaseDefaultPath.MaximumLength - BaseDefaultPath.Length; + /* Initialize command line */ InitCommandLines(); @@ -349,7 +371,7 @@ DllMain(HANDLE hDll, } /* Initialize the DLL critical section */ - RtlInitializeCriticalSection(&DllLock); + RtlInitializeCriticalSection(&BaseDllDirectoryLock); /* Initialize the National Language Support routines */ if (!NlsInit()) @@ -395,7 +417,7 @@ DllMain(HANDLE hDll, ConsoleInitialized = FALSE; RtlDeleteCriticalSection (&ConsoleLock); } - RtlDeleteCriticalSection (&DllLock); + RtlDeleteCriticalSection (&BaseDllDirectoryLock); /* Close object base directory */ NtClose(hBaseDir); diff --git a/reactos/dll/win32/kernel32/process/procsup.c b/reactos/dll/win32/kernel32/process/procsup.c index 33b053d9324..a4d35d786d7 100644 --- a/reactos/dll/win32/kernel32/process/procsup.c +++ b/reactos/dll/win32/kernel32/process/procsup.c @@ -14,6 +14,9 @@ #define NDEBUG #include +UNICODE_STRING BasePathVariableName = RTL_CONSTANT_STRING(L"PATH"); +UNICODE_STRING BaseDefaultPath; + #define CMD_STRING L"cmd /c " extern __declspec(noreturn) @@ -352,13 +355,46 @@ BasepDuplicateAndWriteHandle(IN HANDLE ProcessHandle, } } +LPWSTR +WINAPI +BasepGetProcessPath(DWORD Reserved, + LPWSTR FullPath, + PVOID Environment) +{ + return NULL; +} + LPWSTR WINAPI BasepGetDllPath(LPWSTR FullPath, PVOID Environment) { - /* FIXME: Not yet implemented */ - return NULL; + LPWSTR DllPath = NULL; + + /* Acquire DLL directory lock */ + RtlEnterCriticalSection(&BaseDllDirectoryLock); + + /* Check if we have a base dll directory */ + if (BaseDllDirectory.Buffer) + { + /* Then get process path */ + DllPath = BasepGetProcessPath(0, FullPath, Environment); + + /* Release DLL directory lock */ + RtlLeaveCriticalSection(&BaseDllDirectoryLock); + + /* Return dll path */ + return DllPath; + } + + /* Release DLL directory lock */ + RtlLeaveCriticalSection(&BaseDllDirectoryLock); + + /* There is no base DLL directory */ + UNIMPLEMENTED; + + /* Return dll path */ + return DllPath; } VOID