- fixed the ProbeForWrite prototype

- some fixes to get ntoskrnl to build with -Wcast-qual and -Wsign-compare
- don't touch any memory outside the given range in ProbeForWrite and touch all pages within the range

svn path=/trunk/; revision=19748
This commit is contained in:
Thomas Bluemel 2005-11-29 11:44:04 +00:00
parent 73f5202b01
commit fb9cd9cd0c
13 changed files with 63 additions and 56 deletions

View file

@ -28,9 +28,9 @@ Author:
//
// Page-Rounding Macros
//
#define PAGE_ROUND_DOWN(x) (((ULONG)x)&(~(PAGE_SIZE-1)))
#define PAGE_ROUND_DOWN(x) (((ULONG_PTR)x)&(~(PAGE_SIZE-1)))
#define PAGE_ROUND_UP(x) \
( (((ULONG)x)%PAGE_SIZE) ? ((((ULONG)x)&(~(PAGE_SIZE-1)))+PAGE_SIZE) : ((ULONG)x) )
( (((ULONG_PTR)x)%PAGE_SIZE) ? ((((ULONG_PTR)x)&(~(PAGE_SIZE-1)))+PAGE_SIZE) : ((ULONG_PTR)x) )
//
// Macro for generating pool tags

View file

@ -20,11 +20,11 @@
#endif
#ifndef PAGE_ROUND_DOWN
#define PAGE_ROUND_DOWN(x) (((ULONG)x)&(~(PAGE_SIZE-1)))
#define PAGE_ROUND_DOWN(x) (((ULONG_PTR)x)&(~(PAGE_SIZE-1)))
#endif
#ifndef PAGE_ROUND_UP
#define PAGE_ROUND_UP(x) ( (((ULONG)x)%PAGE_SIZE) ? ((((ULONG)x)&(~(PAGE_SIZE-1)))+PAGE_SIZE) : ((ULONG)x) )
#define PAGE_ROUND_UP(x) ( (((ULONG_PTR)x)%PAGE_SIZE) ? ((((ULONG_PTR)x)&(~(PAGE_SIZE-1)))+PAGE_SIZE) : ((ULONG_PTR)x) )
#endif
#define ABS_VALUE(V) (((V) < 0) ? -(V) : (V))

View file

@ -89,7 +89,7 @@ InitSystemSharedUserPage (PCSZ ParameterLine)
/* Create local parameter line copy */
ParamBuffer = ExAllocatePool(PagedPool, 256);
strcpy (ParamBuffer, (char *)ParameterLine);
strcpy (ParamBuffer, (const char *)ParameterLine);
DPRINT("%s\n", ParamBuffer);
/* Cut options off */

View file

@ -123,7 +123,7 @@ static const ULARGE_INTEGER __emptyULargeInteger = {{0, 0}};
(((ULONG_PTR)(Ptr) + sizeof(Type) - 1 < (ULONG_PTR)(Ptr) || \
(ULONG_PTR)(Ptr) + sizeof(Type) - 1 >= (ULONG_PTR)MmUserProbeAddress) ? \
ExRaiseStatus (STATUS_ACCESS_VIOLATION), Default : \
*(Type *)&(*(volatile Type *)(Ptr)))
*(Type *)(Ptr))
#define ProbeForReadBoolean(Ptr) ProbeForReadGenericType(Ptr, BOOLEAN, FALSE)
#define ProbeForReadUchar(Ptr) ProbeForReadGenericType(Ptr, UCHAR, 0)

View file

