Author: tkreuzer
Date: Sat Dec 22 17:58:53 2012
New Revision: 57971
URL: http://svn.reactos.org/svn/reactos?rev=57971&view=rev
Log:
[WIN32K]
- Move some files to more appropriate locations
- Remove an empty file
Added:
trunk/reactos/win32ss/gdi/eng/math.c
- copied unchanged from r57947, trunk/reactos/win32ss/user/ntuser/misc/math.c
trunk/reactos/win32ss/user/ntuser/usrheap.c
- copied unchanged from r57947, trunk/reactos/win32ss/user/ntuser/misc/usrheap.c
Removed:
trunk/reactos/win32ss/user/ntuser/misc/driver.c
trunk/reactos/win32ss/user/ntuser/misc/math.c
trunk/reactos/win32ss/user/ntuser/misc/usrheap.c
Modified:
trunk/reactos/win32ss/CMakeLists.txt
Modified: trunk/reactos/win32ss/CMakeLists.txt
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/CMakeLists.txt?rev…
==============================================================================
--- trunk/reactos/win32ss/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/reactos/win32ss/CMakeLists.txt [iso-8859-1] Sat Dec 22 17:58:53 2012
@@ -70,6 +70,7 @@
gdi/eng/lineto.c
gdi/eng/ldevobj.c
gdi/eng/mapping.c
+ gdi/eng/math.c
gdi/eng/mem.c
gdi/eng/engmisc.c
gdi/eng/mouse.c
@@ -87,11 +88,9 @@
gdi/eng/xlateobj.c
user/ntuser/main.c
user/ntuser/misc/file.c
- user/ntuser/misc/math.c
user/ntuser/misc/rtlstr.c
user/ntuser/misc/copy.c
user/ntuser/misc/registry.c
- user/ntuser/misc/usrheap.c
reactx/ntddraw/ddraw.c
reactx/ntddraw/dd.c
reactx/ntddraw/ddsurf.c
@@ -135,6 +134,7 @@
user/ntuser/sysparams.c
user/ntuser/timer.c
user/ntuser/useratom.c
+ user/ntuser/usrheap.c
user/ntuser/vis.c
user/ntuser/windc.c
user/ntuser/window.c
Removed: trunk/reactos/win32ss/user/ntuser/misc/driver.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/ntuser/misc/d…
==============================================================================
--- trunk/reactos/win32ss/user/ntuser/misc/driver.c [iso-8859-1] (original)
+++ trunk/reactos/win32ss/user/ntuser/misc/driver.c (removed)
@@ -1,1 +1,0 @@
-
Removed: trunk/reactos/win32ss/user/ntuser/misc/math.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/ntuser/misc/m…
==============================================================================
--- trunk/reactos/win32ss/user/ntuser/misc/math.c [iso-8859-1] (original)
+++ trunk/reactos/win32ss/user/ntuser/misc/math.c (removed)
@@ -1,73 +1,0 @@
-/* Math functions for i387.
- Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by John C. Bowman <bowman(a)ipp-garching.mpg.de>, 1995.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, write to the Free
- Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
-*/
-
-#include <win32k.h>
-
-/*
- * FIXME: Is there a better algorithm, like FT_MulDiv?
- *
- * @implemented
- */
-INT APIENTRY EngMulDiv(
- INT nMultiplicand,
- INT nMultiplier,
- INT nDivisor)
-{
-#if SIZEOF_LONG_LONG >= 8
- long long ret;
-
- if (!nDivisor) return -1;
-
- /* We want to deal with a positive divisor to simplify the logic. */
- if (nDivisor < 0)
- {
- nMultiplicand = - nMultiplicand;
- nDivisor = -nDivisor;
- }
-
- /* If the result is positive, we "add" to round. else, we subtract to round. */
- if ( ( (nMultiplicand < 0) && (nMultiplier < 0) ) ||
- ( (nMultiplicand >= 0) && (nMultiplier >= 0) ) )
- ret = (((long long)nMultiplicand * nMultiplier) + (nDivisor/2)) / nDivisor;
- else
- ret = (((long long)nMultiplicand * nMultiplier) - (nDivisor/2)) / nDivisor;
-
- if ((ret > 2147483647) || (ret < -2147483647)) return -1;
- return ret;
-#else
- if (!nDivisor) return -1;
-
- /* We want to deal with a positive divisor to simplify the logic. */
- if (nDivisor < 0)
- {
- nMultiplicand = - nMultiplicand;
- nDivisor = -nDivisor;
- }
-
- /* If the result is positive, we "add" to round. else, we subtract to round. */
- if ( ( (nMultiplicand < 0) && (nMultiplier < 0) ) ||
- ( (nMultiplicand >= 0) && (nMultiplier >= 0) ) )
- return ((nMultiplicand * nMultiplier) + (nDivisor/2)) / nDivisor;
-
- return ((nMultiplicand * nMultiplier) - (nDivisor/2)) / nDivisor;
-
-#endif
-}
Removed: trunk/reactos/win32ss/user/ntuser/misc/usrheap.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/ntuser/misc/u…
==============================================================================
--- trunk/reactos/win32ss/user/ntuser/misc/usrheap.c [iso-8859-1] (original)
+++ trunk/reactos/win32ss/user/ntuser/misc/usrheap.c (removed)
@@ -1,227 +1,0 @@
-/*
- * ReactOS W32 Subsystem
- * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include <win32k.h>
-
-#define NDEBUG
-#include <debug.h>
-
-
-_Function_class_(RTL_HEAP_COMMIT_ROUTINE)
-_IRQL_requires_same_
-static
-NTSTATUS
-NTAPI
-IntUserHeapCommitRoutine(
- _In_ PVOID Base,
- _Inout_ PVOID *CommitAddress,
- _Inout_ PSIZE_T CommitSize)
-{
- PPROCESSINFO W32Process;
- PW32HEAP_USER_MAPPING Mapping;
- PVOID UserBase = NULL;
- NTSTATUS Status;
- SIZE_T Delta;
- PVOID UserCommitAddress;
-
- W32Process = PsGetCurrentProcessWin32Process();
-
- if (W32Process != NULL)
- {
- /* Search for the mapping */
- Mapping = &W32Process->HeapMappings;
- while (Mapping != NULL)
- {
- if (Mapping->KernelMapping == Base)
- {
- UserBase = Mapping->UserMapping;
- break;
- }
-
- Mapping = Mapping->Next;
- }
-
- ASSERT(UserBase != NULL);
- }
- else
- {
- SIZE_T ViewSize = 0;
- LARGE_INTEGER Offset;
- extern PSECTION_OBJECT GlobalUserHeapSection;
-
- /* HACK: This needs to be handled during startup only... */
- ASSERT(Base == (PVOID)GlobalUserHeap);
-
- /* Temporarily map it into user space */
- Offset.QuadPart = 0;
- Status = MmMapViewOfSection(GlobalUserHeapSection,
- PsGetCurrentProcess(),
- &UserBase,
- 0,
- 0,
- &Offset,
- &ViewSize,
- ViewUnmap,
- SEC_NO_CHANGE,
- PAGE_EXECUTE_READ); /* Would prefer PAGE_READONLY, but thanks to RTL heaps... */
-
- if (!NT_SUCCESS(Status))
- return Status;
- }
-
- /* Apply the commit address offset to the user base address */
- Delta = (SIZE_T) ((ULONG_PTR) (*CommitAddress) - (ULONG_PTR) (Base));
- UserCommitAddress = (PVOID) ((ULONG_PTR) (UserBase) + Delta);
-
- /* Perform the actual commit */
- Status = ZwAllocateVirtualMemory(NtCurrentProcess(),
- &UserCommitAddress,
- 0,
- CommitSize,
- MEM_COMMIT,
- PAGE_EXECUTE_READ);
-
- if (NT_SUCCESS(Status))
- {
- /* Determine the address to return */
- Delta = (SIZE_T) ((ULONG_PTR) (UserCommitAddress) - (ULONG_PTR) (UserBase));
- *CommitAddress = (PVOID) ((ULONG_PTR) (Base) + Delta);
- }
-
- if (W32Process == NULL)
- {
- MmUnmapViewOfSection(PsGetCurrentProcess(),
- UserBase);
- }
-
- return Status;
-}
-
-static PWIN32HEAP
-IntUserHeapCreate(IN PSECTION_OBJECT SectionObject,
- IN PVOID *SystemMappedBase,
- IN ULONG HeapSize)
-{
- PVOID MappedView = NULL;
- LARGE_INTEGER Offset;
- SIZE_T ViewSize = PAGE_SIZE;
- RTL_HEAP_PARAMETERS Parameters = {0};
- PVOID pHeap;
- NTSTATUS Status;
-
- Offset.QuadPart = 0;
-
- /* Commit the first page before creating the heap! */
- Status = MmMapViewOfSection(SectionObject,
- PsGetCurrentProcess(),
- &MappedView,
- 0,
- 0,
- &Offset,
- &ViewSize,
- ViewUnmap,
- SEC_NO_CHANGE,
- PAGE_EXECUTE_READ); /* Would prefer PAGE_READONLY, but thanks to RTL heaps... */
- if (!NT_SUCCESS(Status))
- return NULL;
-
- Status = ZwAllocateVirtualMemory(NtCurrentProcess(),
- &MappedView,
- 0,
- &ViewSize,
- MEM_COMMIT,
- PAGE_EXECUTE_READ); /* Would prefer PAGE_READONLY, but thanks to RTL heaps... */
-
- MmUnmapViewOfSection(PsGetCurrentProcess(),
- MappedView);
-
- if (!NT_SUCCESS(Status))
- return NULL;
-
- /* Create the heap, don't serialize in kmode! The caller is responsible
- to synchronize the heap! */
- Parameters.Length = sizeof(Parameters);
- Parameters.InitialCommit = ViewSize;
- Parameters.InitialReserve = (SIZE_T)HeapSize;
- Parameters.CommitRoutine = IntUserHeapCommitRoutine;
-
- pHeap = RtlCreateHeap(HEAP_ZERO_MEMORY | HEAP_NO_SERIALIZE,
- *SystemMappedBase,
- (SIZE_T)HeapSize,
- ViewSize,
- NULL,
- &Parameters);
-
- return pHeap;
-}
-
-PWIN32HEAP
-UserCreateHeap(OUT PSECTION_OBJECT *SectionObject,
- IN OUT PVOID *SystemBase,
- IN SIZE_T HeapSize)
-{
- LARGE_INTEGER SizeHeap;
- PWIN32HEAP pHeap = NULL;
- NTSTATUS Status;
-
- SizeHeap.QuadPart = HeapSize;
-
- /* Create the section and map it into session space */
- Status = MmCreateSection((PVOID*)SectionObject,
- SECTION_ALL_ACCESS,
- NULL,
- &SizeHeap,
- PAGE_EXECUTE_READWRITE, /* Would prefer PAGE_READWRITE, but thanks to RTL heaps... */
- SEC_RESERVE | 1,
- NULL,
- NULL);
-
- if (!NT_SUCCESS(Status))
- {
- SetLastNtError(Status);
- return FALSE;
- }
-
- Status = MmMapViewInSessionSpace(*SectionObject,
- SystemBase,
- &HeapSize);
- if (!NT_SUCCESS(Status))
- {
- ObDereferenceObject(*SectionObject);
- *SectionObject = NULL;
-
- SetLastNtError(Status);
- return FALSE;
- }
-
- /* Create the heap */
- pHeap = IntUserHeapCreate(*SectionObject,
- SystemBase,
- HeapSize);
-
- if (pHeap == NULL)
- {
- ObDereferenceObject(*SectionObject);
- *SectionObject = NULL;
-
- SetLastNtError(STATUS_UNSUCCESSFUL);
- }
-
- return pHeap;
-}
Author: tkreuzer
Date: Sat Dec 22 17:43:20 2012
New Revision: 57970
URL: http://svn.reactos.org/svn/reactos?rev=57970&view=rev
Log:
[WIN32K]
- Rewrite NtUserGetAtomName, make it return the length in WCHARs instead of bytes, as it is supposed to be. Fix a buffer overrun, when the caller passes a too large UNICODE_STRING buffer. Probe the output buffers before accessing them. Makes sure the target string is always NULL terminated, even if the buffer is too small for the whole name.
- Remove NULL termination code from IntGetAtomName, since that is already done by RtlQueryAtomInAtomTable
Modified:
trunk/reactos/win32ss/include/ntuser.h
trunk/reactos/win32ss/user/ntuser/useratom.c
Modified: trunk/reactos/win32ss/include/ntuser.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/include/ntuser.h?r…
==============================================================================
--- trunk/reactos/win32ss/include/ntuser.h [iso-8859-1] (original)
+++ trunk/reactos/win32ss/include/ntuser.h [iso-8859-1] Sat Dec 22 17:43:20 2012
@@ -1893,11 +1893,13 @@
NtUserGetAsyncKeyState(
INT Key);
-DWORD
-NTAPI
+_Success_(return!=0)
+_At_(pustrName->Buffer, _Out_z_bytecap_post_bytecount_(pustrName->MaximumLength, return*2+2))
+ULONG
+APIENTRY
NtUserGetAtomName(
- ATOM nAtom,
- PUNICODE_STRING pBuffer);
+ _In_ ATOM atom,
+ _Inout_ PUNICODE_STRING pustrName);
UINT
NTAPI
Modified: trunk/reactos/win32ss/user/ntuser/useratom.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/ntuser/userat…
==============================================================================
--- trunk/reactos/win32ss/user/ntuser/useratom.c [iso-8859-1] (original)
+++ trunk/reactos/win32ss/user/ntuser/useratom.c [iso-8859-1] Sat Dec 22 17:43:20 2012
@@ -34,11 +34,11 @@
}
ULONG FASTCALL
-IntGetAtomName(RTL_ATOM nAtom, LPWSTR lpBuffer, ULONG nSize)
+IntGetAtomName(RTL_ATOM nAtom, LPWSTR lpBuffer, ULONG cjBufSize)
{
NTSTATUS Status = STATUS_SUCCESS;
PTHREADINFO pti;
- ULONG Size = nSize;
+ ULONG Size = cjBufSize;
pti = PsGetCurrentThreadWin32Thread();
if (pti->rpdesk == NULL)
@@ -49,13 +49,12 @@
Status = RtlQueryAtomInAtomTable(gAtomTable, nAtom, NULL, NULL, lpBuffer, &Size);
- if (Size < nSize)
- *(lpBuffer + Size/sizeof(WCHAR)) = 0;
if (!NT_SUCCESS(Status))
{
SetLastNtError(Status);
return 0;
}
+
return Size;
}
@@ -78,30 +77,67 @@
return Atom;
}
-DWORD
+/*!
+ * \brief Returns the name of an atom.
+ *
+ * \param atom - The atom to be queried.
+ * \param pustrName - Pointer to an initialized UNICODE_STRING that receives
+ * the name of the atom. The function does not update the
+ Length member. The string is always NULL-terminated.
+ *
+ * \return The length of the name in characters, or 0 if the function fails.
+ *
+ * \note The function does not aquire any global lock, since synchronisation is
+ * handled by the RtlAtom function.
+ */
+_Success_(return!=0)
+_At_(pustrName->Buffer, _Out_z_bytecap_post_bytecount_(pustrName->MaximumLength, return*2+2))
+ULONG
APIENTRY
NtUserGetAtomName(
- ATOM nAtom,
- PUNICODE_STRING pBuffer)
+ _In_ ATOM atom,
+ _Inout_ PUNICODE_STRING pustrName)
{
- DWORD Ret;
- WCHAR Buffer[256];
- UNICODE_STRING CapturedName = {0};
- UserEnterShared();
- CapturedName.Buffer = (LPWSTR)&Buffer;
- CapturedName.MaximumLength = sizeof(Buffer);
- Ret = IntGetAtomName((RTL_ATOM)nAtom, CapturedName.Buffer, (ULONG)CapturedName.Length);
- _SEH2_TRY
- {
- RtlCopyMemory(pBuffer->Buffer, &Buffer, pBuffer->MaximumLength);
- }
- _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
- {
- Ret = 0;
- }
- _SEH2_END
- UserLeave();
- return Ret;
+ WCHAR awcBuffer[256];
+ ULONG cjLength;
+
+ /* Retrieve the atom name into a local buffer (max length is 255 chars) */
+ cjLength = IntGetAtomName((RTL_ATOM)atom, awcBuffer, sizeof(awcBuffer));
+ if (cjLength != 0)
+ {
+ _SEH2_TRY
+ {
+ /* Probe the unicode string and the buffer */
+ ProbeForRead(pustrName, sizeof(*pustrName), 1);
+ ProbeForWrite(pustrName->Buffer, pustrName->MaximumLength, 1);
+
+ /* Check if we have enough space to write the NULL termination */
+ if (pustrName->MaximumLength >= sizeof(UNICODE_NULL))
+ {
+ /* Limit the length to the buffer size */
+ cjLength = min(pustrName->MaximumLength - sizeof(UNICODE_NULL),
+ cjLength);
+
+ /* Copy the string and NULL terminate it */
+ RtlCopyMemory(pustrName->Buffer, awcBuffer, cjLength);
+ pustrName->Buffer[cjLength / sizeof(WCHAR)] = L'\0';
+ }
+ else
+ {
+ cjLength = 0;
+ }
+ }
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+ {
+ /* On exception, set last error and fail */
+ SetLastNtError(_SEH2_GetExceptionCode());
+ cjLength = 0;
+ }
+ _SEH2_END
+ }
+
+ /* Return the length in characters */
+ return cjLength / sizeof(WCHAR);
}
/* EOF */