mem.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * TAP-Windows -- A kernel driver to provide virtual tap
  3. * device functionality on Windows.
  4. *
  5. * This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
  6. *
  7. * This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc.,
  8. * and is released under the GPL version 2 (see below).
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program (see the file COPYING included with this
  21. * distribution); if not, write to the Free Software Foundation, Inc.,
  22. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. //------------------
  25. // Memory Management
  26. //------------------
  27. PVOID
  28. MemAlloc(
  29. __in ULONG p_Size,
  30. __in BOOLEAN zero
  31. );
  32. VOID
  33. MemFree(
  34. __in PVOID p_Addr,
  35. __in ULONG p_Size
  36. );
  37. //======================================================================
  38. // TAP Packet Queue
  39. //======================================================================
  40. typedef
  41. struct _TAP_PACKET
  42. {
  43. LIST_ENTRY QueueLink;
  44. # define TAP_PACKET_SIZE(data_size) (sizeof (TAP_PACKET) + (data_size))
  45. # define TP_TUN 0x80000000
  46. # define TP_SIZE_MASK (~TP_TUN)
  47. ULONG m_SizeFlags;
  48. // m_Data must be the last struct member
  49. UCHAR m_Data [];
  50. } TAP_PACKET, *PTAP_PACKET;
  51. #define TAP_PACKET_TAG '6PAT' // "TAP6"
  52. typedef struct _TAP_PACKET_QUEUE
  53. {
  54. KSPIN_LOCK QueueLock;
  55. LIST_ENTRY Queue;
  56. ULONG Count; // Count of currently queued items
  57. ULONG MaxCount;
  58. } TAP_PACKET_QUEUE, *PTAP_PACKET_QUEUE;
  59. VOID
  60. tapPacketQueueInsertTail(
  61. __in PTAP_PACKET_QUEUE TapPacketQueue,
  62. __in PTAP_PACKET TapPacket
  63. );
  64. // Call with QueueLock held
  65. PTAP_PACKET
  66. tapPacketRemoveHeadLocked(
  67. __in PTAP_PACKET_QUEUE TapPacketQueue
  68. );
  69. PTAP_PACKET
  70. tapPacketRemoveHead(
  71. __in PTAP_PACKET_QUEUE TapPacketQueue
  72. );
  73. VOID
  74. tapPacketQueueInitialize(
  75. __in PTAP_PACKET_QUEUE TapPacketQueue
  76. );
  77. //----------------------
  78. // Cancel-Safe IRP Queue
  79. //----------------------
  80. typedef struct _TAP_IRP_CSQ
  81. {
  82. IO_CSQ CsqQueue;
  83. KSPIN_LOCK QueueLock;
  84. LIST_ENTRY Queue;
  85. ULONG Count; // Count of currently queued items
  86. ULONG MaxCount;
  87. } TAP_IRP_CSQ, *PTAP_IRP_CSQ;
  88. VOID
  89. tapIrpCsqInitialize(
  90. __in PTAP_IRP_CSQ TapIrpCsq
  91. );
  92. VOID
  93. tapIrpCsqFlush(
  94. __in PTAP_IRP_CSQ TapIrpCsq
  95. );