summaryrefslogtreecommitdiff
path: root/windows/TapDriver6/mem.h
blob: a8359e192f2e06a1f11934176671414caac53dfe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 *  TAP-Windows -- A kernel driver to provide virtual tap
 *                 device functionality on Windows.
 *
 *  This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
 *
 *  This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc.,
 *  and is released under the GPL version 2 (see below).
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2
 *  as published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program (see the file COPYING included with this
 *  distribution); if not, write to the Free Software Foundation, Inc.,
 *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

//------------------
// Memory Management
//------------------

PVOID
MemAlloc(
    __in ULONG p_Size,
    __in BOOLEAN zero
    );

VOID
MemFree(
    __in PVOID p_Addr,
    __in ULONG p_Size
    );

//======================================================================
// TAP Packet Queue
//======================================================================

typedef
struct _TAP_PACKET
{
    LIST_ENTRY                  QueueLink;

#   define TAP_PACKET_SIZE(data_size) (sizeof (TAP_PACKET) + (data_size))
#   define TP_TUN 0x80000000
#   define TP_SIZE_MASK      (~TP_TUN)
    ULONG                       m_SizeFlags;

    // m_Data must be the last struct member
    UCHAR                       m_Data [];
} TAP_PACKET, *PTAP_PACKET;

#define TAP_PACKET_TAG      '6PAT'  // "TAP6"

typedef struct _TAP_PACKET_QUEUE
{
    KSPIN_LOCK      QueueLock;
    LIST_ENTRY      Queue;
    ULONG           Count;   // Count of currently queued items
    ULONG           MaxCount;
} TAP_PACKET_QUEUE, *PTAP_PACKET_QUEUE;

VOID
tapPacketQueueInsertTail(
    __in PTAP_PACKET_QUEUE  TapPacketQueue,
    __in PTAP_PACKET        TapPacket
    );


// Call with QueueLock held
PTAP_PACKET
tapPacketRemoveHeadLocked(
    __in PTAP_PACKET_QUEUE  TapPacketQueue
    );

PTAP_PACKET
tapPacketRemoveHead(
    __in PTAP_PACKET_QUEUE  TapPacketQueue
    );

VOID
tapPacketQueueInitialize(
    __in PTAP_PACKET_QUEUE  TapPacketQueue
    );

//----------------------
// Cancel-Safe IRP Queue
//----------------------

typedef struct _TAP_IRP_CSQ
{
    IO_CSQ          CsqQueue;
    KSPIN_LOCK      QueueLock;
    LIST_ENTRY      Queue;
    ULONG           Count;   // Count of currently queued items
    ULONG           MaxCount;
} TAP_IRP_CSQ, *PTAP_IRP_CSQ;

VOID
tapIrpCsqInitialize(
    __in PTAP_IRP_CSQ  TapIrpCsq
    );

VOID
tapIrpCsqFlush(
    __in PTAP_IRP_CSQ  TapIrpCsq
    );