ReactOS 0.4.16-dev-88-ga65b6ae
tools.h
Go to the documentation of this file.
1/*++
2
3Copyright (c) 2002-2012 Alexandr A. Telyatnikov (Alter)
4
5Module Name:
6 tools.h
7
8Abstract:
9 This header contains some useful definitions for data manipulation.
10
11Author:
12 Alexander A. Telyatnikov (Alter)
13
14Environment:
15 kernel mode only
16
17Notes:
18
19 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30Revision History:
31
32Licence:
33 GPLv2
34
35--*/
36
37#ifndef __TOOLS_H__
38#define __TOOLS_H__
39
40#pragma pack(push, 1)
41
42#ifdef __cplusplus
43extern "C" {
44#endif //__cplusplus
45
46//----------------
47
48#ifndef USER_MODE
49#include <ntddk.h> // various NT definitions
50#endif //USER_MODE
51
52//----------------
53
54#ifndef FOUR_BYTE_DEFINED
55#define FOUR_BYTE_DEFINED
56typedef struct _FOUR_BYTE {
62#endif //FOUR_BYTE_DEFINED
63
64#ifdef _DEBUG
65
66#ifndef DBG
67#define DBG
68#endif // DBG
69
70#else // _DEBUG
71
72#ifdef DBG
73#undef DBG
74#endif // DBG
75
76#endif // _DEBUG
77
78// This macro has the effect of Bit = log2(Data)
79
80#define WHICH_BIT(Data, Bit) { \
81 for (Bit = 0; Bit < 32; Bit++) { \
82 if ((Data >> Bit) == 1) { \
83 break; \
84 } \
85 } \
86}
87
88#define PAGE_MASK (PAGE_SIZE-1)
89
90#define ntohs(x) ( (((USHORT)x[0])<<8) | x[1] )
91#define PLAY_ACTIVE(DeviceExtension) (((PCDROM_DATA)(DeviceExtension + 1))->PlayActive)
92#define MSF_TO_LBA(Minutes,Seconds,Frames) \
93 (ULONG)((60 * 75 * (Minutes)) + (75 * (Seconds)) + ((Frames) - 150))
94#define LBA_TO_MSF(Lba,Minutes,Seconds,Frames) \
95{ \
96 (Minutes) = (UCHAR)(Lba / (60 * 75)); \
97 (Seconds) = (UCHAR)((Lba % (60 * 75)) / 75); \
98 (Frames) = (UCHAR)((Lba % (60 * 75)) % 75); \
99}
100#define DEC_TO_BCD(x) (((x / 10) << 4) + (x % 10))
101
102
103#ifdef DBG
104
105#define KdDump(a,b) \
106if((a)!=NULL) { \
107 ULONG i; \
108 for(i=0; i<(b); i++) { \
109 ULONG c; \
110 c = (ULONG)(*(((PUCHAR)(a))+i)); \
111 KdPrint(("%2.2x ",c)); \
112 if ((i & 0x0f) == 0x0f) KdPrint(("\n")); \
113 } \
114 KdPrint(("\n")); \
115}
116
117#define DbgDumpRegTranslation(chan, idx) \
118 KdPrint2((PRINT_PREFIX \
119 " IO_%#x (%#x), %s:\n", \
120 idx, \
121 chan->RegTranslation[idx].Addr, \
122 chan->RegTranslation[idx].Proc ? "Proc" : ( \
123 chan->RegTranslation[idx].MemIo ? "Mem" : "IO"))); \
124
125#define BrutePoint() { ASSERT(0); }
126
127#define DbgAllocatePool(x,y) ExAllocatePool(x,y)
128#define DbgFreePool(x) ExFreePool(x)
129#define DbgAllocatePoolWithTag(a,b,c) ExAllocatePoolWithTag(a,b,c)
130
131#else
132
133#define KdDump(a,b) {}
134
135#define DbgDumpRegTranslation(chan, idx) {}
136
137#define DbgAllocatePool(x,y) ExAllocatePool(x,y)
138#define DbgFreePool(x) ExFreePool(x)
139#define DbgAllocatePoolWithTag(a,b,c) ExAllocatePoolWithTag(a,b,c)
140
141#define BrutePoint() {}
142
143#endif //DBG
144
145
146
147#define WAIT_FOR_XXX_EMU_DELAY DEF_I64(5000000) // 0.5 s
148
149// neat little hacks to count number of bits set efficiently
151{ ULONG i = 0; while (_X) { _X &= _X - 1; i++; } return i; }
153{ ULONG i = 0; while (_X) { _X &= _X - 1; i++; } return i; }
154
155#ifndef max
156#define max(a,b) (((a) > (b)) ? (a) : (b))
157#endif //max
158
159#ifndef min
160#define min(a,b) (((a) < (b)) ? (a) : (b))
161#endif //min
162//#define abs(a) (((a) < 0) ? (-(a)) : (a))
163
164/*
165extern ULONG MajorVersion;
166extern ULONG MinorVersion;
167extern ULONG BuildNumber;
168extern ULONG SPVersion;
169*/
170
171#ifdef __cplusplus
172};
173#endif //__cplusplus
174
175#ifndef USER_MODE
177#endif //USER_MODE
178
179/*
180#define WinVer_Is351 (MajorVersion==0x03)
181#define WinVer_IsNT (MajorVersion==0x04)
182#define WinVer_Is2k (MajorVersion==0x05 && MinorVersion==0x00)
183#define WinVer_IsXP (MajorVersion==0x05 && MinorVersion==0x01)
184#define WinVer_IsdNET (MajorVersion==0x05 && MinorVersion==0x02)
185
186#define WinVer_Id() ((MajorVersion << 8) | MinorVersion)
187
188#define WinVer_351 (0x0351)
189#define WinVer_NT (0x0400)
190#define WinVer_2k (0x0500)
191#define WinVer_XP (0x0501)
192#define WinVer_dNET (0x0502)
193*/
194
195#define PtrOffset(BASE,OFFSET) ((ULONG)((ULONG)(OFFSET) - (ULONG)(BASE)))
196
197#ifndef offsetof
198#define offsetof(type, field) (ULONG)&(((type *)0)->field)
199#endif //offsetof
200
201#pragma pack(pop)
202
203#endif // __TOOLS_H__
#define _X(x)
Definition: CPath.cpp:42
struct _FOUR_BYTE * PFOUR_BYTE
struct _FOUR_BYTE FOUR_BYTE
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
__inline ULONG CountOfSetBitsULong(ULONG _X)
Definition: tools.h:152
__inline ULONG CountOfSetBitsUChar(UCHAR _X)
Definition: tools.h:150
UNICODE_STRING SavedSPString
UCHAR Byte0
Definition: tools.h:16
UCHAR Byte1
Definition: tools.h:17
UCHAR Byte2
Definition: tools.h:18
UCHAR Byte3
Definition: tools.h:19
uint32_t ULONG
Definition: typedefs.h:59
unsigned char UCHAR
Definition: xmlstorage.h:181