@ -882,6 +882,7 @@ IoSetDeviceInterfaceState(
PWCHAR StartPosition;
PWCHAR EndPosition;
NTSTATUS Status;
GUID EventGuid;
if (SymbolicLinkName == NULL)
return STATUS_INVALID_PARAMETER_1;
@ -917,10 +918,11 @@ IoSetDeviceInterfaceState(
return Status;
}
EventGuid = Enable ? GUID_DEVICE_INTERFACE_ARRIVAL : GUID_DEVICE_INTERFACE_REMOVAL;
IopNotifyPlugPlayNotification(
PhysicalDeviceObject,
EventCategoryDeviceInterfaceChange,
Enable ? (LPGUID)&GUID_DEVICE_INTERFACE_ARRIVAL : (LPGUID)&GUID_DEVICE_INTERFACE_REMOVAL,
&EventGuid,
&GuidString,
(PVOID)SymbolicLinkName);

View file

@ -221,7 +221,7 @@ IoGetDeviceProperty(
/* Query the device caps */
Status = IopQueryDeviceCapabilities(DeviceNode, &DeviceCaps);
if (NT_SUCCESS(Status) && (DeviceCaps.Address != -1))
if (NT_SUCCESS(Status) && (DeviceCaps.Address != (ULONG)-1))
{
/* Return length */
*ResultLength = sizeof(ULONG);

View file

@ -217,7 +217,7 @@ STDCALL
NtQueryDebugFilterState(IN ULONG ComponentId,
IN ULONG Level)
{
int i;
unsigned int i;
/* convert Level to mask if it isn't already one */
if ( Level < 32 )
@ -241,7 +241,7 @@ NtSetDebugFilterState(IN ULONG ComponentId,
IN ULONG Level,
IN BOOLEAN State)
{
int i;
unsigned int i;
for ( i = 0; i < KdComponentTableEntries; i++ )
{
if ( ComponentId == KdComponentTable[i].ComponentId )

View file

@ -45,7 +45,7 @@ EiReplyOrRequestPort (IN PEPORT Port,
}
Size = sizeof(QUEUEDMESSAGE);
if (LpcReply && LpcReply->u1.s1.TotalLength > sizeof(PORT_MESSAGE))
if (LpcReply && LpcReply->u1.s1.TotalLength > (CSHORT)sizeof(PORT_MESSAGE))
{
Size += LpcReply->u1.s1.TotalLength - sizeof(PORT_MESSAGE);
}

View file

@ -139,7 +139,7 @@ static __inline BOOLEAN Intsafe_CanOffsetPointer
#ifndef RTL_CONTAINS_FIELD
#define RTL_CONTAINS_FIELD(P_, SIZE_, FIELD_) \
((((char *)(P_)) + (SIZE_)) > (((char *)(&((P_)->FIELD_))) + sizeof((P_)->FIELD_)))
((ULONG_PTR)(P_) + (ULONG_PTR)(SIZE_) > (ULONG_PTR)&((P_)->FIELD_) + sizeof((P_)->FIELD_))
#endif
#define ELFFMT_FIELDS_EQUAL(TYPE1_, TYPE2_, FIELD_) \
@ -266,8 +266,13 @@ static __inline ULONG ElfFmtpSafeReadULong
{
PBYTE p;
ULONG nSafeInput;
union
{
CONST ULONG32 *ConstInput;
ULONG32 *Input;
}pInput = {Input};
RtlRetrieveUlong(&nSafeInput, Input);
RtlRetrieveUlong(&nSafeInput, pInput.Input);
if(DataType == ELF_TARG_DATA)
return nSafeInput;

View file

@ -97,7 +97,7 @@ static __inline BOOLEAN Intsafe_CanOffsetPointer(IN CONST VOID * Pointer, IN SIZ
#ifndef RTL_CONTAINS_FIELD
#define RTL_CONTAINS_FIELD(P_, SIZE_, FIELD_) \
((((char *)(P_)) + (SIZE_)) > (((char *)(&((P_)->FIELD_))) + sizeof((P_)->FIELD_)))
((ULONG_PTR)(P_) + (ULONG_PTR)(SIZE_) > (ULONG_PTR)&((P_)->FIELD_) + sizeof((P_)->FIELD_))
#endif
static __inline BOOLEAN IsPowerOf2(IN ULONG Number)

View file

@ -2744,8 +2744,8 @@ __cdecl
MmspCompareSegments(const void * x,
const void * y)
{
PMM_SECTION_SEGMENT Segment1 = (PMM_SECTION_SEGMENT)x;
PMM_SECTION_SEGMENT Segment2 = (PMM_SECTION_SEGMENT)y;
const MM_SECTION_SEGMENT *Segment1 = (const MM_SECTION_SEGMENT *)x;
const MM_SECTION_SEGMENT *Segment2 = (const MM_SECTION_SEGMENT *)y;
return
(Segment1->VirtualAddress - Segment2->VirtualAddress) >>

View file

@ -989,20 +989,20 @@ ProbeForRead (IN CONST VOID *Address,
IN ULONG Length,
IN ULONG Alignment)
{
ASSERT(Alignment == 1 || Alignment == 2 || Alignment == 4 || Alignment == 8);
if (Length != 0)
{
ASSERT(Alignment == 1 || Alignment == 2 || Alignment == 4 || Alignment == 8);
if (Length == 0)
return;
if (((ULONG_PTR)Address & (Alignment - 1)) != 0)
{
ExRaiseStatus (STATUS_DATATYPE_MISALIGNMENT);
}
else if ((ULONG_PTR)Address + Length - 1 < (ULONG_PTR)Address ||
(ULONG_PTR)Address + Length - 1 >= (ULONG_PTR)MmUserProbeAddress)
{
ExRaiseStatus (STATUS_ACCESS_VIOLATION);
}
if (((ULONG_PTR)Address & (Alignment - 1)) != 0)
{
ExRaiseStatus (STATUS_DATATYPE_MISALIGNMENT);
}
else if ((ULONG_PTR)Address + Length - 1 < (ULONG_PTR)Address ||
(ULONG_PTR)Address + Length - 1 >= (ULONG_PTR)MmUserProbeAddress)
{
ExRaiseStatus (STATUS_ACCESS_VIOLATION);
}
}
}
@ -1010,39 +1010,39 @@ ProbeForRead (IN CONST VOID *Address,
* @implemented
*/
VOID STDCALL
ProbeForWrite (IN CONST VOID *Address,
ProbeForWrite (IN PVOID Address,
IN ULONG Length,
IN ULONG Alignment)
{
volatile CHAR *Current;
PCHAR Last;
volatile CHAR *Current;
PCHAR Last;
ASSERT(Alignment == 1 || Alignment == 2 || Alignment == 4 || Alignment == 8);
if (Length != 0)
{
ASSERT(Alignment == 1 || Alignment == 2 || Alignment == 4 || Alignment == 8);
if (Length == 0)
return;
if (((ULONG_PTR)Address & (Alignment - 1)) != 0)
{
ExRaiseStatus (STATUS_DATATYPE_MISALIGNMENT);
}
if (((ULONG_PTR)Address & (Alignment - 1)) != 0)
{
ExRaiseStatus (STATUS_DATATYPE_MISALIGNMENT);
}
Last = (PCHAR)((ULONG_PTR)Address + Length - 1);
if ((ULONG_PTR)Last < (ULONG_PTR)Address ||
(ULONG_PTR)Last >= (ULONG_PTR)MmUserProbeAddress)
{
ExRaiseStatus (STATUS_ACCESS_VIOLATION);
}
Last = (CHAR*)((ULONG_PTR)Address + Length - 1);
if ((ULONG_PTR)Last < (ULONG_PTR)Address ||
(ULONG_PTR)Last >= (ULONG_PTR)MmUserProbeAddress)
{
ExRaiseStatus (STATUS_ACCESS_VIOLATION);
}
/* Check for accessible pages */
Current = (CHAR*)Address;
*Current = *Current;
Current = (PCHAR)((ULONG_PTR)PAGE_ROUND_DOWN(Current) + PAGE_SIZE);
while (Current <= Last)
{
*Current = *Current;
Current = (CHAR*)((ULONG_PTR)Current + PAGE_SIZE);
}
/* Check for accessible pages, do *not* touch any memory outside of the
range!*/
Current = (volatile CHAR*)Address;
Last = (PCHAR)(PAGE_ROUND_DOWN(Last));
do
{
*Current = *Current;
Current = (volatile CHAR*)(PAGE_ROUND_DOWN(Current) + PAGE_SIZE);
} while (Current <= Last);
}
}
/* EOF */

View file

@ -6738,7 +6738,7 @@ NTOSAPI
VOID
DDKAPI
ProbeForWrite(
IN CONST VOID *Address,
IN PVOID Address,
IN ULONG Length,
IN ULONG Alignment);