Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

188 lines
4.0 KiB

  1. /**************************************************************************************************************************
  2. * RESOURCE.C SigmaTel STIR4200 memory allocation module
  3. **************************************************************************************************************************
  4. * (C) Unpublished Copyright of Sigmatel, Inc. All Rights Reserved.
  5. *
  6. *
  7. * Created: 04/06/2000
  8. * Version 0.9
  9. *
  10. *
  11. **************************************************************************************************************************/
  12. #define DOBREAKS // enable debug breaks
  13. #include <ndis.h>
  14. #include <ntddndis.h> // defines OID's
  15. #include <usbdi.h>
  16. #include <usbdlib.h>
  17. #include "debug.h"
  18. #include "ircommon.h"
  19. #include "irndis.h"
  20. /*****************************************************************************
  21. *
  22. * Function: MyMemAlloc
  23. *
  24. * Synopsis: allocates a block of memory using NdisAllocateMemory
  25. *
  26. * Arguments: size - size of the block to allocate
  27. *
  28. * Returns: a pointer to the allocated block of memory
  29. *
  30. *
  31. *****************************************************************************/
  32. PVOID
  33. MyMemAlloc(
  34. UINT size
  35. )
  36. {
  37. PVOID pMem;
  38. NDIS_STATUS status;
  39. status = NdisAllocateMemoryWithTag( &pMem, size, IRUSB_TAG );
  40. if( status != NDIS_STATUS_SUCCESS )
  41. {
  42. DEBUGMSG(DBG_ERR, (" Memory allocation failed\n"));
  43. pMem = NULL;
  44. }
  45. return pMem;
  46. }
  47. /*****************************************************************************
  48. *
  49. * Function: MyMemFree
  50. *
  51. * Synopsis: frees a block of memory allocated by MyMemAlloc
  52. *
  53. * Arguments: memptr - memory to free
  54. * size - size of the block to free
  55. *
  56. *
  57. *****************************************************************************/
  58. VOID
  59. MyMemFree(
  60. PVOID pMem,
  61. UINT size
  62. )
  63. {
  64. NdisFreeMemory( pMem, size, 0 );
  65. }
  66. /*****************************************************************************
  67. *
  68. * Function: MyUrbAlloc
  69. *
  70. * Synopsis: allocates an URB using NdisAllocateMemory
  71. *
  72. * Arguments: size - size of urb to allocate
  73. *
  74. * Returns: a pointer to the urb
  75. *
  76. *****************************************************************************/
  77. PURB
  78. MyUrbAlloc(
  79. UINT size
  80. )
  81. {
  82. PURB pUrb = NULL;
  83. pUrb = MyMemAlloc( size );
  84. if( NULL == pUrb )
  85. {
  86. DEBUGMSG(DBG_ERR, (" IrUsb failed to alloc urb\n"));
  87. }
  88. else
  89. {
  90. NdisZeroMemory( pUrb, size );
  91. }
  92. return pUrb;
  93. }
  94. /*****************************************************************************
  95. *
  96. * Function: MyUrbFree
  97. *
  98. * Synopsis: frees an Urb allocated by MyUrbAlloc
  99. *
  100. * Arguments: pUrb - urb to free
  101. * size - size of the urb to free
  102. *
  103. *
  104. *****************************************************************************/
  105. VOID
  106. MyUrbFree(
  107. PURB pUrb,
  108. UINT size
  109. )
  110. {
  111. MyMemFree(pUrb, size);
  112. }
  113. /*****************************************************************************
  114. *
  115. * Function: NewDevice
  116. *
  117. * Synopsis: allocates an IR device and zeros the memory
  118. *
  119. * Arguments: none
  120. *
  121. * Returns: initialized IR device or NULL (if alloc failed)
  122. *
  123. *
  124. *****************************************************************************/
  125. PIR_DEVICE
  126. NewDevice()
  127. {
  128. PIR_DEVICE pNewDev;
  129. pNewDev = MyMemAlloc( sizeof(IR_DEVICE) );
  130. if( pNewDev != NULL )
  131. {
  132. NdisZeroMemory( (PVOID)pNewDev, sizeof(IR_DEVICE) );
  133. if( !AllocUsbInfo( pNewDev ) )
  134. {
  135. MyMemFree( pNewDev, sizeof(IR_DEVICE) );
  136. pNewDev = NULL;
  137. }
  138. }
  139. return pNewDev;
  140. }
  141. /*****************************************************************************
  142. *
  143. * Function: FreeDevice
  144. *
  145. * Synopsis: frees an IR device structure
  146. *
  147. * Arguments: pThisDev - pointer to device to free
  148. *
  149. * Returns: none
  150. *
  151. *
  152. *****************************************************************************/
  153. VOID
  154. FreeDevice(
  155. IN OUT PIR_DEVICE pThisDev
  156. )
  157. {
  158. FreeUsbInfo( pThisDev );
  159. MyMemFree( (PVOID)pThisDev, sizeof(IR_DEVICE) );
  160. }