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
3.1 KiB

  1. #ifndef _UTIL_H_
  2. #define _UTIL_H_
  3. typedef enum
  4. _WORKSTATE
  5. {
  6. WS_NotScheduled = 0,
  7. WS_Scheduled,
  8. WS_Executing,
  9. WS_Executed
  10. }
  11. WORKSTATE;
  12. typedef
  13. VOID
  14. (*WORKITEM_EXEC_ROUTINE)(
  15. IN PVOID Args[4],
  16. UINT workType
  17. );
  18. typedef
  19. VOID
  20. (*WORKITEM_FREE_ROUTINE)(
  21. IN PVOID Args[4],
  22. IN UINT workType
  23. );
  24. typedef struct
  25. _WORKITEM
  26. {
  27. //
  28. // Indicates the state of the work item
  29. //
  30. WORKSTATE workState;
  31. //
  32. // Indicates the type of work to be done
  33. //
  34. UINT workType;
  35. //
  36. // Points to the lookaside list the item was allocated from
  37. //
  38. PNPAGED_LOOKASIDE_LIST pLookaside;
  39. //
  40. // Context to be passed to scheduled item
  41. //
  42. PVOID Args[4];
  43. //
  44. // Routine to be called to execute the work item
  45. //
  46. WORKITEM_EXEC_ROUTINE pExecRoutine;
  47. //
  48. // Routine to be called to free the context for the work item
  49. //
  50. WORKITEM_FREE_ROUTINE pFreeRoutine;
  51. //
  52. // Associated NdisWorkItem
  53. //
  54. NDIS_WORK_ITEM ndisWorkItem;
  55. }
  56. WORKITEM;
  57. VOID InitializeWorkItemLookasideList(
  58. IN PNPAGED_LOOKASIDE_LIST pLookaside,
  59. IN ULONG tagLookaside
  60. );
  61. WORKITEM* AllocWorkItem(
  62. IN PNPAGED_LOOKASIDE_LIST pLookaside,
  63. IN WORKITEM_EXEC_ROUTINE pExecRoutine,
  64. IN WORKITEM_FREE_ROUTINE pFreeRoutine,
  65. IN PVOID Args[4],
  66. IN UINT workType
  67. );
  68. VOID ScheduleWorkItem(
  69. IN WORKITEM *pWorkItem
  70. );
  71. VOID FreeWorkItem(
  72. IN WORKITEM *pWorkItem
  73. );
  74. VOID WorkItemExec(
  75. IN NDIS_WORK_ITEM* pNdisWorkItem,
  76. IN PVOID pvContext
  77. );
  78. typedef struct
  79. _HANDLE_CB
  80. {
  81. //
  82. // Indicates that the entry contains a valid context pointer
  83. //
  84. BOOLEAN fActive;
  85. //
  86. // Pointer to the context saved in this entry
  87. //
  88. PVOID pContext;
  89. //
  90. // Handle value to access this particular entry
  91. //
  92. NDIS_HANDLE Handle;
  93. }
  94. HANDLE_CB;
  95. typedef struct
  96. _HANDLE_TABLE_CB
  97. {
  98. //
  99. // Points to the table that holds the Handle control blocks.
  100. //
  101. HANDLE_CB* HandleTable;
  102. //
  103. // Size of the handle table
  104. //
  105. UINT nTableSize;
  106. //
  107. // Shows the number of active handles
  108. //
  109. UINT nActiveHandles;
  110. //
  111. // Keeps the unique part of the handle.
  112. // This is incremented everytime a handle is generated and a context is inserted
  113. // into the handle table.
  114. //
  115. USHORT usKeys;
  116. }
  117. HANDLE_TABLE_CB, *PHANDLE_TABLE_CB, *HANDLE_TABLE;
  118. #define NO_PREFERED_INDEX (USHORT) -1
  119. HANDLE_TABLE InitializeHandleTable(
  120. IN UINT nHandleTableSize
  121. );
  122. VOID FreeHandleTable(
  123. IN OUT HANDLE_TABLE Table
  124. );
  125. NDIS_HANDLE InsertToHandleTable(
  126. IN HANDLE_TABLE Table,
  127. IN USHORT usPreferedIndex,
  128. IN PVOID pContext
  129. );
  130. PVOID RetrieveFromHandleTable(
  131. IN HANDLE_TABLE Table,
  132. IN NDIS_HANDLE Handle
  133. );
  134. USHORT RetrieveIndexFromHandle(
  135. IN NDIS_HANDLE Handle
  136. );
  137. PVOID RetrieveFromHandleTableByIndex(
  138. IN HANDLE_TABLE Table,
  139. IN USHORT usIndex
  140. );
  141. PVOID RetrieveFromHandleTableBySessionId(
  142. IN HANDLE_TABLE Table,
  143. IN USHORT usSessionId
  144. );
  145. VOID RemoveFromHandleTable(
  146. IN HANDLE_TABLE Table,
  147. IN NDIS_HANDLE Handle
  148. );
  149. USHORT RetrieveSessionIdFromHandle(
  150. IN NDIS_HANDLE Handle
  151. );
  152. #endif