win-pvdrivers

annotate liblfds.6/src/single_dir_for_windows_kernel/stack_new.c @ 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
rev   line source
james@766 1 #include "stack_internal.h"
james@766 2
james@766 3
james@766 4
james@766 5
james@766 6
james@766 7 /****************************************************************************/
james@766 8 int stack_new( struct stack_state **ss, atom_t number_elements )
james@766 9 {
james@766 10 int
james@766 11 rv = 0;
james@766 12
james@766 13 assert( ss != NULL );
james@766 14 // TRD : number_elements can be any value in its range
james@766 15
james@766 16 *ss = (struct stack_state *) abstraction_aligned_malloc( sizeof(struct stack_state), ALIGN_DOUBLE_POINTER );
james@766 17
james@766 18 if( *ss != NULL )
james@766 19 {
james@766 20 // TRD : the size of the freelist is the size of the stack
james@766 21 freelist_new( &(*ss)->fs, number_elements, stack_internal_freelist_init_function, NULL );
james@766 22
james@766 23 if( (*ss)->fs == NULL )
james@766 24 {
james@766 25 abstraction_aligned_free( *ss );
james@766 26 *ss = NULL;
james@766 27 }
james@766 28
james@766 29 if( (*ss)->fs != NULL )
james@766 30 {
james@766 31 (*ss)->top[STACK_POINTER] = NULL;
james@766 32 (*ss)->top[STACK_COUNTER] = 0;
james@766 33 (*ss)->aba_counter = 0;
james@766 34 rv = 1;
james@766 35 }
james@766 36 }
james@766 37
james@766 38 return( rv );
james@766 39 }
james@766 40
james@766 41
james@766 42
james@766 43
james@766 44
james@766 45 /****************************************************************************/
james@766 46 #pragma warning( disable : 4100 )
james@766 47
james@766 48 int stack_internal_freelist_init_function( void **user_data, void *user_state )
james@766 49 {
james@766 50 int
james@766 51 rv = 0;
james@766 52
james@766 53 assert( user_data != NULL );
james@766 54 assert( user_state == NULL );
james@766 55
james@766 56 *user_data = abstraction_aligned_malloc( sizeof(struct stack_element), ALIGN_DOUBLE_POINTER );
james@766 57
james@766 58 if( *user_data != NULL )
james@766 59 rv = 1;
james@766 60
james@766 61 return( rv );
james@766 62 }
james@766 63
james@766 64 #pragma warning( default : 4100 )
james@766 65
james@766 66
james@766 67
james@766 68
james@766 69
james@766 70 /****************************************************************************/
james@766 71 void stack_internal_new_element_from_freelist( struct stack_state *ss, struct stack_element *se[STACK_PAC_SIZE], void *user_data )
james@766 72 {
james@766 73 struct freelist_element
james@766 74 *fe;
james@766 75
james@766 76 assert( ss != NULL );
james@766 77 assert( se != NULL );
james@766 78 // TRD : user_data can be any value in its range
james@766 79
james@766 80 freelist_pop( ss->fs, &fe );
james@766 81
james@766 82 if( fe == NULL )
james@766 83 se[STACK_POINTER] = NULL;
james@766 84
james@766 85 if( fe != NULL )
james@766 86 stack_internal_init_element( ss, se, fe, user_data );
james@766 87
james@766 88 return;
james@766 89 }
james@766 90
james@766 91
james@766 92
james@766 93
james@766 94
james@766 95 /****************************************************************************/
james@766 96 void stack_internal_new_element( struct stack_state *ss, struct stack_element *se[STACK_PAC_SIZE], void *user_data )
james@766 97 {
james@766 98 struct freelist_element
james@766 99 *fe;
james@766 100
james@766 101 assert( ss != NULL );
james@766 102 assert( se != NULL );
james@766 103 // TRD : user_data can be any value in its range
james@766 104
james@766 105 freelist_guaranteed_pop( ss->fs, &fe );
james@766 106
james@766 107 if( fe == NULL )
james@766 108 se[STACK_POINTER] = NULL;
james@766 109
james@766 110 if( fe != NULL )
james@766 111 stack_internal_init_element( ss, se, fe, user_data );
james@766 112
james@766 113 return;
james@766 114 }
james@766 115
james@766 116
james@766 117
james@766 118
james@766 119
james@766 120 /****************************************************************************/
james@766 121 void stack_internal_init_element( struct stack_state *ss, struct stack_element *se[STACK_PAC_SIZE], struct freelist_element *fe, void *user_data )
james@766 122 {
james@766 123 assert( ss != NULL );
james@766 124 assert( se != NULL );
james@766 125 assert( fe != NULL );
james@766 126 // TRD : user_data can be any value in its range
james@766 127
james@766 128 freelist_get_user_data_from_element( fe, (void **) &se[STACK_POINTER] );
james@766 129
james@766 130 se[STACK_COUNTER] = (struct stack_element *) abstraction_increment( (atom_t *) &ss->aba_counter );
james@766 131
james@766 132 se[STACK_POINTER]->next[STACK_POINTER] = NULL;
james@766 133 se[STACK_POINTER]->next[STACK_COUNTER] = 0;
james@766 134 se[STACK_POINTER]->fe = fe;
james@766 135 se[STACK_POINTER]->user_data = user_data;
james@766 136
james@766 137 return;
james@766 138 }
james@766 139