xref: /kvmtool/include/linux/kernel.h (revision c1b3d8d86e5e587282f0dc24eebb46b365b49f20)
1*c1b3d8d8SSasha Levin #ifndef KVM__LINUX_KERNEL_H_
2*c1b3d8d8SSasha Levin #define KVM__LINUX_KERNEL_H_
3*c1b3d8d8SSasha Levin 
4*c1b3d8d8SSasha Levin #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
5*c1b3d8d8SSasha Levin 
6*c1b3d8d8SSasha Levin #define ALIGN(x,a)		__ALIGN_MASK(x,(typeof(x))(a)-1)
7*c1b3d8d8SSasha Levin #define __ALIGN_MASK(x,mask)	(((x)+(mask))&~(mask))
8*c1b3d8d8SSasha Levin 
9*c1b3d8d8SSasha Levin #ifndef offsetof
10*c1b3d8d8SSasha Levin #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
11*c1b3d8d8SSasha Levin #endif
12*c1b3d8d8SSasha Levin 
13*c1b3d8d8SSasha Levin #ifndef container_of
14*c1b3d8d8SSasha Levin /**
15*c1b3d8d8SSasha Levin  * container_of - cast a member of a structure out to the containing structure
16*c1b3d8d8SSasha Levin  * @ptr:	the pointer to the member.
17*c1b3d8d8SSasha Levin  * @type:	the type of the container struct this is embedded in.
18*c1b3d8d8SSasha Levin  * @member:	the name of the member within the struct.
19*c1b3d8d8SSasha Levin  *
20*c1b3d8d8SSasha Levin  */
21*c1b3d8d8SSasha Levin #define container_of(ptr, type, member) ({			\
22*c1b3d8d8SSasha Levin 	const typeof(((type *)0)->member) * __mptr = (ptr);	\
23*c1b3d8d8SSasha Levin 	(type *)((char *)__mptr - offsetof(type, member)); })
24*c1b3d8d8SSasha Levin #endif
25*c1b3d8d8SSasha Levin 
26*c1b3d8d8SSasha Levin #endif
27