diff --git a/reactos/include/ndk/mmtypes.h b/reactos/include/ndk/mmtypes.h index 11889dbfc75..6fd9cf271d5 100644 --- a/reactos/include/ndk/mmtypes.h +++ b/reactos/include/ndk/mmtypes.h @@ -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 diff --git a/reactos/include/reactos/helper.h b/reactos/include/reactos/helper.h index c7d933ec869..7d003b0c6bf 100644 --- a/reactos/include/reactos/helper.h +++ b/reactos/include/reactos/helper.h @@ -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)) diff --git a/reactos/ntoskrnl/ex/init.c b/reactos/ntoskrnl/ex/init.c index ff5f5f193bc..a4a06d79536 100644 --- a/reactos/ntoskrnl/ex/init.c +++ b/reactos/ntoskrnl/ex/init.c @@ -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 */ diff --git a/reactos/ntoskrnl/include/internal/ntoskrnl.h b/reactos/ntoskrnl/include/internal/ntoskrnl.h index ada3859dea5..fb92bffe5b8 100644 --- a/reactos/ntoskrnl/include/internal/ntoskrnl.h +++ b/reactos/ntoskrnl/include/internal/ntoskrnl.h @@ -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) diff --git a/reactos/ntoskrnl/io/deviface.c b/reactos/ntoskrnl/io/deviface.c index 37c385671a1..6644548567a 100644 --- a/reactos/ntoskrnl/io/deviface.c +++ b/reactos/ntoskrnl/io/deviface.c @@ -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); diff --git a/reactos/ntoskrnl/io/pnpmgr.c b/reactos/ntoskrnl/io/pnpmgr.c index b2785ce6c50..3c34d402e0a 100644 --- a/reactos/ntoskrnl/io/pnpmgr.c +++ b/reactos/ntoskrnl/io/pnpmgr.c @@ -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); diff --git a/reactos/ntoskrnl/kd/kdmain.c b/reactos/ntoskrnl/kd/kdmain.c index a0b68d03e38..88b5e0424f1 100644 --- a/reactos/ntoskrnl/kd/kdmain.c +++ b/reactos/ntoskrnl/kd/kdmain.c @@ -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 ) diff --git a/reactos/ntoskrnl/lpc/reply.c b/reactos/ntoskrnl/lpc/reply.c index e42e30b06ed..e67db081f06 100644 --- a/reactos/ntoskrnl/lpc/reply.c +++ b/reactos/ntoskrnl/lpc/reply.c @@ -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); } diff --git a/reactos/ntoskrnl/mm/elf.inc.h b/reactos/ntoskrnl/mm/elf.inc.h index 3d3e27e4bf5..655096a501e 100644 --- a/reactos/ntoskrnl/mm/elf.inc.h +++ b/reactos/ntoskrnl/mm/elf.inc.h @@ -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; diff --git a/reactos/ntoskrnl/mm/pe.c b/reactos/ntoskrnl/mm/pe.c index ce9fb8bf8f0..c0f7df023f9 100644 --- a/reactos/ntoskrnl/mm/pe.c +++ b/reactos/ntoskrnl/mm/pe.c @@ -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) diff --git a/reactos/ntoskrnl/mm/section.c b/reactos/ntoskrnl/mm/section.c index ac8895e8515..f766f900ab6 100644 --- a/reactos/ntoskrnl/mm/section.c +++ b/reactos/ntoskrnl/mm/section.c @@ -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) >> diff --git a/reactos/ntoskrnl/mm/virtual.c b/reactos/ntoskrnl/mm/virtual.c index a8c0b06b797..557557ddde2 100644 --- a/reactos/ntoskrnl/mm/virtual.c +++ b/reactos/ntoskrnl/mm/virtual.c @@ -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 */ diff --git a/reactos/w32api/include/ddk/winddk.h b/reactos/w32api/include/ddk/winddk.h index eef60ca5e2b..8f5f16f553f 100644 --- a/reactos/w32api/include/ddk/winddk.h +++ b/reactos/w32api/include/ddk/winddk.h @@ -6738,7 +6738,7 @@ NTOSAPI VOID DDKAPI ProbeForWrite( - IN CONST VOID *Address, + IN PVOID Address, IN ULONG Length, IN ULONG Alignment);