[KERNEL32]

- Rename global vars to some better names (some of the names seen in Windows 2003 asserts and text messages).
- Add BaseDefaultPath initialization, which will be needed but the new kernel32/ldr code, which is in turn required by the new ntdll/ldr code.
- Add some beginnings of BasepGetDllPath(), but it returns NULL anyway now so no change in execution.

svn path=/trunk/; revision=51197
This commit is contained in:
Aleksey Bragin 2011-03-29 21:48:13 +00:00
parent ed27eba843
commit a77d09adf9
6 changed files with 94 additions and 28 deletions

View file

@ -28,6 +28,8 @@ DEBUG_CHANNEL(kernel32file);
UNICODE_STRING SystemDirectory;
UNICODE_STRING WindowsDirectory;
UNICODE_STRING BaseDefaultPathAppend;
UNICODE_STRING BaseDefaultPath;
/* FUNCTIONS *****************************************************************/

View file

@ -20,7 +20,7 @@
#include <debug.h>
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;
}

View file

@ -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);

View file

@ -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);
}

View file

@ -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);

View file

@ -14,6 +14,9 @@
#define NDEBUG
#include <debug.h>
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