Doxygen

typedefs.h
Go to the documentation of this file.
00001 /*
00002   PROJECT:    ReactOS
00003   LICENSE:    GPL v2 or any later version
00004   FILE:       include/host/typedefs.h
00005   PURPOSE:    Type definitions and useful macros for host tools
00006   COPYRIGHT:  Copyright 2007 Hervé Poussineau
00007               Copyright 2007 Colin Finck <mail@colinfinck.de>
00008 */
00009 
00010 #ifndef _TYPEDEFS_HOST_H
00011 #define _TYPEDEFS_HOST_H
00012 
00013 #include <assert.h>
00014 #include <stdlib.h>
00015 #include <limits.h>
00016 
00017 /* Function attributes for GCC */
00018 #if !defined(_MSC_VER) && !defined(__fastcall)
00019 #define __fastcall __attribute__((fastcall))
00020 #endif
00021 #if !defined(_MSC_VER) && !defined(__cdecl)
00022 #define __cdecl __attribute__((cdecl))
00023 #endif
00024 #if !defined(_MSC_VER) && !defined(__stdcall)
00025 #define __stdcall __attribute__((stdcall))
00026 #endif
00027 
00028 /* Basic definitions */
00029 #define UNIMPLEMENTED { printf("%s unimplemented\n", __FUNCTION__); exit(1); }
00030 #define ASSERT(x) assert(x)
00031 #define ASSERTMSG(x, m) assert(x)
00032 #define DPRINT if (0) printf
00033 #define DPRINT1 printf
00034 
00035 #define NTAPI
00036 #define WINAPI
00037 
00038 #define IN
00039 #define OUT
00040 #define OPTIONAL
00041 
00042 #define FALSE 0
00043 #define TRUE  1
00044 
00045 #define ANYSIZE_ARRAY 1
00046 
00047 /* Basic types
00048    Emulate a LLP64 memory model using a LP64 compiler */
00049 typedef void VOID, *PVOID;
00050 typedef char CHAR, CCHAR, *PCHAR, *PSTR;
00051 typedef const char *PCSTR, *LPCSTR;
00052 typedef unsigned char UCHAR, *PUCHAR, BYTE, *LPBYTE, BOOLEAN, *PBOOLEAN;
00053 typedef short SHORT, *PSHORT;
00054 typedef unsigned short USHORT, *PUSHORT, WORD, *PWORD, *LPWORD, WCHAR, *PWCHAR, *PWSTR, *LPWSTR;
00055 typedef const unsigned short *PCWSTR, *LPCWSTR;
00056 typedef int INT, LONG, *PLONG, *LPLONG, BOOL;
00057 typedef unsigned int UINT, *PUINT, *LPUINT, ULONG, *PULONG, DWORD, *LPDWORD;
00058 typedef long LONG_PTR, *PLONG_PTR, INT_PTR, *PINT_PTR;
00059 typedef unsigned long ULONG_PTR, DWORD_PTR, *PULONG_PTR, UINT_PTR, *PUINT_PTR;
00060 typedef long long LONGLONG;
00061 typedef unsigned long long ULONGLONG;
00062 
00063 /* Derived types */
00064 typedef PVOID HANDLE, HKEY, *PHKEY;
00065 typedef INT NTSTATUS, POOL_TYPE;
00066 typedef LONG HRESULT;
00067 typedef ULONG_PTR SIZE_T, *PSIZE_T;
00068 typedef WORD LANGID;
00069 
00070 #define MAXUSHORT USHRT_MAX
00071 
00072 /* Widely used structures */
00073 #include <pshpack4.h>
00074 typedef struct _RTL_BITMAP
00075 {
00076     ULONG  SizeOfBitMap;
00077     PULONG  Buffer;
00078 } RTL_BITMAP, *PRTL_BITMAP;
00079 
00080 typedef struct _RTL_BITMAP_RUN
00081 {
00082     ULONG StartingIndex;
00083     ULONG NumberOfBits;
00084 } RTL_BITMAP_RUN, *PRTL_BITMAP_RUN;
00085 
00086 typedef union _LARGE_INTEGER
00087 {
00088     struct
00089     {
00090         DWORD LowPart;
00091         LONG  HighPart;
00092     };
00093     LONGLONG QuadPart;
00094 } LARGE_INTEGER, *PLARGE_INTEGER;
00095 
00096 typedef struct _LIST_ENTRY
00097 {
00098     struct _LIST_ENTRY *Flink;
00099     struct _LIST_ENTRY *Blink;
00100 } LIST_ENTRY,*PLIST_ENTRY;
00101 
00102 typedef struct _ANSI_STRING
00103 {
00104     USHORT Length;
00105     USHORT MaximumLength;
00106     PSTR   Buffer;
00107 } ANSI_STRING, *PANSI_STRING;
00108 
00109 typedef struct _UNICODE_STRING
00110 {
00111     USHORT Length;
00112     USHORT MaximumLength;
00113     PWSTR  Buffer;
00114 } UNICODE_STRING, *PUNICODE_STRING;
00115 #include <poppack.h>
00116 
00117 /* List Functions */
00118 static __inline
00119 VOID
00120 InitializeListHead(
00121                    IN PLIST_ENTRY ListHead
00122                    )
00123 {
00124     ListHead->Flink = ListHead->Blink = ListHead;
00125 }
00126 
00127 static __inline
00128 VOID
00129 InsertHeadList(
00130                IN PLIST_ENTRY ListHead,
00131                IN PLIST_ENTRY Entry
00132                )
00133 {
00134     PLIST_ENTRY OldFlink;
00135     OldFlink = ListHead->Flink;
00136     Entry->Flink = OldFlink;
00137     Entry->Blink = ListHead;
00138     OldFlink->Blink = Entry;
00139     ListHead->Flink = Entry;
00140 }
00141 
00142 static __inline
00143 VOID
00144 InsertTailList(
00145                IN PLIST_ENTRY ListHead,
00146                IN PLIST_ENTRY Entry
00147                )
00148 {
00149     PLIST_ENTRY OldBlink;
00150     OldBlink = ListHead->Blink;
00151     Entry->Flink = ListHead;
00152     Entry->Blink = OldBlink;
00153     OldBlink->Flink = Entry;
00154     ListHead->Blink = Entry;
00155 }
00156 
00157 static __inline
00158 BOOLEAN
00159 IsListEmpty(
00160             IN const LIST_ENTRY * ListHead
00161             )
00162 {
00163     return (BOOLEAN)(ListHead->Flink == ListHead);
00164 }
00165 
00166 static __inline
00167 BOOLEAN
00168 RemoveEntryList(
00169                 IN PLIST_ENTRY Entry)
00170 {
00171     PLIST_ENTRY OldFlink;
00172     PLIST_ENTRY OldBlink;
00173 
00174     OldFlink = Entry->Flink;
00175     OldBlink = Entry->Blink;
00176     OldFlink->Blink = OldBlink;
00177     OldBlink->Flink = OldFlink;
00178     return (BOOLEAN)(OldFlink == OldBlink);
00179 }
00180 
00181 static __inline
00182 PLIST_ENTRY
00183 RemoveHeadList(
00184                IN PLIST_ENTRY ListHead)
00185 {
00186     PLIST_ENTRY Flink;
00187     PLIST_ENTRY Entry;
00188 
00189     Entry = ListHead->Flink;
00190     Flink = Entry->Flink;
00191     ListHead->Flink = Flink;
00192     Flink->Blink = ListHead;
00193     return Entry;
00194 }
00195 
00196 static __inline
00197 PLIST_ENTRY
00198 RemoveTailList(
00199                IN PLIST_ENTRY ListHead)
00200 {
00201     PLIST_ENTRY Blink;
00202     PLIST_ENTRY Entry;
00203 
00204     Entry = ListHead->Blink;
00205     Blink = Entry->Blink;
00206     ListHead->Blink = Blink;
00207     Blink->Flink = ListHead;
00208     return Entry;
00209 }
00210 
00211 typedef const UNICODE_STRING *PCUNICODE_STRING;
00212 
00213 /* Widely used macros */
00214 #define LOBYTE(w)               ((BYTE)(w))
00215 #define HIBYTE(w)               ((BYTE)(((WORD)(w)>>8)&0xFF))
00216 #define LOWORD(l)               ((WORD)((DWORD_PTR)(l)))
00217 #define HIWORD(l)               ((WORD)(((DWORD_PTR)(l)>>16)&0xFFFF))
00218 #define MAKEWORD(a,b)           ((WORD)(((BYTE)(a))|(((WORD)((BYTE)(b)))<<8)))
00219 #define MAKELONG(a,b)           ((LONG)(((WORD)(a))|(((DWORD)((WORD)(b)))<<16)))
00220 
00221 #define MAXULONG 0xFFFFFFFF
00222 
00223 #define NT_SUCCESS(x)           ((x)>=0)
00224 #if !defined(__GNUC__)
00225 #define FIELD_OFFSET(t,f)       ((LONG)(LONG_PTR)&(((t*) 0)->f))
00226 #else
00227 #define FIELD_OFFSET(t,f)       ((LONG)__builtin_offsetof(t,f))
00228 #endif
00229 #define RTL_CONSTANT_STRING(s)  { sizeof(s)-sizeof((s)[0]), sizeof(s), s }
00230 #define CONTAINING_RECORD(address, type, field)  ((type *)(((ULONG_PTR)address) - (ULONG_PTR)(&(((type *)0)->field))))
00231 
00232 #define RtlZeroMemory(Destination, Length)            memset(Destination, 0, Length)
00233 #define RtlCopyMemory(Destination, Source, Length)    memcpy(Destination, Source, Length)
00234 #define RtlMoveMemory(Destination, Source, Length)    memmove(Destination, Source, Length)
00235 
00236 #define MAKELANGID(p,s)         ((((WORD)(s))<<10)|(WORD)(p))
00237 #define PRIMARYLANGID(l)        ((WORD)(l)&0x3ff)
00238 #define SUBLANGID(l)            ((WORD)(l)>>10)
00239 #define SUBLANG_NEUTRAL         0x00
00240 
00241 /* Prevent inclusion of some other headers */
00242 #define __INTERNAL_DEBUG
00243 #define RTL_H
00244 
00245 #endif