Source code of Windows XP (NT5)
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.

137 lines
2.9 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: NewDevice
  69. *
  70. * Synopsis: allocates an IR device and zeros the memory
  71. *
  72. * Arguments: none
  73. *
  74. * Returns: initialized IR device or NULL (if alloc failed)
  75. *
  76. *
  77. *****************************************************************************/
  78. PIR_DEVICE
  79. NewDevice()
  80. {
  81. PIR_DEVICE pNewDev;
  82. pNewDev = MyMemAlloc( sizeof(IR_DEVICE) );
  83. if( pNewDev != NULL )
  84. {
  85. NdisZeroMemory( (PVOID)pNewDev, sizeof(IR_DEVICE) );
  86. if( !AllocUsbInfo( pNewDev ) )
  87. {
  88. MyMemFree( pNewDev, sizeof(IR_DEVICE) );
  89. pNewDev = NULL;
  90. }
  91. }
  92. return pNewDev;
  93. }
  94. /*****************************************************************************
  95. *
  96. * Function: FreeDevice
  97. *
  98. * Synopsis: frees an IR device structure
  99. *
  100. * Arguments: pThisDev - pointer to device to free
  101. *
  102. * Returns: none
  103. *
  104. *
  105. *****************************************************************************/
  106. VOID
  107. FreeDevice(
  108. IN OUT PIR_DEVICE pThisDev
  109. )
  110. {
  111. FreeUsbInfo( pThisDev );
  112. MyMemFree( (PVOID)pThisDev, sizeof(IR_DEVICE) );
  113. }