Author: sir_richard
Date: Tue Oct 5 17:01:41 2010
New Revision: 49002
URL:
http://svn.reactos.org/svn/reactos?rev=49002&view=rev
Log:
[NTOS]: Build fix.
Modified:
trunk/reactos/include/reactos/exeformat.h
Modified: trunk/reactos/include/reactos/exeformat.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/reactos/exeformat.…
==============================================================================
--- trunk/reactos/include/reactos/exeformat.h [iso-8859-1] (original)
+++ trunk/reactos/include/reactos/exeformat.h [iso-8859-1] Tue Oct 5 17:01:41 2010
@@ -95,6 +95,78 @@
#define EXEFMT_LOADED_ELF32 (0x00000004)
#define EXEFMT_LOADED_ELF64 (0x00000005)
+/* TODO: Intsafe should be made into a library, as it's generally useful */
+static __inline BOOLEAN Intsafe_CanAddULongPtr(IN ULONG_PTR Addend1, IN ULONG_PTR
Addend2)
+{
+ return Addend1 <= (MAXULONG_PTR - Addend2);
+}
+
+static __inline BOOLEAN Intsafe_CanAddLong64(IN LONG64 Addend1, IN LONG64 Addend2)
+{
+ return Addend1 <= (MAXLONGLONG - Addend2);
+}
+
+static __inline BOOLEAN Intsafe_CanAddULong32(IN ULONG Addend1, IN ULONG Addend2)
+{
+ return Addend1 <= (MAXULONG - Addend2);
+}
+
+static __inline BOOLEAN Intsafe_AddULong32(OUT PULONG Result, IN ULONG Addend1, IN ULONG
Addend2)
+{
+ if(!Intsafe_CanAddULong32(Addend1, Addend2))
+ return FALSE;
+
+ *Result = Addend1 + Addend2;
+ return TRUE;
+}
+
+static __inline BOOLEAN Intsafe_CanMulULong32(IN ULONG Factor1, IN ULONG Factor2)
+{
+ return Factor1 <= (MAXULONG / Factor2);
+}
+
+static __inline BOOLEAN Intsafe_CanOffsetPointer(IN CONST VOID * Pointer, IN SIZE_T
Offset)
+{
+ /* FIXME: (PVOID)MAXULONG_PTR isn't necessarily a valid address */
+ return Intsafe_CanAddULongPtr((ULONG_PTR)Pointer, Offset);
+}
+
+static __inline BOOLEAN IsPowerOf2(IN ULONG Number)
+{
+ if(Number == 0)
+ return FALSE;
+ return (Number & (Number - 1)) == 0;
+}
+
+static __inline ULONG ModPow2(IN ULONG Address, IN ULONG Alignment)
+{
+ ASSERT(IsPowerOf2(Alignment));
+ return Address & (Alignment - 1);
+}
+
+static __inline BOOLEAN IsAligned(IN ULONG Address, IN ULONG Alignment)
+{
+ return ModPow2(Address, Alignment) == 0;
+}
+
+static __inline BOOLEAN AlignUp(OUT PULONG AlignedAddress, IN ULONG Address, IN ULONG
Alignment)
+{
+ ULONG nExcess = ModPow2(Address, Alignment);
+
+ if(nExcess == 0)
+ {
+ *AlignedAddress = Address;
+ return nExcess == 0;
+ }
+ else
+ return Intsafe_AddULong32(AlignedAddress, Address, Alignment - nExcess);
+}
+
+#define PEFMT_FIELDS_EQUAL(TYPE1_, TYPE2_, FIELD_) \
+ ( \
+ (FIELD_OFFSET(TYPE1_, FIELD_) == FIELD_OFFSET(TYPE2_, FIELD_)) && \
+ (RTL_FIELD_SIZE(TYPE1_, FIELD_) == RTL_FIELD_SIZE(TYPE2_, FIELD_)) \
+ )
#endif
/* EOF */