win-pvdrivers

view common/include/xen_windows.h @ 160:71d971853d57

Fixed a structure packing problem which was breaking vbd when used with a 32 bit backend.
author James Harper <james.harper@bendigoit.com.au>
date Fri Feb 01 16:47:42 2008 +1100 (2008-02-01)
parents 2efec00dd95f
children d90e78d0e7b7
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 #else
11 #if defined(_IA64_)
12 #define __ia64__
13 #else
14 #if defined(_X86_)
15 #define __i386__
16 #else
17 #error Unknown architecture
18 #endif
19 #endif
20 #endif
21 typedef INT8 int8_t;
22 typedef UINT8 uint8_t;
23 typedef INT16 int16_t;
24 typedef UINT16 uint16_t;
25 typedef INT32 int32_t;
26 typedef UINT32 uint32_t;
27 typedef UINT64 uint64_t;
28 //typedef unsigned long pgentry_t;
30 #include <xen.h>
32 #define _PAGE_PRESENT 0x001UL
33 #define _PAGE_RW 0x002UL
34 #define _PAGE_USER 0x004UL
35 #define _PAGE_PWT 0x008UL
36 #define _PAGE_PCD 0x010UL
37 #define _PAGE_ACCESSED 0x020UL
38 #define _PAGE_DIRTY 0x040UL
39 #define _PAGE_PAT 0x080UL
40 #define _PAGE_PSE 0x080UL
41 #define _PAGE_GLOBAL 0x100UL
43 #define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED)
45 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
47 typedef unsigned long xenbus_transaction_t;
48 typedef uint32_t XENSTORE_RING_IDX;
50 #define XBT_NIL ((xenbus_transaction_t)0)
52 #define SPLITSTRING_POOL_TAG (ULONG) 'SSPT'
54 static char **
55 SplitString(char *String, char Split, int MaxParts, int *Count)
56 {
57 char **RetVal;
58 char *first;
59 char *last;
61 //KdPrint((__DRIVER_NAME " a\n"));
63 *Count = 0;
65 RetVal = ExAllocatePoolWithTag(NonPagedPool, (MaxParts + 1) * sizeof(char *), SPLITSTRING_POOL_TAG);
66 last = String;
67 do
68 {
69 if (*Count == MaxParts)
70 break;
71 //KdPrint((__DRIVER_NAME " b - count = %d\n", *Count));
72 first = last;
73 for (last = first; *last != '\0' && *last != Split; last++);
74 RetVal[*Count] = ExAllocatePoolWithTag(NonPagedPool, last - first + 1, SPLITSTRING_POOL_TAG);
75 //KdPrint((__DRIVER_NAME " c - count = %d\n", *Count));
76 strncpy(RetVal[*Count], first, last - first);
77 RetVal[*Count][last - first] = 0;
78 //KdPrint((__DRIVER_NAME " d - count = %d\n", *Count));
79 (*Count)++;
80 //KdPrint((__DRIVER_NAME " e - count = %d\n", *Count));
81 if (*last == Split)
82 last++;
83 } while (*last != 0);
84 //KdPrint((__DRIVER_NAME " f - count = %d\n", *Count));
85 RetVal[*Count] = NULL;
86 return RetVal;
87 }
89 static VOID
90 FreeSplitString(char **Bits, int Count)
91 {
92 int i;
94 for (i = 0; i < Count; i++)
95 ExFreePoolWithTag(Bits[i], SPLITSTRING_POOL_TAG);
96 ExFreePoolWithTag(Bits, SPLITSTRING_POOL_TAG);
97 }
99 #define ALLOCATE_PAGES_POOL_TAG (ULONG) 'APPT'
101 static PMDL
102 AllocatePages(int Pages)
103 {
104 PMDL Mdl;
105 PVOID Buf;
107 Buf = ExAllocatePoolWithTag(NonPagedPool, Pages * PAGE_SIZE, ALLOCATE_PAGES_POOL_TAG);
108 if (Buf == NULL)
109 {
110 KdPrint((__DRIVER_NAME " AllocatePages Failed at ExAllocatePoolWithTag\n"));
111 return NULL;
112 }
113 KdPrint((__DRIVER_NAME " --- AllocatePages IRQL = %d, Buf = %p\n", KeGetCurrentIrql(), Buf));
114 Mdl = IoAllocateMdl(Buf, Pages * PAGE_SIZE, FALSE, FALSE, NULL);
115 if (Mdl == NULL)
116 {
117 // free the memory here
118 KdPrint((__DRIVER_NAME " AllocatePages Failed at IoAllocateMdl\n"));
119 return NULL;
120 }
121 MmBuildMdlForNonPagedPool(Mdl);
123 return Mdl;
124 }
126 static PMDL
127 AllocatePage()
128 {
129 return AllocatePages(1);
130 }
132 static VOID
133 FreePages(PMDL Mdl)
134 {
135 PVOID Buf = MmGetMdlVirtualAddress(Mdl);
136 KdPrint((__DRIVER_NAME " --- FreePages IRQL = %d, Buf = %p\n", KeGetCurrentIrql(), Buf));
137 IoFreeMdl(Mdl);
138 ExFreePoolWithTag(Buf, ALLOCATE_PAGES_POOL_TAG);
139 }
141 #endif