win-pvdrivers

diff 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
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/liblfds.6/src/single_dir_for_windows_kernel/stack_new.c	Sun Jan 31 21:28:42 2010 +1100
     1.3 @@ -0,0 +1,139 @@
     1.4 +#include "stack_internal.h"
     1.5 +
     1.6 +
     1.7 +
     1.8 +
     1.9 +
    1.10 +/****************************************************************************/
    1.11 +int stack_new( struct stack_state **ss, atom_t number_elements )
    1.12 +{
    1.13 +  int
    1.14 +    rv = 0;
    1.15 +
    1.16 +  assert( ss != NULL );
    1.17 +  // TRD : number_elements can be any value in its range
    1.18 +
    1.19 +  *ss = (struct stack_state *) abstraction_aligned_malloc( sizeof(struct stack_state), ALIGN_DOUBLE_POINTER );
    1.20 +
    1.21 +  if( *ss != NULL )
    1.22 +  {
    1.23 +    // TRD : the size of the freelist is the size of the stack
    1.24 +    freelist_new( &(*ss)->fs, number_elements, stack_internal_freelist_init_function, NULL );
    1.25 +
    1.26 +    if( (*ss)->fs == NULL )
    1.27 +    {
    1.28 +      abstraction_aligned_free( *ss );
    1.29 +      *ss = NULL;
    1.30 +    }
    1.31 +
    1.32 +    if( (*ss)->fs != NULL )
    1.33 +    {
    1.34 +      (*ss)->top[STACK_POINTER] = NULL;
    1.35 +      (*ss)->top[STACK_COUNTER] = 0;
    1.36 +      (*ss)->aba_counter = 0;
    1.37 +      rv = 1;
    1.38 +    }
    1.39 +  }
    1.40 +
    1.41 +  return( rv );
    1.42 +}
    1.43 +
    1.44 +
    1.45 +
    1.46 +
    1.47 +
    1.48 +/****************************************************************************/
    1.49 +#pragma warning( disable : 4100 )
    1.50 +
    1.51 +int stack_internal_freelist_init_function( void **user_data, void *user_state )
    1.52 +{
    1.53 +  int
    1.54 +    rv = 0;
    1.55 +
    1.56 +  assert( user_data != NULL );
    1.57 +  assert( user_state == NULL );
    1.58 +
    1.59 +  *user_data = abstraction_aligned_malloc( sizeof(struct stack_element), ALIGN_DOUBLE_POINTER );
    1.60 +
    1.61 +  if( *user_data != NULL )
    1.62 +    rv = 1;
    1.63 +
    1.64 +  return( rv );
    1.65 +}
    1.66 +
    1.67 +#pragma warning( default : 4100 )
    1.68 +
    1.69 +
    1.70 +
    1.71 +
    1.72 +
    1.73 +/****************************************************************************/
    1.74 +void stack_internal_new_element_from_freelist( struct stack_state *ss, struct stack_element *se[STACK_PAC_SIZE], void *user_data )
    1.75 +{
    1.76 +  struct freelist_element
    1.77 +    *fe;
    1.78 +
    1.79 +  assert( ss != NULL );
    1.80 +  assert( se != NULL );
    1.81 +  // TRD : user_data can be any value in its range
    1.82 +
    1.83 +  freelist_pop( ss->fs, &fe );
    1.84 +
    1.85 +  if( fe == NULL )
    1.86 +    se[STACK_POINTER] = NULL;
    1.87 +
    1.88 +  if( fe != NULL )
    1.89 +    stack_internal_init_element( ss, se, fe, user_data );
    1.90 +
    1.91 +  return;
    1.92 +}
    1.93 +
    1.94 +
    1.95 +
    1.96 +
    1.97 +
    1.98 +/****************************************************************************/
    1.99 +void stack_internal_new_element( struct stack_state *ss, struct stack_element *se[STACK_PAC_SIZE], void *user_data )
   1.100 +{
   1.101 +  struct freelist_element
   1.102 +    *fe;
   1.103 +
   1.104 +  assert( ss != NULL );
   1.105 +  assert( se != NULL );
   1.106 +  // TRD : user_data can be any value in its range
   1.107 +
   1.108 +  freelist_guaranteed_pop( ss->fs, &fe );
   1.109 +
   1.110 +  if( fe == NULL )
   1.111 +    se[STACK_POINTER] = NULL;
   1.112 +
   1.113 +  if( fe != NULL )
   1.114 +    stack_internal_init_element( ss, se, fe, user_data );
   1.115 +
   1.116 +  return;
   1.117 +}
   1.118 +
   1.119 +
   1.120 +
   1.121 +
   1.122 +
   1.123 +/****************************************************************************/
   1.124 +void stack_internal_init_element( struct stack_state *ss, struct stack_element *se[STACK_PAC_SIZE], struct freelist_element *fe, void *user_data )
   1.125 +{
   1.126 +  assert( ss != NULL );
   1.127 +  assert( se != NULL );
   1.128 +  assert( fe != NULL );
   1.129 +  // TRD : user_data can be any value in its range
   1.130 +
   1.131 +  freelist_get_user_data_from_element( fe, (void **) &se[STACK_POINTER] );
   1.132 +
   1.133 +  se[STACK_COUNTER] = (struct stack_element *) abstraction_increment( (atom_t *) &ss->aba_counter );
   1.134 +
   1.135 +  se[STACK_POINTER]->next[STACK_POINTER] = NULL;
   1.136 +  se[STACK_POINTER]->next[STACK_COUNTER] = 0;
   1.137 +  se[STACK_POINTER]->fe = fe;
   1.138 +  se[STACK_POINTER]->user_data = user_data;
   1.139 +
   1.140 +  return;
   1.141 +}
   1.142 +