03b9dfbf31b98fa3cf90f80ab48399dcfbb0e432
[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 #if !defined (LINUX_24) && LINUX_VERSION_CODE > KERNEL_VERSION(2,6,22)
12 #define malloc(_size, type, flags)                      \
13         kmalloc(_size, GFP_ATOMIC | __GFP_ZERO)
14 #else /* LINUX <= 2.6.22 and LINUX_24 */
15 /* linux 2.6.22 does not zero allocated memory */
16 #define malloc(_size, type, flags)                      \
17         ({ int _s = _size;                              \
18         void *_ret = kmalloc(_s, GFP_ATOMIC);           \
19         if (_ret) memset(_ret, 0, _s);                  \
20         (_ret);                                         \
21         })
22 #endif /* LINUX <= 2.6.22 */
23
24 #define calloc(_n, _s) malloc((_n * _s), NULL, GFP_ATOMIC | __GFP_ZERO)
25 #define free(_var, type) kfree(_var)
26
27 #else /* _WIN32, the windows version */
28
29 /*
30  * ntddk.h uses win_malloc() and MmFreeContiguousMemory().
31  * wipfw uses
32  * ExAllocatePoolWithTag(, pool, len, tag)
33  * ExFreePoolWithTag(ptr, tag)
34  */
35 #define malloc(_size, _type, _flags) my_alloc(_size)
36
37 void *my_alloc(int _size);
38 /* the 'tag' version does not work without -Gz in the linker */
39 #define free(_var, type) ExFreePool(_var)
40 //#define free(_var, type) ExFreePoolWithTag(_var, 'wfpi')
41
42 #endif /* _WIN32 */
43
44 #define M_NOWAIT        0x0001          /* do not block */
45 #define M_ZERO          0x0100          /* bzero the allocation */
46 #endif /* _SYS_MALLOC_H_ */