Author: ion
Date: Fri Jun 23 03:40:50 2006
New Revision: 22520
URL:
http://svn.reactos.ru/svn/reactos?rev=22520&view=rev
Log:
[AUDIT] - Unlock Thomas's low resource notification code, since it's clean.
- Entirely rewrite Kernel32 Probe functions to um, actually probe (ported Thomas's
code in the kernel and adjusted for user-mode and then checked with WINE's code). I
can't begin to fathom what the previous routines were supposed to be doing.
Modified:
trunk/reactos/dll/win32/kernel32/mem/isbad.c
trunk/reactos/dll/win32/kernel32/mem/procmem.c (props changed)
trunk/reactos/dll/win32/kernel32/mem/resnotify.c (props changed)
trunk/reactos/dll/win32/kernel32/mem/section.c (props changed)
trunk/reactos/dll/win32/kernel32/mem/virtual.c (props changed)
trunk/reactos/include/ndk/mmfuncs.h
Modified: trunk/reactos/dll/win32/kernel32/mem/isbad.c
URL:
http://svn.reactos.ru/svn/reactos/trunk/reactos/dll/win32/kernel32/mem/isba…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/mem/isbad.c (original)
+++ trunk/reactos/dll/win32/kernel32/mem/isbad.c Fri Jun 23 03:40:50 2006
@@ -1,259 +1,246 @@
-/* $Id$
- *
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS system libraries
+/*
+ * PROJECT: ReactOS Win32 Base API
+ * LICENSE: GPL - See COPYING in the top level directory
* FILE: dll/win32/kernel32/mem/isbad.c
- * PURPOSE:
- * PROGRAMMER: Ariadne ( ariadne(a)xs4all.nl)
- * Ge van Geldorp
- * Filip Navara
- * UPDATE HISTORY:
- * Created 03/10/99
- */
+ * PURPOSE: Handles probing of memory addresses
+ * PROGRAMMERS: Alex Ionescu (alex.ionescu(a)reactos.org)
+ * Thomas Weidenmueller (w3seek(a)reactos.org)
+ */
+
+/* INCLUDES ******************************************************************/
#include <k32.h>
#define NDEBUG
-#include "../include/debug.h"
-
-/* FIXME: Stubs. What is it for? */
-/*
- * @implemented
- */
-UINT
-wcsnlen (
- LPCWSTR lpsz,
- UINT ucchMax
- )
-{
- UINT i = 0;
- while( i < ucchMax && lpsz[i] ) i++;
- return i;
-}
-
-
-/* FIXME: Stubs. What is it for? */
-/*
- * @implemented
- */
-UINT
-strnlen (
- LPCSTR lpsz,
- UINT uiMax
- )
-{
- UINT i = 0;
- while( i < uiMax && lpsz[i] ) i++;
- return i;
-}
-
-/* --- --- --- */
+#include "debug.h"
+
+extern SYSTEM_BASIC_INFORMATION BaseCachedSysInfo;
+
+/* FUNCTIONS *****************************************************************/
/*
* @implemented
*/
BOOL
STDCALL
-IsBadReadPtr (
- CONST VOID * lp,
- UINT ucb
- )
-{
- MEMORY_BASIC_INFORMATION MemoryInformation;
-
- if ( ucb == 0 )
- {
- return TRUE;
- }
-
- VirtualQuery (
- lp,
- & MemoryInformation,
- sizeof (MEMORY_BASIC_INFORMATION)
- );
-
- if ( MemoryInformation.State != MEM_COMMIT )
- {
- return TRUE;
- }
-
- if ( MemoryInformation.RegionSize < ucb )
- {
- return TRUE;
- }
-
- if ( MemoryInformation.Protect == PAGE_EXECUTE )
- {
- return TRUE;
- }
-
- if ( MemoryInformation.Protect == PAGE_NOACCESS )
- {
- return TRUE;
- }
-
- return FALSE;
-
-}
-
-
-/*
- * @implemented
- */
-BOOL
-STDCALL
-IsBadHugeReadPtr (
- CONST VOID * lp,
- UINT ucb
- )
-{
- return IsBadReadPtr (lp, ucb);
-}
-
-
-/*
- * @implemented
- */
-BOOL
-STDCALL
-IsBadCodePtr (
- FARPROC lpfn
- )
-{
- MEMORY_BASIC_INFORMATION MemoryInformation;
-
-
- VirtualQuery (
- lpfn,
- & MemoryInformation,
- sizeof (MEMORY_BASIC_INFORMATION)
- );
-
- if ( MemoryInformation.State != MEM_COMMIT )
- {
- return TRUE;
- }
-
- if ( (MemoryInformation.Protect == PAGE_EXECUTE)
- || (MemoryInformation.Protect == PAGE_EXECUTE_READ)
- )
- {
- return FALSE;
- }
-
- return TRUE;
-}
-
-
-/*
- * @implemented
- */
-BOOL
-STDCALL
-IsBadWritePtr (
- LPVOID lp,
- UINT ucb
- )
-{
- MEMORY_BASIC_INFORMATION MemoryInformation;
-
- if ( ucb == 0 )
- {
- return TRUE;
- }
-
- VirtualQuery (
- lp,
- & MemoryInformation,
- sizeof (MEMORY_BASIC_INFORMATION)
- );
-
- if ( MemoryInformation.State != MEM_COMMIT )
- {
- return TRUE;
- }
-
- if ( MemoryInformation.RegionSize < ucb )
- {
- return TRUE;
- }
-
-
- if ( MemoryInformation.Protect == PAGE_READONLY)
- {
- return TRUE;
- }
-
- if ( (MemoryInformation.Protect == PAGE_EXECUTE)
- || (MemoryInformation.Protect == PAGE_EXECUTE_READ)
- )
- {
- return TRUE;
- }
-
- if ( MemoryInformation.Protect == PAGE_NOACCESS )
- {
- return TRUE;
- }
-
- return FALSE;
-}
-
-
-/*
- * @implemented
- */
-BOOL
-STDCALL
-IsBadHugeWritePtr (
- LPVOID lp,
- UINT ucb
- )
-{
- return IsBadWritePtr (lp, ucb);
-}
-
-
-/*
- * @implemented
- */
-BOOL
-STDCALL
-IsBadStringPtrW (
- LPCWSTR lpsz,
- UINT ucchMax
- )
-{
- UINT Len = wcsnlen (
- lpsz + 1,
- ucchMax >> 1
- );
- return IsBadReadPtr (
- lpsz,
- Len << 1
- );
-}
-
-
-/*
- * @implemented
- */
-BOOL
-STDCALL
-IsBadStringPtrA (
- LPCSTR lpsz,
- UINT ucchMax
- )
-{
- UINT Len = strnlen (
- lpsz + 1,
- ucchMax
- );
- return IsBadReadPtr (
- lpsz,
- Len
- );
-}
-
+IsBadReadPtr(IN LPCVOID lp,
+ IN UINT_PTR ucb)
+{
+ ULONG PageSize;
+ BOOLEAN Result = FALSE;
+ volatile CHAR *Current;
+ PCHAR Last;
+
+ /* Quick cases */
+ if (!ucb) return FALSE;
+ if (!lp) return TRUE;
+
+ /* Get the page size */
+ PageSize = BaseCachedSysInfo.PageSize;
+
+ /* Calculate the last page */
+ Last = (PCHAR)((ULONG_PTR)lp + ucb - 1);
+
+ /* Another quick failure case */
+ if ((ULONG_PTR)Last < (ULONG_PTR)lp) return TRUE;
+
+ /* Enter SEH */
+ _SEH_TRY
+ {
+ /* Probe the entire range */
+ Current = (volatile CHAR*)lp;
+ Last = (PCHAR)(PAGE_ROUND_DOWN(Last));
+ do
+ {
+ *Current;
+ Current = (volatile CHAR*)(PAGE_ROUND_DOWN(Current) + PAGE_SIZE);
+ } while (Current <= Last);
+ }
+ _SEH_HANDLE
+ {
+ /* We hit an exception, so return true */
+ Result = TRUE;
+ }
+ _SEH_END
+
+ /* Return exception status */
+ return Result;
+}
+
+/*
+ * @implemented
+ */
+BOOL
+NTAPI
+IsBadHugeReadPtr(LPCVOID lp,
+ UINT_PTR ucb)
+{
+ /* Implementation is the same on 32-bit */
+ return IsBadReadPtr(lp, ucb);
+}
+
+/*
+ * @implemented
+ */
+BOOL
+NTAPI
+IsBadCodePtr(FARPROC lpfn)
+{
+ /* Executing has the same privileges as reading */
+ return IsBadReadPtr((LPVOID)lpfn, 1);
+}
+
+/*
+ * @implemented
+ */
+BOOL
+NTAPI
+IsBadWritePtr(LPVOID lp,
+ UINT_PTR ucb)
+{
+ ULONG PageSize;
+ BOOLEAN Result = FALSE;
+ volatile CHAR *Current;
+ PCHAR Last;
+
+ /* Quick cases */
+ if (!ucb) return FALSE;
+ if (!lp) return TRUE;
+
+ /* Get the page size */
+ PageSize = BaseCachedSysInfo.PageSize;
+
+ /* Calculate the last page */
+ Last = (PCHAR)((ULONG_PTR)lp + ucb - 1);
+
+ /* Another quick failure case */
+ if ((ULONG_PTR)Last < (ULONG_PTR)lp) return TRUE;
+
+ /* Enter SEH */
+ _SEH_TRY
+ {
+ /* Probe the entire range */
+ Current = (volatile CHAR*)lp;
+ Last = (PCHAR)(PAGE_ROUND_DOWN(Last));
+ do
+ {
+ *Current = *Current;
+ Current = (volatile CHAR*)(PAGE_ROUND_DOWN(Current) + PAGE_SIZE);
+ } while (Current <= Last);
+ }
+ _SEH_HANDLE
+ {
+ /* We hit an exception, so return true */
+ Result = TRUE;
+ }
+ _SEH_END
+
+ /* Return exception status */
+ return Result;
+}
+
+/*
+ * @implemented
+ */
+BOOL
+NTAPI
+IsBadHugeWritePtr(LPVOID lp,
+ UINT_PTR ucb)
+{
+ /* Implementation is the same on 32-bit */
+ return IsBadWritePtr(lp, ucb);
+}
+
+/*
+ * @implemented
+ */
+BOOL
+NTAPI
+IsBadStringPtrW(IN LPCWSTR lpsz,
+ UINT_PTR ucchMax)
+{
+ BOOLEAN Result = FALSE;
+ volatile WCHAR *Current;
+ PWCHAR Last;
+ WCHAR Char;
+
+ /* Quick cases */
+ if (!ucchMax) return FALSE;
+ if (!lpsz) return TRUE;
+
+ /* Calculate the last page */
+ Last = (PWCHAR)((ULONG_PTR)lpsz + (ucchMax * 2) - 2);
+
+ /* Another quick failure case */
+ if ((ULONG_PTR)Last < (ULONG_PTR)lpsz) return TRUE;
+
+ /* Enter SEH */
+ _SEH_TRY
+ {
+ /* Probe the entire range */
+ Current = (volatile WCHAR*)lpsz;
+ Last = (PWCHAR)(PAGE_ROUND_DOWN(Last));
+ do
+ {
+ Char = *Current;
+ Current++;
+ } while (Char && (Current <= Last));
+ }
+ _SEH_HANDLE
+ {
+ /* We hit an exception, so return true */
+ Result = TRUE;
+ }
+ _SEH_END
+
+ /* Return exception status */
+ return Result;
+}
+
+/*
+ * @implemented
+ */
+BOOL
+NTAPI
+IsBadStringPtrA(IN LPCSTR lpsz,
+ UINT_PTR ucchMax)
+{
+ BOOLEAN Result = FALSE;
+ volatile CHAR *Current;
+ PCHAR Last;
+ CHAR Char;
+
+ /* Quick cases */
+ if (!ucchMax) return FALSE;
+ if (!lpsz) return TRUE;
+
+ /* Calculate the last page */
+ Last = (PCHAR)((ULONG_PTR)lpsz + ucchMax - 1);
+
+ /* Another quick failure case */
+ if ((ULONG_PTR)Last < (ULONG_PTR)lpsz) return TRUE;
+
+ /* Enter SEH */
+ _SEH_TRY
+ {
+ /* Probe the entire range */
+ Current = (volatile CHAR*)lpsz;
+ Last = (PCHAR)(PAGE_ROUND_DOWN(Last));
+ do
+ {
+ Char = *Current;
+ Current++;
+ } while (Char && (Current <= Last));
+ }
+ _SEH_HANDLE
+ {
+ /* We hit an exception, so return true */
+ Result = TRUE;
+ }
+ _SEH_END
+
+ /* Return exception status */
+ return Result;
+}
/* EOF */
Propchange: trunk/reactos/dll/win32/kernel32/mem/procmem.c
------------------------------------------------------------------------------
--- svn:needs-lock (original)
+++ svn:needs-lock (removed)
@@ -1,1 +1,0 @@
-*
Propchange: trunk/reactos/dll/win32/kernel32/mem/resnotify.c
------------------------------------------------------------------------------
--- svn:needs-lock (original)
+++ svn:needs-lock (removed)
@@ -1,1 +1,0 @@
-*
Propchange: trunk/reactos/dll/win32/kernel32/mem/section.c
------------------------------------------------------------------------------
--- svn:needs-lock (original)
+++ svn:needs-lock (removed)
@@ -1,1 +1,0 @@
-*
Propchange: trunk/reactos/dll/win32/kernel32/mem/virtual.c
------------------------------------------------------------------------------
--- svn:needs-lock (original)
+++ svn:needs-lock (removed)
@@ -1,1 +1,0 @@
-*
Modified: trunk/reactos/include/ndk/mmfuncs.h
URL:
http://svn.reactos.ru/svn/reactos/trunk/reactos/include/ndk/mmfuncs.h?rev=2…
==============================================================================
--- trunk/reactos/include/ndk/mmfuncs.h (original)
+++ trunk/reactos/include/ndk/mmfuncs.h Fri Jun 23 03:40:50 2006
@@ -232,8 +232,8 @@
IN HANDLE ProcessHandle,
IN PVOID BaseAddress,
IN PVOID Buffer,
- IN ULONG NumberOfBytesToWrite,
- OUT PULONG NumberOfBytesWritten
+ IN SIZE_T NumberOfBytesToWrite,
+ OUT PSIZE_T NumberOfBytesWritten
);
NTSYSAPI