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
,
106 ULONG_PTR Last
, Current
= (ULONG_PTR
)Address
;
109 /* Only probe if we have a valid length */
113 ASSERT((Alignment
== 1) ||
119 /* Check the alignment */
120 if ((Current
& (Alignment
- 1)) != 0)
122 /* Incorrect alignment */
123 ExRaiseDatatypeMisalignment();
126 /* Get the end address */
127 Last
= Current
+ Length
- 1;
128 if ((Last
< Current
) || (Last
>= (ULONG_PTR
)MmUserProbeAddress
))
130 /* Raise an access violation */
131 ExRaiseAccessViolation();
134 /* ProbeForRead doesn't check if memory pages are readable! */
143 ProbeForWrite(IN PVOID Address
,
147 ULONG_PTR Last
, Current
= (ULONG_PTR
)Address
;
150 /* Only probe if we have a valid length */
154 ASSERT((Alignment
== 1) ||
160 /* Check the alignment */
161 if ((Current
& (Alignment
- 1)) != 0)
163 /* Incorrect alignment */
164 ExRaiseDatatypeMisalignment();
167 /* Get the end address */
168 Last
= Current
+ Length
- 1;
169 if ((Last
< Current
) || (Last
>= (ULONG_PTR
)MmUserProbeAddress
))
171 /* Raise an access violation */
172 ExRaiseAccessViolation();
175 /* Round down to the last page */
176 Last
= PAGE_ROUND_DOWN(Last
) + PAGE_SIZE
;
179 /* Attempt a write */
180 *(volatile CHAR
*)Current
= *(volatile CHAR
*)Current
;
182 /* Go to the next address */
183 Current
= PAGE_ROUND_DOWN(Current
) + PAGE_SIZE
;
184 } while (Current
!= Last
);