2006-06-22 23:40:50 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Win32 Base API
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
2006-05-25 19:50:19 +00:00
|
|
|
* FILE: dll/win32/kernel32/mem/isbad.c
|
2006-06-22 23:40:50 +00:00
|
|
|
* PURPOSE: Handles probing of memory addresses
|
|
|
|
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
|
|
|
|
* Thomas Weidenmueller (w3seek@reactos.org)
|
1999-10-03 23:19:15 +00:00
|
|
|
*/
|
2006-05-25 19:50:19 +00:00
|
|
|
|
2006-06-22 23:40:50 +00:00
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
2003-01-15 21:24:36 +00:00
|
|
|
#include <k32.h>
|
1999-10-02 20:20:44 +00:00
|
|
|
|
2003-04-29 22:39:57 +00:00
|
|
|
#define NDEBUG
|
2007-09-02 19:42:22 +00:00
|
|
|
#include <debug.h>
|
1999-10-03 23:19:15 +00:00
|
|
|
|
2006-06-22 23:40:50 +00:00
|
|
|
extern SYSTEM_BASIC_INFORMATION BaseCachedSysInfo;
|
1999-10-03 23:19:15 +00:00
|
|
|
|
2006-06-22 23:40:50 +00:00
|
|
|
/* FUNCTIONS *****************************************************************/
|
1999-10-03 23:19:15 +00:00
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-05-09 01:46:57 +00:00
|
|
|
BOOL
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2006-06-22 23:40:50 +00:00
|
|
|
IsBadReadPtr(IN LPCVOID lp,
|
|
|
|
IN UINT_PTR ucb)
|
2005-05-09 01:46:57 +00:00
|
|
|
{
|
2006-06-22 23:40:50 +00:00
|
|
|
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 */
|
2008-11-30 19:28:11 +00:00
|
|
|
_SEH2_TRY
|
2006-06-22 23:40:50 +00:00
|
|
|
{
|
|
|
|
/* 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);
|
|
|
|
}
|
2008-11-30 19:28:11 +00:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-06-22 23:40:50 +00:00
|
|
|
{
|
|
|
|
/* We hit an exception, so return true */
|
|
|
|
Result = TRUE;
|
|
|
|
}
|
2008-11-30 19:28:11 +00:00
|
|
|
_SEH2_END
|
2006-06-22 23:40:50 +00:00
|
|
|
|
|
|
|
/* Return exception status */
|
|
|
|
return Result;
|
1999-10-02 20:20:44 +00:00
|
|
|
}
|
1999-10-03 23:19:15 +00:00
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-05-09 01:46:57 +00:00
|
|
|
BOOL
|
2006-06-22 23:40:50 +00:00
|
|
|
NTAPI
|
|
|
|
IsBadHugeReadPtr(LPCVOID lp,
|
|
|
|
UINT_PTR ucb)
|
1999-10-02 20:20:44 +00:00
|
|
|
{
|
2006-06-22 23:40:50 +00:00
|
|
|
/* Implementation is the same on 32-bit */
|
|
|
|
return IsBadReadPtr(lp, ucb);
|
1999-10-02 20:20:44 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-05-09 01:46:57 +00:00
|
|
|
BOOL
|
2006-06-22 23:40:50 +00:00
|
|
|
NTAPI
|
|
|
|
IsBadCodePtr(FARPROC lpfn)
|
1999-10-02 20:20:44 +00:00
|
|
|
{
|
2006-06-22 23:40:50 +00:00
|
|
|
/* Executing has the same privileges as reading */
|
|
|
|
return IsBadReadPtr((LPVOID)lpfn, 1);
|
1999-10-02 20:20:44 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2004-01-23 17:18:16 +00:00
|
|
|
BOOL
|
2006-06-22 23:40:50 +00:00
|
|
|
NTAPI
|
|
|
|
IsBadWritePtr(LPVOID lp,
|
|
|
|
UINT_PTR ucb)
|
1999-10-02 20:20:44 +00:00
|
|
|
{
|
2006-06-22 23:40:50 +00:00
|
|
|
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 */
|
2008-11-30 19:28:11 +00:00
|
|
|
_SEH2_TRY
|
2006-06-22 23:40:50 +00:00
|
|
|
{
|
|
|
|
/* 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);
|
|
|
|
}
|
2008-11-30 19:28:11 +00:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-06-22 23:40:50 +00:00
|
|
|
{
|
|
|
|
/* We hit an exception, so return true */
|
|
|
|
Result = TRUE;
|
|
|
|
}
|
2008-11-30 19:28:11 +00:00
|
|
|
_SEH2_END
|
2006-06-22 23:40:50 +00:00
|
|
|
|
|
|
|
/* Return exception status */
|
|
|
|
return Result;
|
1999-10-02 20:20:44 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2004-01-23 17:18:16 +00:00
|
|
|
BOOL
|
2006-06-22 23:40:50 +00:00
|
|
|
NTAPI
|
|
|
|
IsBadHugeWritePtr(LPVOID lp,
|
|
|
|
UINT_PTR ucb)
|
1999-10-02 20:20:44 +00:00
|
|
|
{
|
2006-06-22 23:40:50 +00:00
|
|
|
/* Implementation is the same on 32-bit */
|
|
|
|
return IsBadWritePtr(lp, ucb);
|
1999-10-02 20:20:44 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2004-01-23 17:18:16 +00:00
|
|
|
BOOL
|
2006-06-22 23:40:50 +00:00
|
|
|
NTAPI
|
|
|
|
IsBadStringPtrW(IN LPCWSTR lpsz,
|
|
|
|
UINT_PTR ucchMax)
|
1999-10-02 20:20:44 +00:00
|
|
|
{
|
2006-06-22 23:40:50 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
/* Enter SEH */
|
2008-11-30 19:28:11 +00:00
|
|
|
_SEH2_TRY
|
2006-06-22 23:40:50 +00:00
|
|
|
{
|
|
|
|
/* Probe the entire range */
|
|
|
|
Current = (volatile WCHAR*)lpsz;
|
|
|
|
Last = (PWCHAR)(PAGE_ROUND_DOWN(Last));
|
|
|
|
do
|
|
|
|
{
|
|
|
|
Char = *Current;
|
|
|
|
Current++;
|
2009-10-15 19:28:11 +00:00
|
|
|
} while (Char && (Current != Last + 1));
|
2006-06-22 23:40:50 +00:00
|
|
|
}
|
2008-11-30 19:28:11 +00:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-06-22 23:40:50 +00:00
|
|
|
{
|
|
|
|
/* We hit an exception, so return true */
|
|
|
|
Result = TRUE;
|
|
|
|
}
|
2008-11-30 19:28:11 +00:00
|
|
|
_SEH2_END
|
2006-06-22 23:40:50 +00:00
|
|
|
|
|
|
|
/* Return exception status */
|
|
|
|
return Result;
|
1999-10-02 20:20:44 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-05-09 01:46:57 +00:00
|
|
|
BOOL
|
2006-06-22 23:40:50 +00:00
|
|
|
NTAPI
|
|
|
|
IsBadStringPtrA(IN LPCSTR lpsz,
|
|
|
|
UINT_PTR ucchMax)
|
1999-10-02 20:20:44 +00:00
|
|
|
{
|
2006-06-22 23:40:50 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
/* Enter SEH */
|
2008-11-30 19:28:11 +00:00
|
|
|
_SEH2_TRY
|
2006-06-22 23:40:50 +00:00
|
|
|
{
|
|
|
|
/* Probe the entire range */
|
|
|
|
Current = (volatile CHAR*)lpsz;
|
|
|
|
Last = (PCHAR)(PAGE_ROUND_DOWN(Last));
|
|
|
|
do
|
|
|
|
{
|
|
|
|
Char = *Current;
|
|
|
|
Current++;
|
2009-10-15 19:28:11 +00:00
|
|
|
} while (Char && (Current != Last + 1));
|
2006-06-22 23:40:50 +00:00
|
|
|
}
|
2008-11-30 19:28:11 +00:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2006-06-22 23:40:50 +00:00
|
|
|
{
|
|
|
|
/* We hit an exception, so return true */
|
|
|
|
Result = TRUE;
|
|
|
|
}
|
2008-11-30 19:28:11 +00:00
|
|
|
_SEH2_END
|
2006-06-22 23:40:50 +00:00
|
|
|
|
|
|
|
/* Return exception status */
|
|
|
|
return Result;
|
1999-10-02 20:20:44 +00:00
|
|
|
}
|
1999-10-03 23:19:15 +00:00
|
|
|
|
|
|
|
/* EOF */
|