ReactOS 0.4.16-dev-1369-gd4d04c8
intrin_i.h
Go to the documentation of this file.
1#ifndef _INTRIN_INTERNAL_
2#define _INTRIN_INTERNAL_
3
7{
8 __writecr8(Irql);
9}
10
13KiGetGdtEntry(PVOID pGdt, USHORT Selector)
14{
15 return (PKGDTENTRY64)((ULONG64)pGdt + (Selector & ~RPL_MASK));
16}
17
21{
22 return (PVOID)((ULONG64)Entry->BaseLow |
23 (ULONG64)Entry->Bytes.BaseMiddle << 16 |
24 (ULONG64)Entry->Bytes.BaseHigh << 24 |
25 (ULONG64)Entry->BaseUpper << 32);
26}
27
29VOID
31{
32 Entry->BaseLow = Base & 0xffff;
33 Entry->Bits.BaseMiddle = (Base >> 16) & 0xff;
34 Entry->Bits.BaseHigh = (Base >> 24) & 0xff;
35 Entry->BaseUpper = Base >> 32;
36}
37
39VOID
41{
42 Entry->LimitLow = Limit & 0xffff;
43 Entry->Bits.LimitHigh = Limit >> 16;
44}
45
47VOID
49{
52 Entry->Bits.Type = Type;
53 Entry->Bits.Dpl = Dpl;
54 Entry->Bits.Present = 1;
55 Entry->Bits.System = 0;
56 Entry->Bits.LongMode = 0;
57 Entry->Bits.DefaultBig = 0;
58 Entry->Bits.Granularity = 0;
59 Entry->MustBeZero = 0;
60}
61
63
65VOID
68 _In_ ULONG64 ComponentMask)
69{
70 ComponentMask &= ~XSTATE_MASK_LEGACY_SSE;
72 {
73 _xsaves64(Buffer, ComponentMask);
74 }
75 else if (KeFeatureBits & KF_XSAVEOPT)
76 {
77 _xsaveopt64(Buffer, ComponentMask);
78 }
79 else if (KeFeatureBits & KF_XSTATE)
80 {
81 _xsave64(Buffer, ComponentMask);
82 }
83 else
84 {
85 _fxsave64(Buffer);
86 }
87}
88
90VOID
93 _In_ ULONG64 ComponentMask)
94{
95 ComponentMask &= ~XSTATE_MASK_LEGACY_SSE;
97 {
98 _xrstors64(Buffer, ComponentMask);
99 }
100 else if (KeFeatureBits & KF_XSTATE)
101 {
102 _xrstor64(Buffer, ComponentMask);
103 }
104 else
105 {
106 _fxrstor64(Buffer);
107 }
108}
109
110#if defined(__GNUC__)
111
112static __inline__ __attribute__((always_inline)) void __lgdt(void *Source)
113{
114 __asm__ __volatile__("lgdt %0" : : "m"(*(short*)Source));
115}
116
117static __inline__ __attribute__((always_inline)) void __sgdt(void *Destination)
118{
119 __asm__ __volatile__("sgdt %0" : : "m"(*(short*)Destination) : "memory");
120}
121
122static __inline__ __attribute__((always_inline)) void __lldt(unsigned short Value)
123{
124 __asm__ __volatile__("lldt %0" : : "rm"(Value));
125}
126
127static __inline__ __attribute__((always_inline)) void __sldt(void *Destination)
128{
129 __asm__ __volatile__("sldt %0" : : "m"(*(short*)Destination) : "memory");
130}
131
132static __inline__ __attribute__((always_inline)) void __ltr(unsigned short Source)
133{
134 __asm__ __volatile__("ltr %0" : : "rm"(Source));
135}
136
137static __inline__ __attribute__((always_inline)) void __str(unsigned short *Destination)
138{
139 __asm__ __volatile__("str %0" : : "m"(*Destination) : "memory");
140}
141
142static __inline__ __attribute__((always_inline)) void __swapgs(void)
143{
144 __asm__ __volatile__("swapgs" : : : "memory");
145}
146
147#elif defined(_MSC_VER)
148
149void __lgdt(void *Source);
150
151void __sgdt(void *Destination);
152
153void __lldt(unsigned short Value);
154
155void __sldt(void *Destination);
156
157void __ltr(unsigned short Source);
158
159void __str(unsigned short *Destination);
160
161void __swapgs(void);
162
163#else
164#error Unknown compiler for inline assembler
165#endif
166
167#endif
168
169/* EOF */
Type
Definition: Type.h:7
ULONG64 KeFeatureBits
Definition: krnlinit.c:22
FORCEINLINE VOID KiRestoreXState(_In_ PVOID Buffer, _In_ ULONG64 ComponentMask)
Definition: intrin_i.h:91
FORCEINLINE VOID KeSetCurrentIrql(KIRQL Irql)
Definition: intrin_i.h:6
FORCEINLINE VOID KiSetGdtDescriptorLimit(PKGDTENTRY Entry, ULONG Limit)
Definition: intrin_i.h:40
FORCEINLINE PKGDTENTRY64 KiGetGdtEntry(PVOID pGdt, USHORT Selector)
Definition: intrin_i.h:13
FORCEINLINE VOID KiSetGdtDescriptorBase(PKGDTENTRY Entry, ULONG64 Base)
Definition: intrin_i.h:30
FORCEINLINE PVOID KiGetGdtDescriptorBase(PKGDTENTRY Entry)
Definition: intrin_i.h:20
FORCEINLINE VOID KiSaveXState(_Out_ PVOID Buffer, _In_ ULONG64 ComponentMask)
Definition: intrin_i.h:66
FORCEINLINE VOID KiInitGdtEntry(PKGDTENTRY64 Entry, ULONG64 Base, ULONG Size, UCHAR Type, UCHAR Dpl)
Definition: intrin_i.h:48
Definition: bufpool.h:45
_Out_ PKIRQL Irql
Definition: csq.h:179
#define __attribute__(x)
Definition: wpp_private.h:207
UCHAR KIRQL
Definition: env_spec_w32.h:591
unsigned __int64 ULONG64
Definition: imports.h:198
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3169
#define KF_XSTATE
Definition: ketypes.h:55
#define KF_XSAVES
Definition: ketypes.h:68
#define KF_XSAVEOPT
Definition: ketypes.h:47
#define RPL_MASK
Definition: ketypes.h:124
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:3043
_In_opt_ ULONG Base
Definition: rtlfuncs.h:2478
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
unsigned short USHORT
Definition: pedump.c:61
__asm__(".p2align 4, 0x90\n" ".seh_proc __seh2_global_filter_func\n" "__seh2_global_filter_func:\n" "\tsub %rbp, %rax\n" "\tpush %rbp\n" "\t.seh_pushreg %rbp\n" "\tsub $32, %rsp\n" "\t.seh_stackalloc 32\n" "\t.seh_endprologue\n" "\tsub %rax, %rdx\n" "\tmov %rdx, %rbp\n" "\tjmp *%r8\n" "__seh2_global_filter_func_exit:\n" "\t.p2align 4\n" "\tadd $32, %rsp\n" "\tpop %rbp\n" "\tret\n" "\t.seh_endproc")
base of all file and directory entries
Definition: entries.h:83
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
#define FORCEINLINE
Definition: wdftypes.h:67
_In_ LONG _In_ LONG Limit
Definition: kefuncs.h:304
unsigned char UCHAR
Definition: xmlstorage.h:181