2 * PROJECT: ReactOS Kernel
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: ntoskrnl/ex/exintrin.c
5 * PURPOSE: Exported kernel functions which are now intrinsics
6 * PROGRAMMERS: ReactOS Portable Systems Group
9 /* INCLUDES *******************************************************************/
15 #undef InterlockedIncrement
16 #undef InterlockedDecrement
17 #undef InterlockedCompareExchange
18 #undef InterlockedExchangeAdd
19 #undef InterlockedExchange
22 // HAL Port to Inlined Port
24 #define H2I(Port) PtrToUshort(Port)
26 /* FUNCTIONS ******************************************************************/
33 InterlockedIncrement(IN LONG
volatile *Addend
)
38 return _InterlockedIncrement(Addend
);
46 InterlockedDecrement(IN LONG
volatile *Addend
)
51 return _InterlockedDecrement(Addend
);
59 InterlockedCompareExchange(IN OUT LONG
volatile *Destination
,
66 return _InterlockedCompareExchange(Destination
, Exchange
, Comperand
);
74 InterlockedExchange(IN OUT LONG
volatile *Destination
,
80 return _InterlockedExchange(Destination
, Value
);
88 InterlockedExchangeAdd(IN OUT LONG
volatile *Addend
,
94 return _InterlockedExchangeAdd(Addend
, Increment
);
102 ProbeForRead(IN CONST VOID
*Address
,
108 /* Only probe if we have a valid length */
112 ASSERT((Alignment
== 1) ||
118 /* Check for correct alignment */
119 if (((ULONG_PTR
)Address
& (Alignment
- 1)) != 0)
121 /* Incorrect alignment */
122 ExRaiseDatatypeMisalignment();
124 else if (((ULONG_PTR
)Address
+ Length
) < (ULONG_PTR
)Address
||
125 ((ULONG_PTR
)Address
+ Length
) > (ULONG_PTR
)MmUserProbeAddress
)
128 *(volatile CHAR
* const)MmUserProbeAddress
= 0;
138 ProbeForWrite(IN PVOID Address
,
142 ULONG_PTR Last
, Current
= (ULONG_PTR
)Address
;
145 /* Only probe if we have a valid length */
149 ASSERT((Alignment
== 1) ||
155 /* Check the alignment */
156 if ((Current
& (Alignment
- 1)) != 0)
158 /* Incorrect alignment */
159 ExRaiseDatatypeMisalignment();
162 /* Get the end address */
163 Last
= Current
+ Length
- 1;
164 if ((Last
< Current
) || (Last
>= (ULONG_PTR
)MmUserProbeAddress
))
166 /* Raise an access violation */
167 ExRaiseAccessViolation();
170 /* Round down to the last page */
171 Last
= PAGE_ROUND_DOWN(Last
) + PAGE_SIZE
;
174 /* Attempt a write */
175 *(volatile CHAR
*)Current
= *(volatile CHAR
*)Current
;
177 /* Go to the next address */
178 Current
= PAGE_ROUND_DOWN(Current
) + PAGE_SIZE
;
179 } while (Current
!= Last
);