win-pvdrivers

view liblfds.6/inc/liblfds.h @ 766:6300617040e0

Big changes - not ready for production use.
Removed all the custom DMA handling code as it was completely incompatible with the Windows verifier.
Added liblfds (using the lock free stack) from liblfds.org so that grant's can be obtained at DIRQL.
Fixed xennet and xenvbd to support the changes.
xenusb and xenscsi almost certainly will not yet work after the changes.
author James Harper <james.harper@bendigoit.com.au>
date Sun Jan 31 21:28:42 2010 +1100 (2010-01-31)
parents
children
line source
1 #ifndef __LIBLFDS_H
3 /***** library header *****/
4 #define LIBLFDS_RELEASE_NUMBER 6
9 /***** abstraction *****/
11 /***** defines *****/
12 #if (defined _WIN64 && defined _MSC_VER && !defined WIN_KERNEL_BUILD)
13 // TRD : 64-bit Windows user-mode with the Microsoft C compiler, any CPU
14 #include <assert.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <windows.h>
18 #include <intrin.h>
19 typedef unsigned __int64 atom_t;
20 #define INLINE extern __forceinline
21 #define ALIGN(alignment) __declspec( align(alignment) )
22 #define ALIGN_SINGLE_POINTER 8
23 #define ALIGN_DOUBLE_POINTER 16
24 #endif
26 #if (!defined _WIN64 && defined _WIN32 && defined _MSC_VER && !defined WIN_KERNEL_BUILD)
27 // TRD : 32-bit Windows user-mode with the Microsoft C compiler, any CPU
28 #include <assert.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <windows.h>
32 #include <intrin.h>
33 typedef unsigned long int atom_t;
34 #define INLINE extern __forceinline
35 #define ALIGN(alignment) __declspec( align(alignment) )
36 #define ALIGN_SINGLE_POINTER 4
37 #define ALIGN_DOUBLE_POINTER 8
39 // TRD : this define is documented but missing in Microsoft Platform SDK v7.0
40 #define _InterlockedCompareExchangePointer(destination, exchange, compare) _InterlockedCompareExchange((volatile long *) destination, (long) exchange, (long) compare)
41 #endif
43 #if (defined _WIN64 && defined _MSC_VER && defined WIN_KERNEL_BUILD)
44 // TRD : 64-bit Windows kernel with the Microsoft C compiler, any CPU
45 #include <assert.h>
46 #include <stdio.h>
47 #include <stdlib.h>
48 #include <wdm.h>
49 typedef unsigned __int64 atom_t;
50 #define INLINE extern __forceinline
51 #define ALIGN(alignment) __declspec( align(alignment) )
52 #define ALIGN_SINGLE_POINTER 8
53 #define ALIGN_DOUBLE_POINTER 16
54 #endif
56 #if (!defined _WIN64 && defined _WIN32 && defined _MSC_VER && defined WIN_KERNEL_BUILD)
57 // TRD : 32-bit Windows kernel with the Microsoft C compiler, any CPU
58 #include <assert.h>
59 #include <stdio.h>
60 #include <stdlib.h>
61 #include <wdm.h>
62 typedef unsigned long int atom_t;
63 #define INLINE extern __forceinline
64 #define ALIGN(alignment) __declspec( align(alignment) )
65 #define ALIGN_SINGLE_POINTER 4
66 #define ALIGN_DOUBLE_POINTER 8
68 // TRD : this define is documented but missing in Microsoft Platform SDK v7.0
69 #define _InterlockedCompareExchangePointer(destination, exchange, compare) _InterlockedCompareExchange((volatile long *) destination, (long) exchange, (long) compare)
70 #endif
72 #if (defined __unix__ && defined __x86_64__ && __GNUC__)
73 // TRD : any UNIX with GCC on x64
74 #define _XOPEN_SOURCE 600
75 #include <assert.h>
76 #include <stdio.h>
77 #include <stdlib.h>
78 typedef unsigned long long int atom_t;
79 #define INLINE inline
80 #define ALIGN(alignment) __attribute__( (aligned(alignment)) )
81 #define ALIGN_SINGLE_POINTER 8
82 #define ALIGN_DOUBLE_POINTER 16
83 #endif
85 #if (defined __unix__ && defined __i686__ && __GNUC__)
86 // TRD : any UNIX with GCC on x86
87 #define _XOPEN_SOURCE 600
88 #include <assert.h>
89 #include <stdio.h>
90 #include <stdlib.h>
91 typedef unsigned long int atom_t;
92 #define INLINE inline
93 #define ALIGN(alignment) __attribute__( (aligned(alignment)) )
94 #define ALIGN_SINGLE_POINTER 4
95 #define ALIGN_DOUBLE_POINTER 8
96 #endif
98 #if (defined __unix__ && defined __arm__ && __GNUC__)
99 // TRD : any UNIX with GCC on ARM
100 #define _XOPEN_SOURCE 600
101 #include <assert.h>
102 #include <stdio.h>
103 #include <stdlib.h>
104 typedef unsigned long int atom_t;
105 #define INLINE inline
106 #define ALIGN(alignment) __attribute__( (aligned(alignment)) )
107 #define ALIGN_SINGLE_POINTER 4
108 #define ALIGN_DOUBLE_POINTER 8
109 #endif
111 /***** enums *****/
112 enum data_structure_validity
113 {
114 VALIDITY_VALID,
115 VALIDITY_INVALID_LOOP,
116 VALIDITY_INVALID_MISSING_ELEMENTS,
117 VALIDITY_INVALID_ADDITIONAL_ELEMENTS,
118 VALIDITY_INVALID_TEST_DATA
119 };
121 /***** structs *****/
122 struct validation_info
123 {
124 atom_t
125 min_elements,
126 max_elements;
127 };
129 /***** public prototypes *****/
130 void abstraction_aligned_free( void *memory );
131 void *abstraction_aligned_malloc( size_t size, size_t align_in_bytes );
132 atom_t abstraction_cas( volatile atom_t *destination, atom_t exchange, atom_t compare );
133 unsigned char abstraction_dcas( volatile atom_t *destination, atom_t *exchange, atom_t *compare );
134 atom_t abstraction_increment( atom_t *value );
140 /***** freelist *****/
142 /***** enums *****/
143 enum freelist_query_type
144 {
145 FREELIST_QUERY_ELEMENT_COUNT,
146 FREELIST_QUERY_VALIDATE
147 };
149 /***** incomplete types *****/
150 struct freelist_state;
151 struct freelist_element;
153 /***** public prototypes *****/
154 int freelist_new( struct freelist_state **fs, atom_t number_elements, int (*user_data_init_function)(void **user_data, void *user_state), void *user_state );
155 void freelist_delete( struct freelist_state *fs, void (*user_data_delete_function)(void *user_data, void *user_state), void *user_state );
157 atom_t freelist_new_elements( struct freelist_state *fs, atom_t number_elements );
159 struct freelist_element *freelist_pop( struct freelist_state *fs, struct freelist_element **fe );
160 struct freelist_element *freelist_guaranteed_pop( struct freelist_state *fs, struct freelist_element **fe );
161 void freelist_push( struct freelist_state *fs, struct freelist_element *fe );
163 void *freelist_get_user_data_from_element( struct freelist_element *fe, void **user_data );
164 void freelist_set_user_data_in_element( struct freelist_element *fe, void *user_data );
166 void freelist_query( struct freelist_state *fs, enum freelist_query_type query_type, void *query_input, void *query_output );
172 /***** queue *****/
174 /***** enums *****/
175 enum queue_query_type
176 {
177 QUEUE_QUERY_ELEMENT_COUNT,
178 QUEUE_QUERY_VALIDATE
179 };
181 /***** incomplete types *****/
182 struct queue_state;
184 /***** public prototypes *****/
185 int queue_new( struct queue_state **sq, atom_t number_elements );
186 void queue_delete( struct queue_state *qs, void (*user_data_delete_function)(void *user_data, void *user_state), void *user_state );
188 int queue_enqueue( struct queue_state *qs, void *user_data );
189 int queue_guaranteed_enqueue( struct queue_state *qs, void *user_data );
190 int queue_dequeue( struct queue_state *qs, void **user_data );
192 void queue_query( struct queue_state *qs, enum queue_query_type query_type, void *query_input, void *query_output );
198 /***** ringbuffer *****/
200 /***** enums *****/
201 enum ringbuffer_query_type
202 {
203 RINGBUFFER_QUERY_VALIDATE
204 };
206 /***** incomplete types *****/
207 struct ringbuffer_state;
209 /***** public prototypes *****/
210 int ringbuffer_new( struct ringbuffer_state **rs, atom_t number_elements, int (*user_data_init_function)(void **user_data, void *user_state), void *user_state );
211 void ringbuffer_delete( struct ringbuffer_state *rs, void (*user_data_delete_function)(void *user_data, void *user_state), void *user_state );
213 struct freelist_element *ringbuffer_get_read_element( struct ringbuffer_state *rs, struct freelist_element **fe );
214 struct freelist_element *ringbuffer_get_write_element( struct ringbuffer_state *rs, struct freelist_element **fe, int *overwrite_flag );
216 void ringbuffer_put_read_element( struct ringbuffer_state *rs, struct freelist_element *fe );
217 void ringbuffer_put_write_element( struct ringbuffer_state *rs, struct freelist_element *fe );
219 void ringbuffer_query( struct ringbuffer_state *rs, enum ringbuffer_query_type query_type, void *query_input, void *query_output );
225 /***** slist *****/
227 /***** incomplete types *****/
228 struct slist_state;
229 struct slist_element;
231 /***** public prototypes *****/
232 int slist_new( struct slist_state **ss, void (*user_data_delete_function)(void *user_data, void *user_state), void *user_state );
233 void slist_delete( struct slist_state *ss );
235 struct slist_element *slist_new_head( struct slist_state *ss, void *user_data );
236 struct slist_element *slist_new_next( struct slist_element *se, void *user_data );
238 void slist_delete_element( struct slist_state *ss, struct slist_element *se );
239 void slist_delete_all_elements( struct slist_state *ss );
241 int slist_get_user_data_from_element( struct slist_element *se, void **user_data );
242 int slist_set_user_data_in_element( struct slist_element *se, void *user_data );
244 struct slist_element *slist_get_head( struct slist_state *ss, struct slist_element **se );
245 struct slist_element *slist_get_next( struct slist_element *se, struct slist_element **next_se );
246 struct slist_element *slist_get_head_and_then_next( struct slist_state *ss, struct slist_element **se );
252 /***** stack *****/
254 /***** enums *****/
255 enum stack_query_type
256 {
257 STACK_QUERY_ELEMENT_COUNT
258 };
260 /***** incomplete types *****/
261 struct stack_state;
263 /***** public prototypes *****/
264 int stack_new( struct stack_state **ss, atom_t number_elements );
265 void stack_delete( struct stack_state *ss, void (*user_data_delete_function)(void *user_data, void *user_state), void *user_state );
267 void stack_clear( struct stack_state *ss, void (*user_data_clear_function)(void *user_data, void *user_state), void *user_state );
269 int stack_push( struct stack_state *ss, void *user_data );
270 int stack_guaranteed_push( struct stack_state *ss, void *user_data );
271 int stack_pop( struct stack_state *ss, void **user_data );
273 void stack_query( struct stack_state *ss, enum stack_query_type query_type, void *query_input, void *query_output );
279 #define __LIBLFDS_H
281 #endif