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)
9 #ifndef _WIN32 /* this is the linux version */
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) \
19 void *_ret = kmalloc(_s, GFP_ATOMIC); \
20 if (_ret) memset(_ret, 0, _s); \
23 #endif /* !LINUX_24 */
24 #endif /* LINUX < 2.6.22 */
26 #define calloc(_n, _s) malloc((_n * _s), NULL, GFP_ATOMIC | __GFP_ZERO)
27 #define free(_var, type) kfree(_var)
29 #else /* _WIN32, the windows version */
32 * ntddk.h uses win_malloc() and MmFreeContiguousMemory().
34 * ExAllocatePoolWithTag(, pool, len, tag)
35 * ExFreePoolWithTag(ptr, tag)
37 #define malloc(_size, _type, _flags) my_alloc(_size)
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')
46 #define M_NOWAIT 0x0001 /* do not block */
47 #define M_ZERO 0x0100 /* bzero the allocation */
48 #endif /* _SYS_MALLOC_H_ */