win-pvdrivers

view common/include/xen_windows.h @ 332:52533409dbbd

get things compiling again under DDK
author Andy Grover <andy.grover@oracle.com>
date Thu Jun 19 17:20:16 2008 -0700 (2008-06-19)
parents c563a0f32b2f
children f6841337b2c2
line source
1 #if !defined(_XEN_WINDOWS_H_)
2 #define _XEN_WINDOWS_H_
4 #pragma warning( disable : 4201 ) // nonstandard extension used : nameless struct/union
5 #pragma warning( disable : 4214 ) // nonstandard extension used : bit field types other than int
7 #define __XEN_INTERFACE_VERSION__ 0x00030205
8 #if defined(_AMD64_)
9 #define __x86_64__
10 #elif defined(_IA64_)
11 #define __ia64__
12 #elif defined(__MINGW32__)
13 /* __i386__ already defined */
14 #elif defined(_X86_)
15 #define __i386__
16 #else
17 #error Unknown architecture
18 #endif
20 #ifdef __MINGW32__
21 typedef signed char int8_t;
22 typedef unsigned char uint8_t;
23 typedef signed short int16_t;
24 typedef unsigned short uint16_t;
25 typedef signed int int32_t;
26 typedef unsigned int uint32_t;
27 typedef unsigned long long uint64_t;
28 #else
29 typedef INT8 int8_t;
30 typedef UINT8 uint8_t;
31 typedef INT16 int16_t;
32 typedef UINT16 uint16_t;
33 typedef INT32 int32_t;
34 typedef UINT32 uint32_t;
35 typedef UINT64 uint64_t;
36 #endif
38 #ifdef __MINGW32__
39 #include <stdio.h>
40 #define RtlStringCbCopyA(dst, dst_len, src) strncpy(dst, src, dst_len)
41 #define RtlStringCbPrintfA(args...) snprintf(args)
42 #define RtlStringCbVPrintfA(args...) vsnprintf(args)
43 #endif
44 #include <xen.h>
46 #define _PAGE_PRESENT 0x001UL
47 #define _PAGE_RW 0x002UL
48 #define _PAGE_USER 0x004UL
49 #define _PAGE_PWT 0x008UL
50 #define _PAGE_PCD 0x010UL
51 #define _PAGE_ACCESSED 0x020UL
52 #define _PAGE_DIRTY 0x040UL
53 #define _PAGE_PAT 0x080UL
54 #define _PAGE_PSE 0x080UL
55 #define _PAGE_GLOBAL 0x100UL
57 #define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED)
59 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
61 typedef unsigned long xenbus_transaction_t;
63 #define XBT_NIL ((xenbus_transaction_t)0)
65 #define SPLITSTRING_POOL_TAG (ULONG) 'SSPT'
67 #define wmb() KeMemoryBarrier()
68 #define mb() KeMemoryBarrier()
70 static __inline char **
71 SplitString(char *String, char Split, int MaxParts, int *Count)
72 {
73 char **RetVal;
74 char *first;
75 char *last;
77 //KdPrint((__DRIVER_NAME " a\n"));
79 *Count = 0;
81 RetVal = ExAllocatePoolWithTag(NonPagedPool, (MaxParts + 1) * sizeof(char *), SPLITSTRING_POOL_TAG);
82 last = String;
83 do
84 {
85 if (*Count == MaxParts)
86 break;
87 //KdPrint((__DRIVER_NAME " b - count = %d\n", *Count));
88 first = last;
89 for (last = first; *last != '\0' && *last != Split; last++);
90 RetVal[*Count] = ExAllocatePoolWithTag(NonPagedPool, last - first + 1, SPLITSTRING_POOL_TAG);
91 //KdPrint((__DRIVER_NAME " c - count = %d\n", *Count));
92 strncpy(RetVal[*Count], first, last - first);
93 RetVal[*Count][last - first] = 0;
94 //KdPrint((__DRIVER_NAME " d - count = %d\n", *Count));
95 (*Count)++;
96 //KdPrint((__DRIVER_NAME " e - count = %d\n", *Count));
97 if (*last == Split)
98 last++;
99 } while (*last != 0);
100 //KdPrint((__DRIVER_NAME " f - count = %d\n", *Count));
101 RetVal[*Count] = NULL;
102 return RetVal;
103 }
105 static __inline VOID
106 FreeSplitString(char **Bits, int Count)
107 {
108 int i;
110 for (i = 0; i < Count; i++)
111 ExFreePoolWithTag(Bits[i], SPLITSTRING_POOL_TAG);
112 ExFreePoolWithTag(Bits, SPLITSTRING_POOL_TAG);
113 }
115 #define ALLOCATE_PAGES_POOL_TAG (ULONG) 'APPT'
117 static PMDL
118 AllocatePagesExtra(int Pages, int ExtraSize)
119 {
120 PMDL Mdl;
121 PVOID Buf;
123 Buf = ExAllocatePoolWithTag(NonPagedPool, Pages * PAGE_SIZE, ALLOCATE_PAGES_POOL_TAG);
124 if (Buf == NULL)
125 {
126 KdPrint((__DRIVER_NAME " AllocatePages Failed at ExAllocatePoolWithTag\n"));
127 return NULL;
128 }
129 // KdPrint((__DRIVER_NAME " --- AllocatePages IRQL = %d, Buf = %p\n", KeGetCurrentIrql(), Buf));
130 Mdl = ExAllocatePoolWithTag(NonPagedPool, MmSizeOfMdl(Buf, Pages * PAGE_SIZE) + ExtraSize, ALLOCATE_PAGES_POOL_TAG);
131 //Mdl = IoAllocateMdl(Buf, Pages * PAGE_SIZE, FALSE, FALSE, NULL);
132 if (Mdl == NULL)
133 {
134 // free the memory here
135 KdPrint((__DRIVER_NAME " AllocatePages Failed at IoAllocateMdl\n"));
136 return NULL;
137 }
139 MmInitializeMdl(Mdl, Buf, Pages * PAGE_SIZE);
140 MmBuildMdlForNonPagedPool(Mdl);
142 return Mdl;
143 }
145 static __inline PMDL
146 AllocatePages(int Pages)
147 {
148 return AllocatePagesExtra(Pages, 0);
149 }
151 static __inline PMDL
152 AllocatePage()
153 {
154 return AllocatePagesExtra(1, 0);
155 }
157 static __inline PMDL
158 AllocateUncachedPage()
159 {
160 PMDL mdl;
161 PVOID buf;
163 buf = MmAllocateNonCachedMemory(PAGE_SIZE);
164 mdl = IoAllocateMdl(buf, PAGE_SIZE, FALSE, FALSE, NULL);
165 MmBuildMdlForNonPagedPool(mdl);
167 return mdl;
168 }
170 static __inline VOID
171 FreeUncachedPage(PMDL mdl)
172 {
173 PVOID buf = MmGetMdlVirtualAddress(mdl);
175 IoFreeMdl(mdl);
176 MmFreeNonCachedMemory(buf, PAGE_SIZE);
177 }
179 static __inline VOID
180 FreePages(PMDL Mdl)
181 {
182 PVOID Buf = MmGetMdlVirtualAddress(Mdl);
183 // KdPrint((__DRIVER_NAME " --- FreePages IRQL = %d, Buf = %p\n", KeGetCurrentIrql(), Buf));
184 // IoFreeMdl(Mdl);
185 ExFreePoolWithTag(Mdl, ALLOCATE_PAGES_POOL_TAG);
186 ExFreePoolWithTag(Buf, ALLOCATE_PAGES_POOL_TAG);
187 }
189 #endif