Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

memory_t.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001 - 2003
00003  * NetGroup, Politecnico di Torino (Italy)
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  *
00010  * 1. Redistributions of source code must retain the above copyright
00011  * notice, this list of conditions and the following disclaimer.
00012  * 2. Redistributions in binary form must reproduce the above copyright
00013  * notice, this list of conditions and the following disclaimer in the
00014  * documentation and/or other materials provided with the distribution.
00015  * 3. Neither the name of the Politecnico di Torino nor the names of its
00016  * contributors may be used to endorse or promote products derived from
00017  * this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00020  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00021  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00022  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00023  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00024  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00025  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00026  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00027  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00028  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00029  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030  *
00031  */
00032 
00033 #ifndef __memory_t
00034 #define __memory_t
00035 
00036 #define         uint8   UCHAR
00037 #define         int8    CHAR
00038 #define         uint16  USHORT
00039 #define         int16   SHORT
00040 #define         uint32  ULONG
00041 #define         int32   LONG
00042 #define         uint64  ULONGLONG
00043 #define         int64   LONGLONG
00044 
00045 /*memory type*/
00046 typedef struct __MEM_TYPE
00047 {
00048         uint8 *buffer;
00049         uint32 size;
00050 }  MEM_TYPE, *PMEM_TYPE;
00051 
00052 #define LONG_AT(base,offset) (*(int32*)((uint8*)base+(uint32)offset))
00053 
00054 #define ULONG_AT(base,offset) (*(uint32*)((uint8*)base+(uint32)offset))
00055 
00056 #define SHORT_AT(base,offset) (*(int16*)((uint8*)base+(uint32)offset))
00057 
00058 #define USHORT_AT(base,offset) (*(uint16*)((uint8*)base+(uint32)offset))
00059 
00060 __inline int32 SW_LONG_AT(void *b, uint32 c)
00061 {
00062         return  ((int32)*((uint8 *)b+c)<<24|
00063                  (int32)*((uint8 *)b+c+1)<<16|
00064                  (int32)*((uint8 *)b+c+2)<<8|
00065                  (int32)*((uint8 *)b+c+3)<<0);
00066 }
00067 
00068 
00069 __inline uint32 SW_ULONG_AT(void *b, uint32 c)
00070 {
00071         return  ((uint32)*((uint8 *)b+c)<<24|
00072                  (uint32)*((uint8 *)b+c+1)<<16|
00073                  (uint32)*((uint8 *)b+c+2)<<8|
00074                  (uint32)*((uint8 *)b+c+3)<<0);
00075 }
00076 
00077 __inline int16 SW_SHORT_AT(void *b, uint32 os)
00078 {
00079         return ((int16)
00080                 ((int16)*((uint8 *)b+os+0)<<8|
00081                  (int16)*((uint8 *)b+os+1)<<0));
00082 }
00083 
00084 __inline uint16 SW_USHORT_AT(void *b, uint32 os)
00085 {
00086         return ((uint16)
00087                 ((uint16)*((uint8 *)b+os+0)<<8|
00088                  (uint16)*((uint8 *)b+os+1)<<0));
00089 }
00090 
00091 __inline VOID SW_ULONG_ASSIGN(void *dst, uint32 src)
00092 {
00093         *((uint8*)dst+0)=*((uint8*)&src+3);
00094         *((uint8*)dst+1)=*((uint8*)&src+2);
00095         *((uint8*)dst+2)=*((uint8*)&src+1);
00096         *((uint8*)dst+3)=*((uint8*)&src+0);
00097 
00098 }
00099 
00100 #ifdef WIN_NT_DRIVER
00101 
00102 #define ALLOCATE_MEMORY(dest,type,amount) \
00103           (dest)=ExAllocatePool(NonPagedPool,sizeof(type)*(amount));
00104 #define ALLOCATE_ZERO_MEMORY(dest,type,amount) \
00105         { \
00106                 (dest)=ExAllocatePool(NonPagedPool,sizeof(type)*(amount)); \
00107                 if ((dest)!=NULL) \
00108                         RtlZeroMemory((dest),sizeof(type)*(amount)); \
00109         }       
00110 
00111 #define FREE_MEMORY(dest) ExFreePool(dest);
00112 #define ZERO_MEMORY(dest,amount) RtlZeroMemory(dest,amount);
00113 #define COPY_MEMORY(dest,src,amount) RtlCopyMemory(dest,src,amount);
00114 
00115 #else
00116 
00117 #define ALLOCATE_MEMORY(dest,type,amount) \
00118           (dest)=(type*)GlobalAlloc(GPTR, sizeof(type)*(amount));
00119 #define ALLOCATE_ZERO_MEMORY(dest,type,amount) \
00120           (dest)=(type*)GlobalAlloc(GPTR, sizeof(type)*(amount));
00121 
00122 #define FREE_MEMORY(dest) GlobalFree(dest);
00123 #define ZERO_MEMORY(dest,amount) RtlZeroMemory(dest,amount);
00124 #define COPY_MEMORY(dest,src,amount) RtlCopyMemory(dest,src,amount);
00125 
00126 
00127 #endif /*WIN_NT_DRIVER*/
00128 
00129 
00130 
00131 #endif 
00132 

Generated on Sun May 14 14:51:20 2006 by  doxygen 1.4.2