2 #ifndef KVM__LINUX_KERNEL_H_
3 #define KVM__LINUX_KERNEL_H_
5 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
7 #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)
8 #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
11 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
16 * container_of - cast a member of a structure out to the containing structure
17 * @ptr: the pointer to the member.
18 * @type: the type of the container struct this is embedded in.
19 * @member: the name of the member within the struct.
22 #define container_of(ptr, type, member) ({ \
23 const typeof(((type *)0)->member) * __mptr = (ptr); \
24 (type *)((char *)__mptr - offsetof(type, member)); })
27 #define min(x, y) ({ \
28 typeof(x) _min1 = (x); \
29 typeof(y) _min2 = (y); \
30 (void) (&_min1 == &_min2); \
31 _min1 < _min2 ? _min1 : _min2; })
33 #define max(x, y) ({ \
34 typeof(x) _max1 = (x); \
35 typeof(y) _max2 = (y); \
36 (void) (&_max1 == &_max2); \
37 _max1 > _max2 ? _max1 : _max2; })