tangled
alpha
login
or
join now
huwcampbell.com
/
reactos
0
fork
atom
Reactos
0
fork
atom
overview
issues
pulls
pipelines
[XDK] Add Read/Write helper functions
Timo Kreuzer
8 months ago
d6cfd00a
c70f7416
+730
-49
4 changed files
expand all
collapse all
unified
split
sdk
include
xdk
memaccess.h
wdm.template.h
winnt.template.h
winnt_old.h
+728
sdk/include/xdk/memaccess.h
reviewed
···
1
1
+
$if(0)
2
2
+
#pragma once
3
3
+
4
4
+
#include <intrin.h>
5
5
+
$endif()
6
6
+
7
7
+
#define KeMemoryBarrierWithoutFence() _ReadWriteBarrier()
8
8
+
9
9
+
#if defined(_M_IX86) || defined(_M_AMD64)
10
10
+
#define PreFetchCacheLine(l, a) _mm_prefetch((char const *) a, l)
11
11
+
#define PF_TEMPORAL_LEVEL_1 _MM_HINT_T0
12
12
+
#define PF_TEMPORAL_LEVEL_2 _MM_HINT_T1
13
13
+
#define PF_TEMPORAL_LEVEL_3 _MM_HINT_T2
14
14
+
#define PF_NON_TEMPORAL_LEVEL_ALL _MM_HINT_NTA
15
15
+
#define _AcquireBarrier()
16
16
+
#define _ReleaseBarrier()
17
17
+
#elif defined(_M_ARM) || defined(_M_ARM64)
18
18
+
#define PreFetchCacheLine(l,a) __prefetch((const void *) (a))
19
19
+
#define PrefetchForWrite(p) __prefetch((const void *) (p))
20
20
+
#define PF_TEMPORAL_LEVEL_1 0
21
21
+
#define PF_TEMPORAL_LEVEL_2 1
22
22
+
#define PF_TEMPORAL_LEVEL_3 2
23
23
+
#define PF_NON_TEMPORAL_LEVEL_ALL 3
24
24
+
#define ReadForWriteAccess(p) (*(p))
25
25
+
#endif
26
26
+
27
27
+
#if !defined(RC_INVOKED)
28
28
+
29
29
+
#if defined(_M_IX86)
30
30
+
__forceinline
31
31
+
void
32
32
+
MemoryBarrier (
33
33
+
void)
34
34
+
{
35
35
+
long Barrier;
36
36
+
_InterlockedOr(&Barrier, 0);
37
37
+
}
38
38
+
#define PrefetchForWrite(p)
39
39
+
#define ReadForWriteAccess(p) (*(p))
40
40
+
#elif defined(_M_AMD64)
41
41
+
#define MemoryBarrier __faststorefence
42
42
+
#define PrefetchForWrite(p) _m_prefetchw(p)
43
43
+
#define ReadForWriteAccess(p) (_m_prefetchw(p), *(p))
44
44
+
#elif defined(_M_ARM)
45
45
+
# define MemoryBarrier() __dmb(_ARM_BARRIER_SY)
46
46
+
# define _AcquireBarrier() __dmb(_ARM_BARRIER_ISH)
47
47
+
# define _ReleaseBarrier() __dmb(_ARM_BARRIER_ISH)
48
48
+
# define _DataSynchronizationBarrier() __dsb(_ARM_BARRIER_SY)
49
49
+
# define _InstructionSynchronizationBarrier() __isb(_ARM_BARRIER_SY)
50
50
+
#elif defined(_M_ARM64)
51
51
+
# define MemoryBarrier() __dmb(_ARM64_BARRIER_SY)
52
52
+
# define _AcquireBarrier() __dmb(_ARM64_BARRIER_ISH)
53
53
+
# define _ReleaseBarrier() __dmb(_ARM64_BARRIER_ISH)
54
54
+
# define _DataSynchronizationBarrier() __dsb(_ARM64_BARRIER_SY)
55
55
+
# define _InstructionSynchronizationBarrier() __isb(_ARM64_BARRIER_SY)
56
56
+
#else
57
57
+
#error Unsupported architecture
58
58
+
#endif /* _M_ARM */
59
59
+
60
60
+
#if defined(_M_IX86) || defined(_M_AMD64)
61
61
+
#define __iso_volatile_load8(p) (*(volatile char*)(p))
62
62
+
#define __iso_volatile_load16(p) (*(volatile short*)(p))
63
63
+
#define __iso_volatile_load32(p) (*(volatile int*)(p))
64
64
+
#define __iso_volatile_load64(p) (*(volatile __int64*)(p))
65
65
+
#define __iso_volatile_store8(p,v) (*(volatile char*)(p) = (v))
66
66
+
#define __iso_volatile_store16(p,v) (*(volatile short*)(p) = (v))
67
67
+
#define __iso_volatile_store32(p,v) (*(volatile int*)(p) = (v))
68
68
+
#define __iso_volatile_store64(p,v) (*(volatile __int64*)(p) = (v))
69
69
+
#endif
70
70
+
71
71
+
__forceinline
72
72
+
char
73
73
+
ReadRaw8 (
74
74
+
_In_ _Interlocked_operand_ char const volatile *Source)
75
75
+
{
76
76
+
return *(char *)Source;
77
77
+
}
78
78
+
79
79
+
__forceinline
80
80
+
void
81
81
+
WriteRaw8 (
82
82
+
_Out_ _Interlocked_operand_ char volatile *Destination,
83
83
+
_In_ char Value)
84
84
+
{
85
85
+
*(char *)Destination = Value;
86
86
+
}
87
87
+
88
88
+
__forceinline
89
89
+
short
90
90
+
ReadRaw16 (
91
91
+
_In_ _Interlocked_operand_ short const volatile *Source)
92
92
+
{
93
93
+
return *(short *)Source;
94
94
+
}
95
95
+
96
96
+
__forceinline
97
97
+
void
98
98
+
WriteRaw16 (
99
99
+
_Out_ _Interlocked_operand_ short volatile *Destination,
100
100
+
_In_ short Value)
101
101
+
{
102
102
+
*(short *)Destination = Value;
103
103
+
}
104
104
+
105
105
+
__forceinline
106
106
+
long
107
107
+
ReadRaw (
108
108
+
_In_ _Interlocked_operand_ long const volatile *Source)
109
109
+
{
110
110
+
return *(long *)Source;
111
111
+
}
112
112
+
113
113
+
__forceinline
114
114
+
void
115
115
+
WriteRaw (
116
116
+
_Out_ _Interlocked_operand_ long volatile *Destination,
117
117
+
_In_ long Value)
118
118
+
{
119
119
+
*(long *)Destination = Value;
120
120
+
}
121
121
+
122
122
+
__forceinline
123
123
+
__int64
124
124
+
ReadRaw64 (
125
125
+
_In_ _Interlocked_operand_ __int64 const volatile *Source)
126
126
+
{
127
127
+
return *(__int64 *)Source;
128
128
+
}
129
129
+
130
130
+
__forceinline
131
131
+
void
132
132
+
WriteRaw64 (
133
133
+
_Out_ _Interlocked_operand_ __int64 volatile *Destination,
134
134
+
_In_ __int64 Value)
135
135
+
{
136
136
+
*(__int64 *)Destination = Value;
137
137
+
}
138
138
+
139
139
+
__forceinline
140
140
+
char
141
141
+
ReadNoFence8 (
142
142
+
_In_ _Interlocked_operand_ char const volatile *Source)
143
143
+
{
144
144
+
return __iso_volatile_load8(Source);
145
145
+
}
146
146
+
147
147
+
__forceinline
148
148
+
void
149
149
+
WriteNoFence8 (
150
150
+
_Out_ _Interlocked_operand_ char volatile *Destination,
151
151
+
_In_ char Value)
152
152
+
{
153
153
+
__iso_volatile_store8(Destination, Value);
154
154
+
}
155
155
+
156
156
+
__forceinline
157
157
+
short
158
158
+
ReadNoFence16 (
159
159
+
_In_ _Interlocked_operand_ short const volatile *Source)
160
160
+
{
161
161
+
return __iso_volatile_load16(Source);
162
162
+
}
163
163
+
164
164
+
__forceinline
165
165
+
void
166
166
+
WriteNoFence16 (
167
167
+
_Out_ _Interlocked_operand_ short volatile *Destination,
168
168
+
_In_ short Value)
169
169
+
{
170
170
+
__iso_volatile_store16(Destination, Value);
171
171
+
}
172
172
+
173
173
+
__forceinline
174
174
+
long
175
175
+
ReadNoFence (
176
176
+
_In_ _Interlocked_operand_ long const volatile *Source)
177
177
+
{
178
178
+
return __iso_volatile_load32((const volatile int*)Source);
179
179
+
}
180
180
+
181
181
+
__forceinline
182
182
+
void
183
183
+
WriteNoFence (
184
184
+
_Out_ _Interlocked_operand_ long volatile *Destination,
185
185
+
_In_ long Value)
186
186
+
{
187
187
+
__iso_volatile_store32((volatile int*)Destination, Value);
188
188
+
}
189
189
+
190
190
+
__forceinline
191
191
+
__int64
192
192
+
ReadNoFence64 (
193
193
+
_In_ _Interlocked_operand_ __int64 const volatile *Source)
194
194
+
{
195
195
+
return __iso_volatile_load64(Source);
196
196
+
}
197
197
+
198
198
+
__forceinline
199
199
+
void
200
200
+
WriteNoFence64 (
201
201
+
_Out_ _Interlocked_operand_ __int64 volatile *Destination,
202
202
+
_In_ __int64 Value)
203
203
+
{
204
204
+
__iso_volatile_store64(Destination, Value);
205
205
+
}
206
206
+
207
207
+
208
208
+
__forceinline
209
209
+
char
210
210
+
ReadAcquire8 (
211
211
+
_In_ _Interlocked_operand_ char const volatile *Source)
212
212
+
{
213
213
+
char Value = __iso_volatile_load8(Source);
214
214
+
_AcquireBarrier();
215
215
+
return Value;
216
216
+
}
217
217
+
218
218
+
__forceinline
219
219
+
void
220
220
+
WriteRelease8 (
221
221
+
_Out_ _Interlocked_operand_ char volatile *Destination,
222
222
+
_In_ char Value)
223
223
+
{
224
224
+
_ReleaseBarrier();
225
225
+
__iso_volatile_store8(Destination, Value);
226
226
+
}
227
227
+
228
228
+
__forceinline
229
229
+
short
230
230
+
ReadAcquire16 (
231
231
+
_In_ _Interlocked_operand_ short const volatile *Source)
232
232
+
{
233
233
+
short Value = __iso_volatile_load16(Source);
234
234
+
_AcquireBarrier();
235
235
+
return Value;
236
236
+
}
237
237
+
238
238
+
__forceinline
239
239
+
void
240
240
+
WriteRelease16 (
241
241
+
_Out_ _Interlocked_operand_ short volatile *Destination,
242
242
+
_In_ short Value)
243
243
+
{
244
244
+
_ReleaseBarrier();
245
245
+
__iso_volatile_store16(Destination, Value);
246
246
+
}
247
247
+
248
248
+
__forceinline
249
249
+
long
250
250
+
ReadAcquire (
251
251
+
_In_ _Interlocked_operand_ long const volatile *Source)
252
252
+
{
253
253
+
long Value = __iso_volatile_load32((const volatile int*)Source);
254
254
+
_AcquireBarrier();
255
255
+
return Value;
256
256
+
}
257
257
+
258
258
+
__forceinline
259
259
+
void
260
260
+
WriteRelease (
261
261
+
_Out_ _Interlocked_operand_ long volatile *Destination,
262
262
+
_In_ long Value)
263
263
+
{
264
264
+
_ReleaseBarrier();
265
265
+
__iso_volatile_store32((volatile int*)Destination, Value);
266
266
+
}
267
267
+
268
268
+
__forceinline
269
269
+
__int64
270
270
+
ReadAcquire64 (
271
271
+
_In_ _Interlocked_operand_ __int64 const volatile *Source)
272
272
+
{
273
273
+
__int64 Value = __iso_volatile_load64(Source);
274
274
+
_AcquireBarrier();
275
275
+
return Value;
276
276
+
}
277
277
+
278
278
+
__forceinline
279
279
+
void
280
280
+
WriteRelease64 (
281
281
+
_Out_ _Interlocked_operand_ __int64 volatile *Destination,
282
282
+
_In_ __int64 Value)
283
283
+
{
284
284
+
_ReleaseBarrier();
285
285
+
__iso_volatile_store64(Destination, Value);
286
286
+
}
287
287
+
288
288
+
289
289
+
__forceinline
290
290
+
unsigned char
291
291
+
ReadUCharAcquire (
292
292
+
_In_ _Interlocked_operand_ unsigned char const volatile *Source)
293
293
+
{
294
294
+
return (unsigned char)ReadAcquire8((char*)Source);
295
295
+
}
296
296
+
297
297
+
__forceinline
298
298
+
unsigned char
299
299
+
ReadUCharNoFence (
300
300
+
_In_ _Interlocked_operand_ unsigned char const volatile *Source)
301
301
+
{
302
302
+
return (unsigned char)ReadNoFence8((char*)Source);
303
303
+
}
304
304
+
305
305
+
__forceinline
306
306
+
unsigned char
307
307
+
ReadUCharRaw (
308
308
+
_In_ _Interlocked_operand_ unsigned char const volatile *Source)
309
309
+
{
310
310
+
return (unsigned char)ReadRaw8((char*)Source);
311
311
+
}
312
312
+
313
313
+
__forceinline
314
314
+
void
315
315
+
WriteUCharRelease (
316
316
+
_Out_ _Interlocked_operand_ unsigned char volatile *Destination,
317
317
+
_In_ unsigned char Value)
318
318
+
{
319
319
+
WriteRelease8((char*)Destination, (char)Value);
320
320
+
}
321
321
+
322
322
+
__forceinline
323
323
+
void
324
324
+
WriteUCharNoFence (
325
325
+
_Out_ _Interlocked_operand_ unsigned char volatile *Destination,
326
326
+
_In_ unsigned char Value)
327
327
+
{
328
328
+
WriteNoFence8((char*)Destination, (char)Value);
329
329
+
}
330
330
+
331
331
+
__forceinline
332
332
+
void
333
333
+
WriteUCharRaw (
334
334
+
_Out_ _Interlocked_operand_ unsigned char volatile *Destination,
335
335
+
_In_ unsigned char Value)
336
336
+
{
337
337
+
WriteRaw8((char*)Destination, (char)Value);
338
338
+
}
339
339
+
340
340
+
__forceinline
341
341
+
BOOLEAN
342
342
+
ReadBooleanAcquire (
343
343
+
_In_ _Interlocked_operand_ BOOLEAN const volatile *Source)
344
344
+
{
345
345
+
return (BOOLEAN)ReadAcquire8((char*)Source);
346
346
+
}
347
347
+
348
348
+
__forceinline
349
349
+
unsigned char
350
350
+
ReadBooleanNoFence (
351
351
+
_In_ _Interlocked_operand_ BOOLEAN const volatile *Source)
352
352
+
{
353
353
+
return (BOOLEAN)ReadNoFence8((char*)Source);
354
354
+
}
355
355
+
356
356
+
__forceinline
357
357
+
void
358
358
+
WriteBooleanRelease (
359
359
+
_Out_ _Interlocked_operand_ BOOLEAN volatile *Destination,
360
360
+
_In_ BOOLEAN Value)
361
361
+
{
362
362
+
WriteRelease8((char*)Destination, (char)Value);
363
363
+
}
364
364
+
365
365
+
__forceinline
366
366
+
void
367
367
+
WriteBooleanNoFence (
368
368
+
_Out_ _Interlocked_operand_ BOOLEAN volatile *Destination,
369
369
+
_In_ BOOLEAN Value)
370
370
+
{
371
371
+
WriteNoFence8((char*)Destination, (char)Value);
372
372
+
}
373
373
+
374
374
+
__forceinline
375
375
+
unsigned short
376
376
+
ReadUShortAcquire (
377
377
+
_In_ _Interlocked_operand_ unsigned short const volatile *Source)
378
378
+
{
379
379
+
return (unsigned short)ReadAcquire16((short*)Source);
380
380
+
}
381
381
+
382
382
+
__forceinline
383
383
+
unsigned short
384
384
+
ReadUShortNoFence (
385
385
+
_In_ _Interlocked_operand_ unsigned short const volatile *Source)
386
386
+
{
387
387
+
return (unsigned short)ReadNoFence16((short*)Source);
388
388
+
}
389
389
+
390
390
+
__forceinline
391
391
+
unsigned short
392
392
+
ReadUShortRaw (
393
393
+
_In_ _Interlocked_operand_ unsigned short const volatile *Source)
394
394
+
{
395
395
+
return (unsigned short)ReadRaw16((short*)Source);
396
396
+
}
397
397
+
398
398
+
__forceinline
399
399
+
void
400
400
+
WriteUShortRelease (
401
401
+
_Out_ _Interlocked_operand_ unsigned short volatile *Destination,
402
402
+
_In_ unsigned short Value)
403
403
+
{
404
404
+
WriteRelease16((short*)Destination, (short)Value);
405
405
+
}
406
406
+
407
407
+
__forceinline
408
408
+
void
409
409
+
WriteUShortNoFence (
410
410
+
_Out_ _Interlocked_operand_ unsigned short volatile *Destination,
411
411
+
_In_ unsigned short Value)
412
412
+
{
413
413
+
WriteNoFence16((short*)Destination, (short)Value);
414
414
+
}
415
415
+
416
416
+
__forceinline
417
417
+
void
418
418
+
WriteUShortRaw (
419
419
+
_Out_ _Interlocked_operand_ unsigned short volatile *Destination,
420
420
+
_In_ unsigned short Value)
421
421
+
{
422
422
+
WriteRaw16((short*)Destination, (short)Value);
423
423
+
}
424
424
+
425
425
+
__forceinline
426
426
+
unsigned long
427
427
+
ReadULongAcquire (
428
428
+
_In_ _Interlocked_operand_ unsigned long const volatile *Source)
429
429
+
{
430
430
+
return (unsigned long)ReadAcquire((long*)Source);
431
431
+
}
432
432
+
433
433
+
__forceinline
434
434
+
unsigned long
435
435
+
ReadULongNoFence (
436
436
+
_In_ _Interlocked_operand_ unsigned long const volatile *Source)
437
437
+
{
438
438
+
return (unsigned long)ReadNoFence((long*)Source);
439
439
+
}
440
440
+
441
441
+
__forceinline
442
442
+
unsigned long
443
443
+
ReadULongRaw (
444
444
+
_In_ _Interlocked_operand_ unsigned long const volatile *Source)
445
445
+
{
446
446
+
return (unsigned long)ReadRaw((long*)Source);
447
447
+
}
448
448
+
449
449
+
__forceinline
450
450
+
void
451
451
+
WriteULongRelease (
452
452
+
_Out_ _Interlocked_operand_ unsigned long volatile *Destination,
453
453
+
_In_ unsigned long Value)
454
454
+
{
455
455
+
WriteRelease((long*)Destination, (long)Value);
456
456
+
}
457
457
+
458
458
+
__forceinline
459
459
+
void
460
460
+
WriteULongNoFence (
461
461
+
_Out_ _Interlocked_operand_ unsigned long volatile *Destination,
462
462
+
_In_ unsigned long Value)
463
463
+
{
464
464
+
WriteNoFence((long*)Destination, (long)Value);
465
465
+
}
466
466
+
467
467
+
__forceinline
468
468
+
void
469
469
+
WriteULongRaw (
470
470
+
_Out_ _Interlocked_operand_ unsigned long volatile *Destination,
471
471
+
_In_ unsigned long Value)
472
472
+
{
473
473
+
WriteRaw((long*)Destination, (long)Value);
474
474
+
}
475
475
+
476
476
+
__forceinline
477
477
+
unsigned __int64
478
478
+
ReadULong64Acquire (
479
479
+
_In_ _Interlocked_operand_ unsigned __int64 const volatile *Source)
480
480
+
{
481
481
+
return (unsigned __int64)ReadAcquire64((__int64*)Source);
482
482
+
}
483
483
+
484
484
+
__forceinline
485
485
+
unsigned __int64
486
486
+
ReadULong64NoFence (
487
487
+
_In_ _Interlocked_operand_ unsigned __int64 const volatile *Source)
488
488
+
{
489
489
+
return (unsigned __int64)ReadNoFence64((__int64*)Source);
490
490
+
}
491
491
+
492
492
+
__forceinline
493
493
+
unsigned __int64
494
494
+
ReadULong64Raw (
495
495
+
_In_ _Interlocked_operand_ unsigned __int64 const volatile *Source)
496
496
+
{
497
497
+
return (unsigned __int64)ReadRaw64((__int64*)Source);
498
498
+
}
499
499
+
500
500
+
__forceinline
501
501
+
void
502
502
+
WriteULong64Release (
503
503
+
_Out_ _Interlocked_operand_ unsigned __int64 volatile *Destination,
504
504
+
_In_ unsigned __int64 Value)
505
505
+
{
506
506
+
WriteRelease64((__int64*)Destination, (__int64)Value);
507
507
+
}
508
508
+
509
509
+
__forceinline
510
510
+
void
511
511
+
WriteULong64NoFence (
512
512
+
_Out_ _Interlocked_operand_ unsigned __int64 volatile *Destination,
513
513
+
_In_ unsigned __int64 Value)
514
514
+
{
515
515
+
WriteNoFence64((__int64*)Destination, (__int64)Value);
516
516
+
}
517
517
+
518
518
+
__forceinline
519
519
+
void
520
520
+
WriteULong64Raw (
521
521
+
_Out_ _Interlocked_operand_ unsigned __int64 volatile *Destination,
522
522
+
_In_ unsigned __int64 Value)
523
523
+
{
524
524
+
WriteRaw64((__int64*)Destination, (__int64)Value);
525
525
+
}
526
526
+
527
527
+
#ifdef _WIN64
528
528
+
529
529
+
__forceinline
530
530
+
void*
531
531
+
ReadPointerAcquire (
532
532
+
_In_ _Interlocked_operand_ void* const volatile *Source)
533
533
+
{
534
534
+
return (void*)ReadAcquire64((__int64*)Source);
535
535
+
}
536
536
+
537
537
+
__forceinline
538
538
+
void*
539
539
+
ReadPointerNoFence (
540
540
+
_In_ _Interlocked_operand_ void* const volatile *Source)
541
541
+
{
542
542
+
return (void*)ReadNoFence64((__int64*)Source);
543
543
+
}
544
544
+
545
545
+
__forceinline
546
546
+
void*
547
547
+
ReadPointerRaw (
548
548
+
_In_ _Interlocked_operand_ void* const volatile *Source)
549
549
+
{
550
550
+
return (void*)ReadRaw64((__int64*)Source);
551
551
+
}
552
552
+
553
553
+
__forceinline
554
554
+
void
555
555
+
WritePointerRelease (
556
556
+
_Out_ _Interlocked_operand_ void* volatile *Destination,
557
557
+
_In_ void* Value)
558
558
+
{
559
559
+
WriteRelease64((__int64*)Destination, (__int64)Value);
560
560
+
}
561
561
+
562
562
+
__forceinline
563
563
+
void
564
564
+
WritePointerNoFence (
565
565
+
_Out_ _Interlocked_operand_ void* volatile *Destination,
566
566
+
_In_ void* Value)
567
567
+
{
568
568
+
WriteNoFence64((__int64*)Destination, (__int64)Value);
569
569
+
}
570
570
+
571
571
+
__forceinline
572
572
+
void
573
573
+
WritePointerRaw (
574
574
+
_Out_ _Interlocked_operand_ void* volatile *Destination,
575
575
+
_In_ void* Value)
576
576
+
{
577
577
+
WriteRaw64((__int64*)Destination, (__int64)Value);
578
578
+
}
579
579
+
580
580
+
#define ReadLongPtrAcquire ReadAcquire64
581
581
+
#define ReadLongPtrNoFence ReadNoFence64
582
582
+
#define ReadLongPtrRaw ReadRaw64
583
583
+
#define WriteLongPtrRelease WriteRelease64
584
584
+
#define WriteLongPtrNoFence WriteNoFence64
585
585
+
#define WriteLongPtrRaw WriteRaw64
586
586
+
#define ReadULongPtrAcquire ReadULong64Acquire
587
587
+
#define ReadULongPtrNoFence ReadULong64NoFence
588
588
+
#define ReadULongPtrRaw ReadULong64Raw
589
589
+
#define WriteULongPtrRelease WriteULong64Release
590
590
+
#define WriteULongPtrNoFence WriteULong64NoFence
591
591
+
#define WriteULongPtrRaw WriteULong64Raw
592
592
+
593
593
+
#else // _WIN64
594
594
+
595
595
+
__forceinline
596
596
+
void*
597
597
+
ReadPointerAcquire (
598
598
+
_In_ _Interlocked_operand_ void* const volatile *Source)
599
599
+
{
600
600
+
return (void*)ReadAcquire((long*)Source);
601
601
+
}
602
602
+
603
603
+
__forceinline
604
604
+
void*
605
605
+
ReadPointerNoFence (
606
606
+
_In_ _Interlocked_operand_ void* const volatile *Source)
607
607
+
{
608
608
+
return (void*)ReadNoFence((long*)Source);
609
609
+
}
610
610
+
611
611
+
__forceinline
612
612
+
void*
613
613
+
ReadPointerRaw (
614
614
+
_In_ _Interlocked_operand_ void* const volatile *Source)
615
615
+
{
616
616
+
return (void*)ReadRaw((long*)Source);
617
617
+
}
618
618
+
619
619
+
__forceinline
620
620
+
void
621
621
+
WritePointerRelease (
622
622
+
_Out_ _Interlocked_operand_ void* volatile *Destination,
623
623
+
_In_ void* Value)
624
624
+
{
625
625
+
WriteRelease((long*)Destination, (long)Value);
626
626
+
}
627
627
+
628
628
+
__forceinline
629
629
+
void
630
630
+
WritePointerNoFence (
631
631
+
_Out_ _Interlocked_operand_ void* volatile *Destination,
632
632
+
_In_opt_ void* Value)
633
633
+
{
634
634
+
WriteNoFence((long*)Destination, (long)Value);
635
635
+
}
636
636
+
637
637
+
__forceinline
638
638
+
void
639
639
+
WritePointerRaw (
640
640
+
_Out_ _Interlocked_operand_ void* volatile *Destination,
641
641
+
_In_opt_ void* Value)
642
642
+
{
643
643
+
WriteRaw((long*)Destination, (long)Value);
644
644
+
}
645
645
+
646
646
+
#define ReadLongPtrAcquire ReadAcquire
647
647
+
#define ReadLongPtrNoFence ReadNoFence
648
648
+
#define ReadLongPtrRaw ReadRaw
649
649
+
#define WriteLongPtrRelease WriteRelease
650
650
+
#define WriteLongPtrNoFence WriteNoFence
651
651
+
#define WriteLongPtrRaw WriteRaw
652
652
+
#define ReadULongPtrAcquire ReadULongAcquire
653
653
+
#define ReadULongPtrNoFence ReadULongNoFence
654
654
+
#define ReadULongPtrRaw ReadULongRaw
655
655
+
#define WriteULongPtrRelease WriteULongRelease
656
656
+
#define WriteULongPtrNoFence WriteULongNoFence
657
657
+
#define WriteULongPtrRaw WriteULongRaw
658
658
+
659
659
+
#endif // _WIN64
660
660
+
661
661
+
#define ReadSizeTAcquire ReadULongPtrAcquire
662
662
+
#define ReadSizeTNoFence ReadULongPtrNoFence
663
663
+
#define ReadSizeTRaw ReadULongPtrRaw
664
664
+
#define WriteSizeTRelease WriteULongPtrRelease
665
665
+
#define WriteSizeTNoFence WriteULongPtrNoFence
666
666
+
#define WriteSizeTRaw WriteULongPtrRaw
667
667
+
668
668
+
/* Overloaded functions for C++ */
669
669
+
#if defined(__cplusplus)
670
670
+
extern "C++" {
671
671
+
672
672
+
template<typename T>
673
673
+
__forceinline
674
674
+
T
675
675
+
ReadRaw (
676
676
+
_In_ _Interlocked_operand_ T const volatile *Source)
677
677
+
{
678
678
+
return *(T*)Source;
679
679
+
}
680
680
+
681
681
+
template<typename T>
682
682
+
__forceinline
683
683
+
void
684
684
+
WriteRaw (
685
685
+
_Out_ _Interlocked_operand_ T volatile *Destination,
686
686
+
_In_ T Value)
687
687
+
{
688
688
+
*(T*)Destination = Value;
689
689
+
}
690
690
+
691
691
+
template<typename T>
692
692
+
__forceinline
693
693
+
T
694
694
+
ReadNoFence (
695
695
+
_In_ _Interlocked_operand_ T const volatile *Source)
696
696
+
{
697
697
+
switch (sizeof(T))
698
698
+
{
699
699
+
case 1: return (T)ReadNoFence8((char const volatile *)Source);
700
700
+
case 2: return (T)ReadNoFence16((short const volatile *)Source);
701
701
+
case 4: return (T)ReadNoFence((long const volatile *)Source);
702
702
+
case 8: return (T)ReadNoFence64((__int64 const volatile *)Source);
703
703
+
}
704
704
+
}
705
705
+
706
706
+
template<typename T>
707
707
+
__forceinline
708
708
+
void
709
709
+
WriteNoFence (
710
710
+
_Out_ _Interlocked_operand_ T volatile *Destination,
711
711
+
_In_ T Value)
712
712
+
{
713
713
+
switch (sizeof(T))
714
714
+
{
715
715
+
case 1: WriteNoFence8((char volatile *)Destination, (char)Value);
716
716
+
case 2: WriteNoFence16((short volatile *)Destination, (short)Value);
717
717
+
case 4: WriteNoFence((long volatile *)Destination, (long)Value);
718
718
+
case 8: WriteNoFence64((__int64 volatile *)Destination, (__int64)Value);
719
719
+
}
720
720
+
}
721
721
+
722
722
+
} // extern "C++"
723
723
+
#endif // __cplusplus
724
724
+
725
725
+
#endif // !defined(RC_INVOKED)
726
726
+
727
727
+
#undef _AcquireBarrier
728
728
+
#undef _ReleaseBarrier
+1
sdk/include/xdk/wdm.template.h
reviewed
···
240
240
241
241
242
242
$define (_WDMDDK_)
243
243
+
$include (memaccess.h)
243
244
$include (interlocked.h)
244
245
$include (rtltypes.h)
245
246
$include (ketypes.h)
+1
sdk/include/xdk/winnt.template.h
reviewed
···
71
71
$define(USHORT=WORD)
72
72
$define(UCHAR=BYTE)
73
73
$include(ntbasedef.h)
74
74
+
$include(memaccess.h)
74
75
$include(interlocked.h)
75
76
$include(ketypes.h)
76
77
$include(extypes.h)
-49
sdk/include/xdk/winnt_old.h
reviewed
···
4572
4572
return *((PVOID *)GetCurrentFiber());
4573
4573
}
4574
4574
4575
4575
-
/* TODO: Other architectures than X86 */
4576
4576
-
#if defined(_M_IX86)
4577
4577
-
#define PF_TEMPORAL_LEVEL_1
4578
4578
-
#define PF_NON_TEMPORAL_LEVEL_ALL
4579
4579
-
#define PreFetchCacheLine(l, a)
4580
4580
-
#elif defined (_M_AMD64)
4581
4581
-
#define PreFetchCacheLine(l, a)
4582
4582
-
#elif defined(_M_PPC)
4583
4583
-
#define PreFetchCacheLine(l, a)
4584
4584
-
#elif defined(_M_ARM)
4585
4585
-
#define PreFetchCacheLine(l, a)
4586
4586
-
#elif defined(_M_ARM64)
4587
4587
-
#define PreFetchCacheLine(l, a)
4588
4588
-
#else
4589
4589
-
#error Unknown architecture
4590
4590
-
#endif
4591
4591
-
4592
4592
-
/* TODO: Other architectures than X86 */
4593
4593
-
#if defined(_M_IX86)
4594
4594
-
#if defined(_MSC_VER)
4595
4595
-
FORCEINLINE
4596
4596
-
VOID
4597
4597
-
MemoryBarrier(VOID)
4598
4598
-
{
4599
4599
-
LONG Barrier;
4600
4600
-
__asm { xchg Barrier, eax }
4601
4601
-
}
4602
4602
-
#else
4603
4603
-
FORCEINLINE
4604
4604
-
VOID
4605
4605
-
MemoryBarrier(VOID)
4606
4606
-
{
4607
4607
-
LONG Barrier, *Dummy = &Barrier;
4608
4608
-
(VOID)Dummy;
4609
4609
-
__asm__ __volatile__("xchgl %%eax, %[Barrier]" : : [Barrier] "m" (Barrier) : "memory");
4610
4610
-
}
4611
4611
-
#endif
4612
4612
-
#elif defined (_M_AMD64)
4613
4613
-
#define MemoryBarrier __faststorefence
4614
4614
-
#elif defined(_M_PPC)
4615
4615
-
#define MemoryBarrier()
4616
4616
-
#elif defined(_M_ARM)
4617
4617
-
#define MemoryBarrier()
4618
4618
-
#elif defined(_M_ARM64)
4619
4619
-
#define MemoryBarrier()
4620
4620
-
#else
4621
4621
-
#error Unknown architecture
4622
4622
-
#endif
4623
4623
-
4624
4575
#if defined(_M_IX86) || defined(_M_AMD64)
4625
4576
4626
4577
#define YieldProcessor _mm_pause