First public contribution.
2 * Copyright (c) 2001 - 2005 NetGroup, Politecnico di Torino (Italy)
3 * Copyright (c) 2005 - 2006 CACE Technologies, Davis (California)
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the Politecnico di Torino, CACE Technologies
16 * nor the names of its contributors may be used to endorse or promote
17 * products derived from this software without specific prior written
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 #define uint64 ULONGLONG
44 #define int64 LONGLONG
47 typedef struct __MEM_TYPE
51 } MEM_TYPE, *PMEM_TYPE;
53 #define LONG_AT(base,offset) (*(int32*)((uint8*)base+(uint32)offset))
55 #define ULONG_AT(base,offset) (*(uint32*)((uint8*)base+(uint32)offset))
57 #define SHORT_AT(base,offset) (*(int16*)((uint8*)base+(uint32)offset))
59 #define USHORT_AT(base,offset) (*(uint16*)((uint8*)base+(uint32)offset))
61 __inline int32 SW_LONG_AT(void *b, uint32 c)
63 return ((int32)*((uint8 *)b+c)<<24|
64 (int32)*((uint8 *)b+c+1)<<16|
65 (int32)*((uint8 *)b+c+2)<<8|
66 (int32)*((uint8 *)b+c+3)<<0);
70 __inline uint32 SW_ULONG_AT(void *b, uint32 c)
72 return ((uint32)*((uint8 *)b+c)<<24|
73 (uint32)*((uint8 *)b+c+1)<<16|
74 (uint32)*((uint8 *)b+c+2)<<8|
75 (uint32)*((uint8 *)b+c+3)<<0);
78 __inline int16 SW_SHORT_AT(void *b, uint32 os)
81 ((int16)*((uint8 *)b+os+0)<<8|
82 (int16)*((uint8 *)b+os+1)<<0));
85 __inline uint16 SW_USHORT_AT(void *b, uint32 os)
88 ((uint16)*((uint8 *)b+os+0)<<8|
89 (uint16)*((uint8 *)b+os+1)<<0));
92 __inline VOID SW_ULONG_ASSIGN(void *dst, uint32 src)
94 *((uint8*)dst+0)=*((uint8*)&src+3);
95 *((uint8*)dst+1)=*((uint8*)&src+2);
96 *((uint8*)dst+2)=*((uint8*)&src+1);
97 *((uint8*)dst+3)=*((uint8*)&src+0);
103 #define ALLOCATE_MEMORY(dest,type,amount) \
104 (dest)=ExAllocatePoolWithTag(NonPagedPool,sizeof(type)*(amount), '0TWA');
105 #define ALLOCATE_ZERO_MEMORY(dest,type,amount) \
107 (dest)=ExAllocatePoolWithTag(NonPagedPool,sizeof(type)*(amount), '1TWA'); \
109 RtlZeroMemory((dest),sizeof(type)*(amount)); \
112 #define FREE_MEMORY(dest) ExFreePool(dest);
113 #define ZERO_MEMORY(dest,amount) RtlZeroMemory(dest,amount);
114 #define COPY_MEMORY(dest,src,amount) RtlCopyMemory(dest,src,amount);
118 #define ALLOCATE_MEMORY(dest,type,amount) \
119 (dest)=(type*)GlobalAlloc(GPTR, sizeof(type)*(amount));
120 #define ALLOCATE_ZERO_MEMORY(dest,type,amount) \
121 (dest)=(type*)GlobalAlloc(GPTR, sizeof(type)*(amount));
123 #define FREE_MEMORY(dest) GlobalFree(dest);
124 #define ZERO_MEMORY(dest,amount) RtlZeroMemory(dest,amount);
125 #define COPY_MEMORY(dest,src,amount) RtlCopyMemory(dest,src,amount);
128 #endif /*WIN_NT_DRIVER*/