Import source code for dummynet innode emulation.
[ipfw.git] / dummynet / include / sys / malloc.h
1 #ifndef _SYS_MALLOC_H_
2 #define _SYS_MALLOC_H_
3
4 /*
5  * No matter what, try to get clear memory and be non-blocking.
6  * XXX check if 2.4 has a native way to zero memory,
7  * XXX obey to the flags (M_NOWAIT <-> GPF_ATOMIC, M_WAIT <-> GPF_KERNEL)
8  */
9 #ifndef _WIN32 /* this is the linux version */
10
11 #ifndef LINUX_24
12 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,22)
13 #define malloc(_size, type, flags)                      \
14         kmalloc(_size, GFP_ATOMIC | __GFP_ZERO)
15 #else /* LINUX < 2.6.22 and LINUX_24 */
16 /* linux 2.6.22 does not zero allocated memory */
17 #define malloc(_size, type, flags)                      \
18         ({ int _s = _size;                              \
19         void *_ret = kmalloc(_s, GFP_ATOMIC);           \
20         if (_ret) memset(_ret, 0, _s);                  \
21         (_ret);                                         \
22         })
23 #endif /* !LINUX_24 */
24 #endif /* LINUX < 2.6.22 */
25
26 #define calloc(_n, _s) malloc((_n * _s), NULL, GFP_ATOMIC | __GFP_ZERO)
27 #define free(_var, type) kfree(_var)
28
29 #else /* _WIN32, the windows version */
30
31 /*
32  * ntddk.h uses win_malloc() and MmFreeContiguousMemory().
33  * wipfw uses
34  * ExAllocatePoolWithTag(, pool, len, tag)
35  * ExFreePoolWithTag(ptr, tag)
36  */
37 #define malloc(_size, _type, _flags) my_alloc(_size)
38
39 void *my_alloc(int _size);
40 /* the 'tag' version does not work without -Gz in the linker */
41 #define free(_var, type) ExFreePool(_var)
42 //#define free(_var, type) ExFreePoolWithTag(_var, 'wfpi')
43
44 #endif /* _WIN32 */
45
46 #define M_NOWAIT        0x0001          /* do not block */
47 #define M_ZERO          0x0100          /* bzero the allocation */
48 #endif /* _SYS_MALLOC_H_ */