https://git.reactos.org/?p=reactos.git;a=commitdiff;h=4f0a158a2f6373de49414…
commit 4f0a158a2f6373de4941436370cc604632f3b650
Author: Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Thu Feb 15 22:34:48 2018 +0100
Commit: Timo Kreuzer <timo.kreuzer(a)reactos.org>
CommitDate: Sat Aug 4 19:19:34 2018 +0200
[KERNEL32] Fix 64 bit issues
---
dll/win32/kernel32/client/actctx.c | 4 ++--
dll/win32/kernel32/client/compname.c | 9 ++++++++-
dll/win32/kernel32/client/debugger.c | 4 ++--
dll/win32/kernel32/client/dllmain.c | 19 ++++++++++++-------
dll/win32/kernel32/client/except.c | 23 +++++++++++++----------
dll/win32/kernel32/client/file/npipe.c | 2 +-
dll/win32/kernel32/client/loader.c | 4 ++--
dll/win32/kernel32/client/path.c | 15 +++++++--------
dll/win32/kernel32/client/proc.c | 29 ++++++++++++++++++++++++-----
dll/win32/kernel32/client/vdm.c | 5 +++--
dll/win32/kernel32/client/virtmem.c | 4 ++--
dll/win32/kernel32/k32.h | 2 ++
12 files changed, 78 insertions(+), 42 deletions(-)
diff --git a/dll/win32/kernel32/client/actctx.c b/dll/win32/kernel32/client/actctx.c
index 302d6c86a3..cad514ef06 100644
--- a/dll/win32/kernel32/client/actctx.c
+++ b/dll/win32/kernel32/client/actctx.c
@@ -154,8 +154,8 @@ BasepProbeForDllManifest(IN PVOID DllHandle,
*ActCtx = NULL;
/* Check whether the image has manifest resource associated with it */
- Info.Type = (ULONG)RT_MANIFEST;
- Info.Name = (ULONG)ISOLATIONAWARE_MANIFEST_RESOURCE_ID;
+ Info.Type = (ULONG_PTR)RT_MANIFEST;
+ Info.Name = (ULONG_PTR)ISOLATIONAWARE_MANIFEST_RESOURCE_ID;
Info.Language = 0;
if (!(Status = LdrFindResource_U(DllHandle, &Info, 3, &Entry)))
{
diff --git a/dll/win32/kernel32/client/compname.c b/dll/win32/kernel32/client/compname.c
index a336eaa954..91860ce5af 100644
--- a/dll/win32/kernel32/client/compname.c
+++ b/dll/win32/kernel32/client/compname.c
@@ -391,8 +391,15 @@ SetComputerNameToRegistry(LPCWSTR RegistryKey,
UNICODE_STRING KeyName;
UNICODE_STRING ValueName;
HANDLE KeyHandle;
+ SIZE_T StringLength;
NTSTATUS Status;
+ StringLength = wcslen(lpBuffer);
+ if (StringLength > ((MAXULONG / sizeof(WCHAR)) - 1))
+ {
+ return FALSE;
+ }
+
RtlInitUnicodeString(&KeyName, RegistryKey);
InitializeObjectAttributes(&ObjectAttributes,
&KeyName,
@@ -416,7 +423,7 @@ SetComputerNameToRegistry(LPCWSTR RegistryKey,
0,
REG_SZ,
(PVOID)lpBuffer,
- (wcslen (lpBuffer) + 1) * sizeof(WCHAR));
+ (StringLength + 1) * sizeof(WCHAR));
if (!NT_SUCCESS(Status))
{
NtClose(KeyHandle);
diff --git a/dll/win32/kernel32/client/debugger.c b/dll/win32/kernel32/client/debugger.c
index 4420b8e765..9f84848a20 100644
--- a/dll/win32/kernel32/client/debugger.c
+++ b/dll/win32/kernel32/client/debugger.c
@@ -453,8 +453,8 @@ ContinueDebugEvent(IN DWORD dwProcessId,
NTSTATUS Status;
/* Set the Client ID */
- ClientId.UniqueProcess = (HANDLE)dwProcessId;
- ClientId.UniqueThread = (HANDLE)dwThreadId;
+ ClientId.UniqueProcess = UlongToHandle(dwProcessId);
+ ClientId.UniqueThread = UlongToHandle(dwThreadId);
/* Continue debugging */
Status = DbgUiContinue(&ClientId, dwContinueStatus);
diff --git a/dll/win32/kernel32/client/dllmain.c b/dll/win32/kernel32/client/dllmain.c
index 5c4ad13555..4e94781be4 100644
--- a/dll/win32/kernel32/client/dllmain.c
+++ b/dll/win32/kernel32/client/dllmain.c
@@ -172,15 +172,20 @@ DllMain(HANDLE hDll,
BaseWindowsSystemDirectory =
BaseStaticServerData->WindowsSystemDirectory;
/* Construct the default path (using the static buffer) */
- _snwprintf(BaseDefaultPathBuffer,
- sizeof(BaseDefaultPathBuffer) / sizeof(WCHAR),
- L".;%wZ;%wZ\\system;%wZ;",
- &BaseWindowsSystemDirectory,
- &BaseWindowsDirectory,
- &BaseWindowsDirectory);
+ Status = RtlStringCbPrintfW(BaseDefaultPathBuffer,
+ sizeof(BaseDefaultPathBuffer),
+ L".;%wZ;%wZ\\system;%wZ;",
+ &BaseWindowsSystemDirectory,
+ &BaseWindowsDirectory,
+ &BaseWindowsDirectory);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("NLS Init failed\n");
+ return FALSE;
+ }
BaseDefaultPath.Buffer = BaseDefaultPathBuffer;
- BaseDefaultPath.Length = wcslen(BaseDefaultPathBuffer) * sizeof(WCHAR);
+ BaseDefaultPath.Length = (USHORT)wcslen(BaseDefaultPathBuffer) *
sizeof(WCHAR);
BaseDefaultPath.MaximumLength = sizeof(BaseDefaultPathBuffer);
/* Use remaining part of the default path buffer for the append path */
diff --git a/dll/win32/kernel32/client/except.c b/dll/win32/kernel32/client/except.c
index 416f097a94..dbb76b7be4 100644
--- a/dll/win32/kernel32/client/except.c
+++ b/dll/win32/kernel32/client/except.c
@@ -26,8 +26,10 @@ _module_name_from_addr(const void* addr, void **module_start_addr,
char* psz, size_t nChars, char** module_name)
{
MEMORY_BASIC_INFORMATION mbi;
- if (VirtualQuery(addr, &mbi, sizeof(mbi)) != sizeof(mbi) ||
- !GetModuleFileNameA((HMODULE)mbi.AllocationBase, psz, nChars))
+
+ if ((nChars > MAXDWORD) ||
+ (VirtualQuery(addr, &mbi, sizeof(mbi)) != sizeof(mbi)) ||
+ !GetModuleFileNameA((HMODULE)mbi.AllocationBase, psz, (DWORD)nChars))
{
psz[0] = '\0';
*module_name = psz;
@@ -164,6 +166,7 @@ BasepCheckForReadOnlyResource(IN PVOID Ptr)
{
PVOID Data;
ULONG Size, OldProtect;
+ SIZE_T Size2;
MEMORY_BASIC_INFORMATION mbi;
NTSTATUS Status;
LONG Ret = EXCEPTION_CONTINUE_SEARCH;
@@ -194,10 +197,10 @@ BasepCheckForReadOnlyResource(IN PVOID Ptr)
{
/* The user tried to write into the resources. Make the page
writable... */
- Size = 1;
+ Size2 = 1;
Status = NtProtectVirtualMemory(NtCurrentProcess(),
&Ptr,
- &Size,
+ &Size2,
PAGE_READWRITE,
&OldProtect);
if (NT_SUCCESS(Status))
@@ -560,14 +563,14 @@ UnhandledExceptionFilter(IN PEXCEPTION_POINTERS ExceptionInfo)
* line. The biggest 32-bit unsigned int (0xFFFFFFFF == 4.294.967.295)
* takes 10 decimal digits. We then count the terminating NULL.
*/
- Length = wcslen(AeDebugPath) + 2*10 + 1;
+ Length = (ULONG)wcslen(AeDebugPath) + 2*10 + 1;
/* Check whether the debugger path may be a relative path */
if ((*AeDebugPath != L'"') &&
(RtlDetermineDosPathNameType_U(AeDebugPath) == RtlPathTypeRelative))
{
/* Relative path, prepend SystemRoot\System32 */
- PrependLength = wcslen(SharedUserData->NtSystemRoot) + 10 /* ==
wcslen(L"\\System32\\") */;
+ PrependLength = (ULONG)wcslen(SharedUserData->NtSystemRoot) + 10 /* ==
wcslen(L"\\System32\\") */;
if (PrependLength + Length <= ARRAYSIZE(AeDebugCmdLine))
{
hr = StringCchPrintfW(AeDebugCmdLine,
@@ -830,8 +833,8 @@ IsBadReadPtr(IN LPCVOID lp,
*Current;
/* Align the addresses */
- Current = (volatile CHAR *)ROUND_DOWN(Current, PageSize);
- Last = (PCHAR)ROUND_DOWN(Last, PageSize);
+ Current = (volatile CHAR *)ALIGN_DOWN_POINTER_BY(Current, PageSize);
+ Last = (PCHAR)ALIGN_DOWN_POINTER_BY(Last, PageSize);
/* Probe the entire range */
while (Current != Last)
@@ -908,8 +911,8 @@ IsBadWritePtr(IN LPVOID lp,
*Current = *Current;
/* Align the addresses */
- Current = (volatile CHAR *)ROUND_DOWN(Current, PageSize);
- Last = (PCHAR)ROUND_DOWN(Last, PageSize);
+ Current = (volatile CHAR *)ALIGN_DOWN_POINTER_BY(Current, PageSize);
+ Last = (PCHAR)ALIGN_DOWN_POINTER_BY(Last, PageSize);
/* Probe the entire range */
while (Current != Last)
diff --git a/dll/win32/kernel32/client/file/npipe.c
b/dll/win32/kernel32/client/file/npipe.c
index c99d600bcb..d89047d1f0 100644
--- a/dll/win32/kernel32/client/file/npipe.c
+++ b/dll/win32/kernel32/client/file/npipe.c
@@ -142,7 +142,7 @@ CreatePipe(PHANDLE hReadPipe,
/* Create the pipe name */
swprintf(Buffer,
- L"\\Device\\NamedPipe\\Win32Pipes.%08x.%08x",
+ L"\\Device\\NamedPipe\\Win32Pipes.%p.%08x",
NtCurrentTeb()->ClientId.UniqueProcess,
PipeId);
RtlInitUnicodeString(&PipeName, Buffer);
diff --git a/dll/win32/kernel32/client/loader.c b/dll/win32/kernel32/client/loader.c
index 82f8c7d988..a6f84ba87e 100644
--- a/dll/win32/kernel32/client/loader.c
+++ b/dll/win32/kernel32/client/loader.c
@@ -404,7 +404,7 @@ GetProcAddress(HMODULE hModule, LPCSTR lpProcName)
PVOID hMapped;
ULONG Ordinal = 0;
- if (HIWORD(lpProcName) != 0)
+ if ((ULONG_PTR)lpProcName > MAXUSHORT)
{
/* Look up by name */
RtlInitAnsiString(&ProcedureName, (LPSTR)lpProcName);
@@ -413,7 +413,7 @@ GetProcAddress(HMODULE hModule, LPCSTR lpProcName)
else
{
/* Look up by ordinal */
- Ordinal = (ULONG)lpProcName;
+ Ordinal = PtrToUlong(lpProcName);
}
/* Map provided handle */
diff --git a/dll/win32/kernel32/client/path.c b/dll/win32/kernel32/client/path.c
index 7d91c052a8..1db908212f 100644
--- a/dll/win32/kernel32/client/path.c
+++ b/dll/win32/kernel32/client/path.c
@@ -118,7 +118,7 @@ BasepComputeProcessPath(IN PBASE_SEARCH_PATH_TYPE PathOrder,
IN LPVOID Environment)
{
PWCHAR PathBuffer, Buffer, AppNameEnd, PathCurrent;
- ULONG PathLengthInBytes;
+ SIZE_T PathLengthInBytes;
NTSTATUS Status;
UNICODE_STRING EnvPath;
PBASE_SEARCH_PATH_TYPE Order;
@@ -1040,7 +1040,7 @@ GetFullPathNameA(IN LPCSTR lpFileName,
/* Yep, so in this case get the length of the file part too */
Status = RtlUnicodeToMultiByteSize(&FilePartSize,
Buffer,
- (LocalFilePart - Buffer) *
+ (ULONG)(LocalFilePart - Buffer) *
sizeof(WCHAR));
if (!NT_SUCCESS(Status))
{
@@ -1231,7 +1231,7 @@ SearchPathA(IN LPCSTR lpPath OPTIONAL,
/* Yep, so in this case get the length of the file part too */
Status = RtlUnicodeToMultiByteSize(&FilePartSize,
Buffer,
- (LocalFilePart - Buffer) *
+ (ULONG)(LocalFilePart - Buffer) *
sizeof(WCHAR));
if (!NT_SUCCESS(Status))
{
@@ -1302,7 +1302,8 @@ SearchPathW(IN LPCWSTR lpPath OPTIONAL,
OUT LPWSTR *lpFilePart OPTIONAL)
{
UNICODE_STRING FileNameString, ExtensionString, PathString, CallerBuffer;
- ULONG Flags, LengthNeeded, FilePartSize;
+ ULONG Flags;
+ SIZE_T LengthNeeded, FilePartSize;
NTSTATUS Status;
DWORD Result = 0;
@@ -1456,10 +1457,9 @@ GetLongPathNameW(IN LPCWSTR lpszShortPath,
IN DWORD cchBuffer)
{
PWCHAR Path, Original, First, Last, Buffer, Src, Dst;
- ULONG Length;
+ SIZE_T Length, ReturnLength;
WCHAR LastChar;
HANDLE FindHandle;
- DWORD ReturnLength;
ULONG ErrorMode;
BOOLEAN Found = FALSE;
WIN32_FIND_DATAW FindFileData;
@@ -1834,10 +1834,9 @@ GetShortPathNameW(IN LPCWSTR lpszLongPath,
IN DWORD cchBuffer)
{
PWCHAR Path, Original, First, Last, Buffer, Src, Dst;
- ULONG Length;
+ SIZE_T Length, ReturnLength;
WCHAR LastChar;
HANDLE FindHandle;
- DWORD ReturnLength;
ULONG ErrorMode;
BOOLEAN Found = FALSE;
WIN32_FIND_DATAW FindFileData;
diff --git a/dll/win32/kernel32/client/proc.c b/dll/win32/kernel32/client/proc.c
index 551723e3b7..dbd5c10d0f 100644
--- a/dll/win32/kernel32/client/proc.c
+++ b/dll/win32/kernel32/client/proc.c
@@ -440,7 +440,7 @@ BasepSxsCloseHandles(IN PBASE_MSG_SXS_HANDLES Handles)
if (Handles->ViewBase.QuadPart)
{
Status = NtUnmapViewOfSection(NtCurrentProcess(),
- (PVOID)Handles->ViewBase.LowPart);
+ (PVOID)(ULONG_PTR)Handles->ViewBase.QuadPart);
ASSERT(NT_SUCCESS(Status));
}
}
@@ -2310,7 +2310,8 @@ CreateProcessInternalW(IN HANDLE hUserToken,
SECTION_IMAGE_INFORMATION ImageInformation;
IO_STATUS_BLOCK IoStatusBlock;
CLIENT_ID ClientId;
- ULONG NoWindow, RegionSize, StackSize, ErrorCode, Flags;
+ ULONG NoWindow, StackSize, ErrorCode, Flags;
+ SIZE_T RegionSize;
USHORT ImageMachine;
ULONG ParameterFlags, PrivilegeValue, HardErrorMode, ErrorResponse;
ULONG_PTR ErrorParameters[2];
@@ -2342,7 +2343,8 @@ CreateProcessInternalW(IN HANDLE hUserToken,
SIZE_T n;
WCHAR SaveChar;
ULONG Length, FileAttribs, CmdQuoteLength;
- ULONG CmdLineLength, ResultSize;
+ ULONG ResultSize;
+ SIZE_T EnvironmentLength, CmdLineLength;
PWCHAR QuotedCmdLine, AnsiCmdCommand, ExtBuffer, CurrentDirectory;
PWCHAR NullBuffer, ScanString, NameBuffer, SearchPath, DebuggerCmdLine;
ANSI_STRING AnsiEnv;
@@ -2571,8 +2573,17 @@ CreateProcessInternalW(IN HANDLE hUserToken,
AnsiEnv.Buffer = pcScan = (PCHAR)lpEnvironment;
while ((*pcScan) || (*(pcScan + 1))) ++pcScan;
+ /* Make sure the environment is not too large */
+ EnvironmentLength = (pcScan + sizeof(ANSI_NULL) - (PCHAR)lpEnvironment);
+ if (EnvironmentLength > MAXUSHORT)
+ {
+ /* Fail */
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return FALSE;
+ }
+
/* Create our ANSI String */
- AnsiEnv.Length = pcScan - (PCHAR)lpEnvironment + sizeof(ANSI_NULL);
+ AnsiEnv.Length = (USHORT)EnvironmentLength;
AnsiEnv.MaximumLength = AnsiEnv.Length + sizeof(ANSI_NULL);
/* Allocate memory for the Unicode Environment */
@@ -4003,10 +4014,11 @@ StartScan:
if (VdmReserve)
{
/* Reserve the requested allocation */
+ RegionSize = VdmReserve;
Status = NtAllocateVirtualMemory(ProcessHandle,
&BaseAddress,
0,
- &VdmReserve,
+ &RegionSize,
MEM_RESERVE,
PAGE_EXECUTE_READWRITE);
if (!NT_SUCCESS(Status))
@@ -4017,6 +4029,8 @@ StartScan:
Result = FALSE;
goto Quickie;
}
+
+ VdmReserve = (ULONG)RegionSize;
}
/* Check if we've already queried information on the section */
@@ -4267,7 +4281,12 @@ StartScan:
/* Write the remote PEB address and clear it locally, we no longer use it */
CreateProcessMsg->PebAddressNative = RemotePeb;
+#ifdef _WIN64
+ DPRINT1("TODO: WOW64 is not supported yet\n");
+ CreateProcessMsg->PebAddressWow64 = 0;
+#else
CreateProcessMsg->PebAddressWow64 = (ULONG)RemotePeb;
+#endif
RemotePeb = NULL;
/* Now check what kind of architecture this image was made for */
diff --git a/dll/win32/kernel32/client/vdm.c b/dll/win32/kernel32/client/vdm.c
index a3cb7cd01d..ff6e785129 100644
--- a/dll/win32/kernel32/client/vdm.c
+++ b/dll/win32/kernel32/client/vdm.c
@@ -746,7 +746,8 @@ BaseCreateVDMEnvironment(IN PWCHAR lpEnvironment,
BOOL Success = FALSE;
NTSTATUS Status;
- ULONG RegionSize, EnvironmentSize = 0;
+ ULONG EnvironmentSize = 0;
+ SIZE_T RegionSize;
PWCHAR Environment, NewEnvironment = NULL;
ENV_NAME_TYPE NameType;
ULONG NameLength, NumChars, Remaining;
@@ -1025,7 +1026,7 @@ NTAPI
BaseDestroyVDMEnvironment(IN PANSI_STRING AnsiEnv,
IN PUNICODE_STRING UnicodeEnv)
{
- ULONG Dummy = 0;
+ SIZE_T Dummy = 0;
/* Clear the ANSI buffer since Rtl creates this for us */
if (AnsiEnv->Buffer) RtlFreeAnsiString(AnsiEnv);
diff --git a/dll/win32/kernel32/client/virtmem.c b/dll/win32/kernel32/client/virtmem.c
index acf2e13282..7b4085c0ba 100644
--- a/dll/win32/kernel32/client/virtmem.c
+++ b/dll/win32/kernel32/client/virtmem.c
@@ -29,8 +29,8 @@ VirtualAllocEx(IN HANDLE hProcess,
NTSTATUS Status;
/* Make sure the address is within the granularity of the system (64K) */
- if ((lpAddress) &&
- (lpAddress < (PVOID)BaseStaticServerData->SysInfo.AllocationGranularity))
+ if ((lpAddress != NULL) &&
+ (lpAddress <
UlongToPtr(BaseStaticServerData->SysInfo.AllocationGranularity)))
{
/* Fail the call */
SetLastError(ERROR_INVALID_PARAMETER);
diff --git a/dll/win32/kernel32/k32.h b/dll/win32/kernel32/k32.h
index 52e5a8b5c2..604953680d 100644
--- a/dll/win32/kernel32/k32.h
+++ b/dll/win32/kernel32/k32.h
@@ -45,6 +45,8 @@
#include <ndk/setypes.h>
#include <ndk/umfuncs.h>
+#include <ntstrsafe.h>
+
/* CSRSS Headers */
#include <csr/csr.h>
#include <win/base.h>