-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacros.h
83 lines (66 loc) · 2 KB
/
macros.h
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
/*****************************************************************/
// MODULE: macros.h
// PURPOSES: common helpful macros [DONE]
/*****************************************************************/
#ifndef _MACROS_H
#define _MACROS_H
//expression represent memory (#Pointer# points to,
//at offset of #Offset# bytes) as varibale of #Type#
#define AT_OFFSET(Type,Pointer,Offset) \
(*((Type*)(((PUCHAR)(Pointer))+(Offset))))
//expression represent pointer to memory (#Pointer# points to,
//at offset of #Offset# bytes) as varibale of #Type#
#define P_OFFSET(Type,Pointer,Offset) \
((Type)(((PUCHAR)(Pointer))+(Offset)))
//offset of field in struct
#define OFFSET_OF_FIELD(StructType,Field) \
((ULONG)(&(((StructType*)NULL)->Field)))
//sizeof struct type member
#define SIZE_OF_FIELD(StructType,Field) \
sizeof(((StructType*)NULL)->Field)
//
// These macros are used to test, set and clear flags respectivly
//
#ifndef FlagOn
#define FlagOn(_F,_SF) ((_F) & (_SF))
#endif
#ifndef BooleanFlagOn
#define BooleanFlagOn(F,SF) ((BOOLEAN)(((F) & (SF)) != 0))
#endif
#ifndef SetFlag
#define SetFlag(_F,_SF) ((_F) |= (_SF))
#endif
#ifndef ClearFlag
#define ClearFlag(_F,_SF) ((_F) &= ~(_SF))
#endif
/*
* Rob Green, a member of the NTDEV list, provides the
* following set of macros that'll keep you from having
* to scratch your head and count zeros ever again.
* Using these defintions, all you'll have to do is write:
*
* interval.QuadPart = RELATIVE(SECONDS(5));
*/
#ifndef ABSOLUTE
#define ABSOLUTE(wait) (wait)
#endif
#ifndef RELATIVE
#define RELATIVE(wait) (-(wait))
#endif
#ifndef NANOSECONDS
#define NANOSECONDS(nanos) \
(((signed __int64)(nanos)) / 100L)
#endif
#ifndef MICROSECONDS
#define MICROSECONDS(micros) \
(((signed __int64)(micros)) * NANOSECONDS(1000L))
#endif
#ifndef MILLISECONDS
#define MILLISECONDS(milli) \
(((signed __int64)(milli)) * MICROSECONDS(1000L))
#endif
#ifndef SECONDS
#define SECONDS(seconds) \
(((signed __int64)(seconds)) * MILLISECONDS(1000L))
#endif
#endif _MACROS_H