ReactOS  0.4.14-dev-606-g14ebc0b
exintrin.c
Go to the documentation of this file.
1 /*
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
7  */
8 
9 /* INCLUDES *******************************************************************/
10 
11 #include <ntoskrnl.h>
12 #define NDEBUG
13 #include <debug.h>
14 
15 #undef InterlockedIncrement
16 #undef InterlockedDecrement
17 #undef InterlockedCompareExchange
18 #undef InterlockedExchangeAdd
19 #undef InterlockedExchange
20 
21 //
22 // HAL Port to Inlined Port
23 //
24 #define H2I(Port) PtrToUshort(Port)
25 
26 /* FUNCTIONS ******************************************************************/
27 
28 /*
29  * @implemented
30  */
31 LONG
34 {
35  //
36  // Call the intrinsic
37  //
39 }
40 
41 /*
42  * @implemented
43  */
44 LONG
47 {
48  //
49  // Call the intrinsic
50  //
52 }
53 
54 /*
55  * @implemented
56  */
57 LONG
60  IN LONG Exchange,
61  IN LONG Comperand)
62 {
63  //
64  // Call the intrinsic
65  //
66  return _InterlockedCompareExchange(Destination, Exchange, Comperand);
67 }
68 
69 /*
70  * @implemented
71  */
72 LONG
75  IN LONG Value)
76 {
77  //
78  // Call the intrinsic
79  //
81 }
82 
83 /*
84  * @implemented
85  */
86 LONG
90 {
91  //
92  // Call the intrinsic
93  //
95 }
96 
97 /*
98  * @implemented
99  */
100 VOID
101 NTAPI
103  IN SIZE_T Length,
105 {
106  ULONG_PTR Last, Current = (ULONG_PTR)Address;
107  PAGED_CODE();
108 
109  /* Only probe if we have a valid length */
110  if (Length != 0)
111  {
112  /* Sanity check */
113  ASSERT((Alignment == 1) ||
114  (Alignment == 2) ||
115  (Alignment == 4) ||
116  (Alignment == 8) ||
117  (Alignment == 16));
118 
119  /* Check the alignment */
120  if ((Current & (Alignment - 1)) != 0)
121  {
122  /* Incorrect alignment */
124  }
125 
126  /* Get the end address */
127  Last = Current + Length - 1;
128  if ((Last < Current) || (Last >= (ULONG_PTR)MmUserProbeAddress))
129  {
130  /* Raise an access violation */
132  }
133 
134  /* ProbeForRead doesn't check if memory pages are readable! */
135  }
136 }
137 
138 /*
139  * @implemented
140  */
141 VOID
142 NTAPI
144  IN SIZE_T Length,
146 {
147  ULONG_PTR Last, Current = (ULONG_PTR)Address;
148  PAGED_CODE();
149 
150  /* Only probe if we have a valid length */
151  if (Length != 0)
152  {
153  /* Sanity check */
154  ASSERT((Alignment == 1) ||
155  (Alignment == 2) ||
156  (Alignment == 4) ||
157  (Alignment == 8) ||
158  (Alignment == 16));
159 
160  /* Check the alignment */
161  if ((Current & (Alignment - 1)) != 0)
162  {
163  /* Incorrect alignment */
165  }
166 
167  /* Get the end address */
168  Last = Current + Length - 1;
169  if ((Last < Current) || (Last >= (ULONG_PTR)MmUserProbeAddress))
170  {
171  /* Raise an access violation */
173  }
174 
175  /* Round down to the last page */
176  Last = PAGE_ROUND_DOWN(Last) + PAGE_SIZE;
177  do
178  {
179  /* Attempt a write */
180  *(volatile CHAR*)Current = *(volatile CHAR*)Current;
181 
182  /* Go to the next address */
183  Current = PAGE_ROUND_DOWN(Current) + PAGE_SIZE;
184  } while (Current != Last);
185  }
186 }
ULONG MmUserProbeAddress
Definition: init.c:50
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
#define IN
Definition: typedefs.h:38
long __cdecl _InterlockedCompareExchange(_Interlocked_operand_ long volatile *_Destination, long _Exchange, long _Comparand)
LONG FASTCALL InterlockedCompareExchange(IN OUT LONG volatile *Destination, IN LONG Exchange, IN LONG Comperand)
Definition: exintrin.c:59
long __cdecl _InterlockedExchange(_Interlocked_operand_ long volatile *_Target, long _Value)
char CHAR
Definition: xmlstorage.h:175
#define PAGE_ROUND_DOWN(x)
Definition: mmtypes.h:36
#define FASTCALL
Definition: nt_native.h:50
IN OUT PLONG Addend
Definition: CrNtStubs.h:22
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
#define PAGED_CODE()
Definition: video.h:57
uint32_t ULONG_PTR
Definition: typedefs.h:63
long __cdecl _InterlockedIncrement(_Interlocked_operand_ long volatile *_Addend)
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
long LONG
Definition: pedump.c:60
long __cdecl _InterlockedDecrement(_Interlocked_operand_ long volatile *_Addend)
static WCHAR Address[46]
Definition: ping.c:68
LONG FASTCALL InterlockedDecrement(IN LONG volatile *Addend)
Definition: exintrin.c:46
LONG FASTCALL InterlockedIncrement(IN LONG volatile *Addend)
Definition: exintrin.c:33
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:2891
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
VOID NTAPI ExRaiseAccessViolation(VOID)
Definition: harderr.c:310
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
VOID NTAPI ExRaiseDatatypeMisalignment(VOID)
Definition: harderr.c:332
#define PAGE_SIZE
Definition: env_spec_w32.h:49
ULONG_PTR SIZE_T
Definition: typedefs.h:78
LONG FASTCALL InterlockedExchange(IN OUT LONG volatile *Destination, IN LONG Value)
Definition: exintrin.c:74
LONG FASTCALL InterlockedExchangeAdd(IN OUT LONG volatile *Addend, IN LONG Increment)
Definition: exintrin.c:88
#define OUT
Definition: typedefs.h:39
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG Increment
Definition: CrNtStubs.h:42
long __cdecl _InterlockedExchangeAdd(_Interlocked_operand_ long volatile *_Addend, long _Value)
#define CONST
Definition: pedump.c:81