-
Notifications
You must be signed in to change notification settings - Fork 254
/
aehd_types.h
1543 lines (1245 loc) · 35.3 KB
/
aehd_types.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2019 Google LLC
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#pragma warning(disable : 4018)
#pragma warning(disable : 4100)
#pragma warning(disable : 4152)
#pragma warning(disable : 4389)
#pragma warning(disable : 4267)
#pragma warning(disable : 4242)
#pragma warning(disable : 4244)
#pragma warning(disable : 4245)
#include <intrin.h>
#include <ntddk.h>
#define __align(a) __declspec(align(a))
#define inline __inline
#define __always_inline __forceinline
#define __alwaysinline __forceinline
typedef unsigned char uint8_t;
typedef char int8_t;
typedef unsigned short uint16_t;
typedef short int16_t;
typedef unsigned int uint32_t;
typedef int int32_t;
typedef unsigned long long uint64_t;
typedef long long int64_t;
typedef unsigned char u8;
typedef char s8;
typedef unsigned short u16;
typedef short s16;
typedef unsigned int u32;
typedef int s32;
typedef unsigned long long u64;
typedef long long s64;
typedef unsigned char __u8;
typedef char __s8;
typedef unsigned short __u16;
typedef short __s16;
typedef unsigned int __u32;
typedef int __s32;
typedef unsigned long long __u64;
typedef long long __s64;
/* This is a hack. We should really replace ulong to size_t */
typedef size_t ulong;
#define bool _Bool
#define null NULL
/* It seems VS has size_t but not ssize_t*/
typedef intptr_t ssize_t;
// per-cpu implementation
#define MAX_CPU_NUMBERS 512
#define DEFINE_PER_CPU(type, name) \
type name[MAX_CPU_NUMBERS]
#define DECLARE_PER_CPU(type, name) \
extern type name[MAX_CPU_NUMBERS]
#define per_cpu(name, cpu) \
name[cpu]
#define this_cpu_ptr(pname) \
pname[raw_smp_processor_id()]
#define __this_cpu_write(name, val) \
name[smp_processor_id()] = val
//intel pmc stuff
#define INTEL_PMC_MAX_GENERIC 32
#define INTEL_PMC_MAX_FIXED 3
struct irq_work {
int DONOTCARE2;
};
typedef u8 mtrr_type;
#define PAGE_MASK (~(unsigned long long)(PAGE_SIZE - 1))
#define kvm_PAGE_TRACK_MAX 1
/*
* These are used to make use of C type-checking..
*/
typedef size_t pteval_t;
typedef size_t pmdval_t;
typedef size_t pudval_t;
typedef size_t pgdval_t;
typedef size_t pgprotval_t;
typedef struct { pteval_t pte; } pte_t;
#define __default_cpu_present_to_apicid(a) 0
#define NR_CPU_REGS 17
/* BITS_PER_LONG is coming from linux kernel where long int has 64bits for
* x86_64 and 32bits for x86. Microsoft VC always treats long as int. So
* We keep the linux kernel definitions here. Since we replaced long(ulong)
* to ssize_t(size_t). This definition is indeed BITS_PER_SIZET.
*/
#ifdef _WIN64
#define BITS_PER_LONG 64
#else
#define BITS_PER_LONG 32
#endif
#define atomic_read(a) *a
#define __must_check
#define false (unsigned char)0
#define true (unsigned char)1
#pragma warning(disable : 4201)
#pragma pack(push, 1)
struct desc_struct {
union {
struct {
unsigned int a;
unsigned int b;
};
struct {
u16 limit0;
u16 base0;
unsigned base1 : 8, type : 4, s : 1, dpl : 2, p : 1;
unsigned limit : 4, avl : 1, l : 1, d : 1, g : 1, base2 : 8;
};
};
};
/* LDT or TSS descriptor in the GDT. 16 bytes. */
struct ldttss_desc64 {
u16 limit0;
u16 base0;
unsigned base1 : 8, type : 5, dpl : 2, p : 1;
unsigned limit1 : 4, zero0 : 3, g : 1, base2 : 8;
u32 base3;
u32 zero1;
};
#pragma pack(pop)
static __inline size_t get_desc_base(const struct desc_struct *desc)
{
return (size_t)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
}
static __inline void set_desc_base(struct desc_struct *desc, size_t base)
{
desc->base0 = base & 0xffff;
desc->base1 = (base >> 16) & 0xff;
desc->base2 = (base >> 24) & 0xff;
}
static __inline size_t get_desc_limit(const struct desc_struct *desc)
{
return desc->limit0 | (desc->limit << 16);
}
static __inline void set_desc_limit(struct desc_struct *desc, size_t limit)
{
desc->limit0 = limit & 0xffff;
desc->limit = (limit >> 16) & 0xf;
}
#define __user
#ifndef EPERM
#define EPERM 1 /* Operation not permitted */
#endif
#ifndef ENOENT
#define ENOENT 2 /* No such file or directory */
#endif
#ifndef ESRCH
#define ESRCH 3 /* No such process */
#endif
#ifndef EINTR
#define EINTR 4 /* Interrupted system call */
#endif
#ifndef EIO
#define EIO 5 /* I/O error */
#endif
#ifndef ENXIO
#define ENXIO 6 /* No such device or address */
#endif
#ifndef E2BIG
#define E2BIG 7 /* Arg list too long */
#endif
#ifndef ENOEXEC
#define ENOEXEC 8 /* Exec format error */
#endif
#ifndef EBADF
#define EBADF 9 /* Bad file number */
#endif
#ifndef ECHILD
#define ECHILD 10 /* No child processes */
#endif
#ifndef EAGAIN
#define EAGAIN 11 /* Try again */
#endif
#ifndef ENOMEM
#define ENOMEM 12 /* Out of memory */
#endif
#ifndef EACCES
#define EACCES 13 /* Permission denied */
#endif
#ifndef EFAULT
#define EFAULT 14 /* Bad address */
#endif
#ifndef ENOTBLK
#define ENOTBLK 15 /* Block device required */
#endif
#ifndef EBUSY
#define EBUSY 16 /* Device or resource busy */
#endif
#ifndef EEXIST
#define EEXIST 17 /* File exists */
#endif
#ifndef EXDEV
#define EXDEV 18 /* Cross-device link */
#endif
#ifndef ENODEV
#define ENODEV 19 /* No such device */
#endif
#ifndef ENOTDIR
#define ENOTDIR 20 /* Not a directory */
#endif
#ifndef EISDIR
#define EISDIR 21 /* Is a directory */
#endif
#ifndef EINVAL
#define EINVAL 22 /* Invalid argument */
#endif
#ifndef ENFILE
#define ENFILE 23 /* File table overflow */
#endif
#ifndef EMFILE
#define EMFILE 24 /* Too many open files */
#endif
#ifndef ENOTTY
#define ENOTTY 25 /* Not a typewriter */
#endif
#ifndef ETXTBSY
#define ETXTBSY 26 /* Text file busy */
#endif
#ifndef EFBIG
#define EFBIG 27 /* File too large */
#endif
#ifndef ENOSPC
#define ENOSPC 28 /* No space left on device */
#endif
#ifndef ESPIPE
#define ESPIPE 29 /* Illegal seek */
#endif
#ifndef EROFS
#define EROFS 30 /* Read-only file system */
#endif
#ifndef EMLINK
#define EMLINK 31 /* Too many links */
#endif
#ifndef EPIPE
#define EPIPE 32 /* Broken pipe */
#endif
#ifndef EDOM
#define EDOM 33 /* Math argument out of domain of func */
#endif
#ifndef ERANGE
#define ERANGE 34 /* Math result not representable */
#endif
#ifndef EDEADLK
#define EDEADLK 35 /* Resource deadlock would occur */
#endif
#ifndef ENAMETOOLONG
#define ENAMETOOLONG 36 /* File name too long */
#endif
#ifndef ENOLCK
#define ENOLCK 37 /* No record locks available */
#endif
#ifndef ENOSYS
#define ENOSYS 38 /* Function not implemented */
#endif
#ifndef ENOTEMPTY
#define ENOTEMPTY 39 /* Directory not empty */
#endif
#ifndef ELOOP
#define ELOOP 40 /* Too many symbolic links encountered */
#endif
#ifndef EWOULDBLOCK
#define EWOULDBLOCK EAGAIN /* Operation would block */
#endif
#ifndef ENOMSG
#define ENOMSG 42 /* No message of desired type */
#endif
#ifndef EIDRM
#define EIDRM 43 /* Identifier removed */
#endif
#ifndef ECHRNG
#define ECHRNG 44 /* Channel number out of range */
#endif
#ifndef EL2NSYNC
#define EL2NSYNC 45 /* Level 2 not synchronized */
#endif
#ifndef EL3HLT
#define EL3HLT 46 /* Level 3 halted */
#endif
#ifndef EL3RST
#define EL3RST 47 /* Level 3 reset */
#endif
#ifndef ELNRNG
#define ELNRNG 48 /* Link number out of range */
#endif
#ifndef EUNATCH
#define EUNATCH 49 /* Protocol driver not attached */
#endif
#ifndef ENOCSI
#define ENOCSI 50 /* No CSI structure available */
#endif
#ifndef EL2HLT
#define EL2HLT 51 /* Level 2 halted */
#endif
#ifndef EBADE
#define EBADE 52 /* Invalid exchange */
#endif
#ifndef EBADR
#define EBADR 53 /* Invalid request descriptor */
#endif
#ifndef EXFULL
#define EXFULL 54 /* Exchange full */
#endif
#ifndef ENOANO
#define ENOANO 55 /* No anode */
#endif
#ifndef EBADRQC
#define EBADRQC 56 /* Invalid request code */
#endif
#ifndef EBADSLT
#define EBADSLT 57 /* Invalid slot */
#endif
#ifndef EDEADLOCK
#define EDEADLOCK EDEADLK
#endif
#ifndef EBFONT
#define EBFONT 59 /* Bad font file format */
#endif
#ifndef ENOSTR
#define ENOSTR 60 /* Device not a stream */
#endif
#ifndef ENODATA
#define ENODATA 61 /* No data available */
#endif
#ifndef ETIME
#define ETIME 62 /* Timer expired */
#endif
#ifndef ENOSR
#define ENOSR 63 /* Out of streams resources */
#endif
#ifndef ENONET
#define ENONET 64 /* Machine is not on the network */
#endif
#ifndef ENOPKG
#define ENOPKG 65 /* Package not installed */
#endif
#ifndef EREMOTE
#define EREMOTE 66 /* Object is remote */
#endif
#ifndef ENOLINK
#define ENOLINK 67 /* Link has been severed */
#endif
#ifndef EADV
#define EADV 68 /* Advertise error */
#endif
#ifndef ESRMNT
#define ESRMNT 69 /* Srmount error */
#endif
#ifndef ECOMM
#define ECOMM 70 /* Communication error on send */
#endif
#ifndef EPROTO
#define EPROTO 71 /* Protocol error */
#endif
#ifndef EMULTIHOP
#define EMULTIHOP 72 /* Multihop attempted */
#endif
#ifndef EDOTDOT
#define EDOTDOT 73 /* RFS specific error */
#endif
#ifndef EBADMSG
#define EBADMSG 74 /* Not a data message */
#endif
#ifndef EOVERFLOW
#define EOVERFLOW 75 /* Value too large for defined data type */
#endif
#ifndef ENOTUNIQ
#define ENOTUNIQ 76 /* Name not unique on network */
#endif
#ifndef EBADFD
#define EBADFD 77 /* File descriptor in bad state */
#endif
#ifndef EREMCHG
#define EREMCHG 78 /* Remote address changed */
#endif
#ifndef ELIBACC
#define ELIBACC 79 /* Can not access a needed shared library */
#endif
#ifndef ELIBBAD
#define ELIBBAD 80 /* Accessing a corrupted shared library */
#endif
#ifndef ELIBSCN
#define ELIBSCN 81 /* .lib section in a.out corrupted */
#endif
#ifndef ELIBMAX
#define ELIBMAX 82 /* Attempting to link in too many shared libraries */
#endif
#ifndef ELIBEXEC
#define ELIBEXEC 83 /* Cannot exec a shared library directly */
#endif
#ifndef EILSEQ
#define EILSEQ 84 /* Illegal byte sequence */
#endif
#ifndef ERESTART
#define ERESTART 85 /* Interrupted system call should be restarted */
#endif
#ifndef ESTRPIPE
#define ESTRPIPE 86 /* Streams pipe error */
#endif
#ifndef EUSERS
#define EUSERS 87 /* Too many users */
#endif
#ifndef ENOTSOCK
#define ENOTSOCK 88 /* Socket operation on non-socket */
#endif
#ifndef EDESTADDRREQ
#define EDESTADDRREQ 89 /* Destination address required */
#endif
#ifndef EMSGSIZE
#define EMSGSIZE 90 /* Message too long */
#endif
#ifndef EPROTOTYPE
#define EPROTOTYPE 91 /* Protocol wrong type for socket */
#endif
#ifndef ENOPROTOOPT
#define ENOPROTOOPT 92 /* Protocol not available */
#endif
#ifndef EPROTONOSUPPORT
#define EPROTONOSUPPORT 93 /* Protocol not supported */
#endif
#ifndef ESOCKTNOSUPPORT
#define ESOCKTNOSUPPORT 94 /* Socket type not supported */
#endif
#ifndef EOPNOTSUPP
#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
#endif
#ifndef EPFNOSUPPORT
#define EPFNOSUPPORT 96 /* Protocol family not supported */
#endif
#ifndef EAFNOSUPPORT
#define EAFNOSUPPORT 97 /* Address family not supported by protocol */
#endif
#ifndef EADDRINUSE
#define EADDRINUSE 98 /* Address already in use */
#endif
#ifndef EADDRNOTAVAIL
#define EADDRNOTAVAIL 99 /* Cannot assign requested address */
#endif
#ifndef ENETDOWN
#define ENETDOWN 100 /* Network is down */
#endif
#ifndef ENETUNREACH
#define ENETUNREACH 101 /* Network is unreachable */
#endif
#ifndef ENETRESET
#define ENETRESET 102 /* Network dropped connection because of reset */
#endif
#ifndef ECONNABORTED
#define ECONNABORTED 103 /* Software caused connection abort */
#endif
#ifndef ECONNRESET
#define ECONNRESET 104 /* Connection reset by peer */
#endif
#ifndef ENOBUFS
#define ENOBUFS 105 /* No buffer space available */
#endif
#ifndef EISCONN
#define EISCONN 106 /* Transport endpoint is already connected */
#endif
#ifndef ENOTCONN
#define ENOTCONN 107 /* Transport endpoint is not connected */
#endif
#ifndef ESHUTDOWN
#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
#endif
#ifndef ETOOMANYREFS
#define ETOOMANYREFS 109 /* Too many references: cannot splice */
#endif
#ifndef ETIMEDOUT
#define ETIMEDOUT 110 /* Connection timed out */
#endif
#ifndef ECONNREFUSED
#define ECONNREFUSED 111 /* Connection refused */
#endif
#ifndef EHOSTDOWN
#define EHOSTDOWN 112 /* Host is down */
#endif
#ifndef EHOSTUNREACH
#define EHOSTUNREACH 113 /* No route to host */
#endif
#ifndef EALREADY
#define EALREADY 114 /* Operation already in progress */
#endif
#ifndef EINPROGRESS
#define EINPROGRESS 115 /* Operation now in progress */
#endif
#ifndef ESTALE
#define ESTALE 116 /* Stale NFS file handle */
#endif
#ifndef EUCLEAN
#define EUCLEAN 117 /* Structure needs cleaning */
#endif
#ifndef ENOTNAM
#define ENOTNAM 118 /* Not a XENIX named type file */
#endif
#ifndef ENAVAIL
#define ENAVAIL 119 /* No XENIX semaphores available */
#endif
#ifndef EISNAM
#define EISNAM 120 /* Is a named type file */
#endif
#ifndef EREMOTEIO
#define EREMOTEIO 121 /* Remote I/O error */
#endif
#ifndef EDQUOT
#define EDQUOT 122 /* Quota exceeded */
#endif
#ifndef ENOMEDIUM
#define ENOMEDIUM 123 /* No medium found */
#endif
#ifndef EMEDIUMTYPE
#define EMEDIUMTYPE 124 /* Wrong medium type */
#endif
#ifndef ECANCELED
#define ECANCELED 125 /* Operation Cancelled */
#endif
#ifndef ENOKEY
#define ENOKEY 126 /* Required key not available */
#endif
#ifndef EKEYEXPIRED
#define EKEYEXPIRED 127 /* Key has expired */
#endif
#ifndef EKEYREVOKED
#define EKEYREVOKED 128 /* Key has been revoked */
#endif
#ifndef EKEYREJECTED
#define EKEYREJECTED 129 /* Key was rejected by service */
#endif
#ifndef MAX_ERRNO
#define MAX_ERRNO 4095
#endif
#define IS_ERR_VALUE(x) ((x) >= (size_t)-MAX_ERRNO)
static __inline void* ERR_PTR(ssize_t error)
{
return (void *)error;
}
static __inline size_t PTR_ERR(const void *ptr)
{
return (size_t)ptr;
}
static __inline size_t IS_ERR(const void *ptr)
{
return IS_ERR_VALUE((size_t)ptr);
}
#define FOLL_NOWAIT 0
#define FOLL_HWPOISON 0
#define FOLL_WRITE 0
#define FOLL_TOUCH 0
#define FOLL_NOWAIT 0
#define VM_READ
#define down_read(a)
#define up_read(a)
#define WRITE_ONCE(a, b) \
do { \
_ReadWriteBarrier(); \
a = b; \
} while(0)
#define ACCESS_ONCE(a, b) \
do { \
_ReadWriteBarrier(); \
b = a; \
} while(0)
#define READ_ONCE(a, b) ACCESS_ONCE(a, b)
#define WARN_ON(a) 0
#define PIDTYPE_PID 0
#define NOTIFY_OK 0
#define atomic_set(a, b) WRITE_ONCE(*a, b)
#define XSAVE_HDR_SIZE 0
#define XSAVE_HDR_OFFSET 0x10
#define XFEATURE_MASK_EXTEND 0x0
#define might_sleep() 0
// visual c compiler does not support branch hint
#define likely(a) a
#define unlikely(a) a
#define kvm_pmu_refresh(a) 0
#define printk DbgPrint
#define pr_info_ratelimited DbgPrint
#define printk_ratelimited DbgPrint
#define printk_once DbgPrint
#define kdprint DbgPrint
#define pr_info DbgPrint
#define pr_warn_once DbgPrint
// cpuid.c
enum cpuid_leafs
{
CPUID_1_EDX = 0,
CPUID_8000_0001_EDX,
CPUID_8086_0001_EDX,
CPUID_LNX_1,
CPUID_1_ECX,
CPUID_C000_0001_EDX,
CPUID_8000_0001_ECX,
CPUID_LNX_2,
CPUID_LNX_3,
CPUID_7_0_EBX,
CPUID_D_1_EAX,
CPUID_F_0_EDX,
CPUID_F_1_EDX,
CPUID_8000_0008_EBX,
CPUID_6_EAX,
CPUID_8000_000A_EDX,
CPUID_7_ECX,
CPUID_8000_0007_EBX,
};
extern int CPU_HAS_X86_FEATURE_XSAVE;
extern int CPU_HAS_X86_FEATURE_PKU;
extern int CPU_HAS_X86_FEATURE_GBPAGES;
extern int CPU_HAS_X86_FEATURE_HLE;
extern int CPU_HAS_X86_FEATURE_RTM;
extern int CPU_HAS_X86_FEATURE_NX;
extern int CPU_HAS_X86_FEATURE_FXSR_OPT;
extern int CPU_HAS_X86_FEATURE_NPT;
extern int CPU_HAS_X86_FEATURE_AVIC;
extern int CPU_HAS_X86_FEATURE_DECODEASSISTS;
extern int CPU_HAS_X86_FEATURE_RDTSCP;
extern int CPU_HAS_X86_FEATURE_LBRV;
extern int CPU_HAS_X86_FEATURE_NRIPS;
extern int CPU_HAS_X86_FEATURE_SMEP;
extern int CPU_HAS_X86_FEATURE_SMAP;
extern int CPU_HAS_X86_FEATURE_MPX;
extern int CPU_HAS_X86_FEATURE_XSAVES;
extern int CPU_HAS_X86_FEATURE_CONSTANT_TSC;
extern int CPU_HAS_X86_BUG_AMD_TLB_MMATCH;
extern int CPU_HAS_X86_FEATURE_FLUSHBYASID;
extern int CPU_HAS_X86_FEATURE_OSVW;
extern int CPU_HAS_X86_FEATURE_SVM;
#define cpu_has(notused, feature) (CPU_HAS_##feature)
#define boot_cpu_has(feature) (CPU_HAS_##feature)
#define static_cpu_has(feature) (CPU_HAS_##feature)
#define WARN_ON_ONCE(a) 0
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
#define __min_t_func_type(a) \
static __inline a __##a##_min(a b, a c) \
{ \
return (b < c) ? b : c; \
}
__min_t_func_type(unsigned)
__min_t_func_type(u64)
__min_t_func_type(u32)
__min_t_func_type(int)
#define min_t(a, b, c) __##a##_min((b), (c))
#define offset_in_page(p) ((size_t)(p) & ~PAGE_MASK)
// Let's borrow MS's HYPERVISOR_ERR here
#define BUG() KeBugCheck(0x00020001)
#define BUG_ON(cond) do { if (cond) BUG();} while (0)
#define volatile
#define min3(a, b, c) min(min(a, b),c)
#pragma pack(push, 1)
struct desc_ptr {
unsigned short size;
size_t address;
};
#pragma pack(pop)
/*
* Bottom two bits of selector give the ring
* privilege level
*/
#define SEGMENT_RPL_MASK 0x3
/* User mode is privilege level 3: */
#define USER_RPL 0x3
/* Bit 2 is Table Indicator (TI): selects between LDT or GDT */
#define SEGMENT_TI_MASK 0x4
/* LDT segment has TI set ... */
#define SEGMENT_LDT 0x4
/* ... GDT has it cleared */
#define SEGMENT_GDT 0x0
#define GDT_ENTRY_INVALID_SEG 0
#define swab16 RtlUshortByteSwap
#define swab32 RtlUlongByteSwap
#define swab64 RtlUlonglongByteSwap
#define container_of CONTAINING_RECORD
#define KERN_WARNING
#define KERN_INFO
#define KERN_ERR
#define KERN_CRIT
#define KERN_DEBUG
// Bitmaps
#define BITS_TO_LONGS(bits) (bits + BITS_PER_LONG - 1)/BITS_PER_LONG
#define DECLARE_BITMAP(name, bits) \
size_t name[BITS_TO_LONGS(bits)]
#define BITMAP_FIRST_WORD_MASK(start) (~(size_t)0 << ((start) & (BITS_PER_LONG - 1)))
#define BITMAP_LAST_WORD_MASK(nbits) (~(size_t)0 >> (-((ssize_t)nbits) & (BITS_PER_LONG - 1)))
#define small_const_nbits(nbits) \
((nbits) <= BITS_PER_LONG)
static __inline int __bitmap_and(size_t *dst, const size_t *bitmap1,
const size_t *bitmap2, unsigned int bits)
{
unsigned int k;
unsigned int lim = bits / BITS_PER_LONG;
size_t result = 0;
for (k = 0; k < lim; k++)
result |= (dst[k] = bitmap1[k] & bitmap2[k]);
if (bits % BITS_PER_LONG)
result |= (dst[k] = bitmap1[k] & bitmap2[k] &
BITMAP_LAST_WORD_MASK(bits));
return result != 0;
}
static __inline void __bitmap_or(size_t *dst, const size_t *bitmap1,
const size_t *bitmap2, unsigned int bits)
{
unsigned int k;
unsigned int nr = BITS_TO_LONGS(bits);
for (k = 0; k < nr; k++)
dst[k] = bitmap1[k] | bitmap2[k];
}
static __inline void __bitmap_xor(size_t *dst, const size_t *bitmap1,
const size_t *bitmap2, unsigned int bits)
{
unsigned int k;
unsigned int nr = BITS_TO_LONGS(bits);
for (k = 0; k < nr; k++)
dst[k] = bitmap1[k] ^ bitmap2[k];
}
static __inline int __bitmap_andnot(size_t *dst, const size_t *bitmap1,
const size_t *bitmap2, unsigned int bits)
{
unsigned int k;
unsigned int lim = bits / BITS_PER_LONG;
size_t result = 0;
for (k = 0; k < lim; k++)
result |= (dst[k] = bitmap1[k] & ~bitmap2[k]);
if (bits % BITS_PER_LONG)
result |= (dst[k] = bitmap1[k] & ~bitmap2[k] &
BITMAP_LAST_WORD_MASK(bits));
return result != 0;
}
static __inline void __bitmap_complement(size_t *dst, const size_t *src, unsigned int bits)
{
unsigned int k, lim = bits / BITS_PER_LONG;
for (k = 0; k < lim; ++k)
dst[k] = ~src[k];
if (bits % BITS_PER_LONG)
dst[k] = ~src[k];
}
static __inline void bitmap_zero(size_t *dst, unsigned int nbits)
{
if (small_const_nbits(nbits))
*dst = 0UL;
else {
unsigned int len = BITS_TO_LONGS(nbits) * sizeof(size_t);
memset(dst, 0, len);
}
}
static __inline void bitmap_copy(size_t *dst, const size_t *src,
unsigned int nbits)
{
if (small_const_nbits(nbits))
*dst = *src;
else {
unsigned int len = BITS_TO_LONGS(nbits) * sizeof(size_t);
memcpy(dst, src, len);
}
}
static __inline int bitmap_and(size_t *dst, const size_t *src1,
const size_t *src2, unsigned int nbits)
{
if (small_const_nbits(nbits))
return (*dst = *src1 & *src2 & BITMAP_LAST_WORD_MASK(nbits)) != 0;
return __bitmap_and(dst, src1, src2, nbits);
}
static __inline void bitmap_or(size_t *dst, const size_t *src1,
const size_t *src2, unsigned int nbits)
{
if (small_const_nbits(nbits))
*dst = *src1 | *src2;
else
__bitmap_or(dst, src1, src2, nbits);
}
static __inline void bitmap_xor(size_t *dst, const size_t *src1,
const size_t *src2, unsigned int nbits)
{
if (small_const_nbits(nbits))
*dst = *src1 ^ *src2;
else
__bitmap_xor(dst, src1, src2, nbits);
}
static __inline int bitmap_andnot(size_t *dst, const size_t *src1,
const size_t *src2, unsigned int nbits)
{