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 * XXX On zeroshell (2.6.25.17) we get a load error
13 * __you_cannot_kmalloc_that_much
14 * which is triggered when kmalloc() is called with a large
15 * compile-time constant argument (include/linux/slab_def.h)
17 * I think it may be a compiler (or source) bug because there is no
18 * evidence that such a large request is made.
19 * Making the _size argument to kmalloc volatile prevents the compiler
20 * from making the mistake, though it is clearly not ideal.
23 #if !defined (LINUX_24) && LINUX_VERSION_CODE > KERNEL_VERSION(2,6,22)
24 #define malloc(_size, type, flags) \
25 ({ volatile int _v = _size; kmalloc(_v, GFP_ATOMIC | __GFP_ZERO); })
26 #else /* LINUX <= 2.6.22 and LINUX_24 */
27 /* linux 2.6.22 does not zero allocated memory */
28 #define malloc(_size, type, flags) \
30 void *_ret = kmalloc(_s, GFP_ATOMIC); \
31 if (_ret) memset(_ret, 0, _s); \
34 #endif /* LINUX <= 2.6.22 */
36 #define calloc(_n, _s) malloc((_n * _s), NULL, GFP_ATOMIC | __GFP_ZERO)
37 #define free(_var, type) kfree(_var)
39 #else /* _WIN32, the windows version */
42 * ntddk.h uses win_malloc() and MmFreeContiguousMemory().
44 * ExAllocatePoolWithTag(, pool, len, tag)
45 * ExFreePoolWithTag(ptr, tag)
47 #define malloc(_size, _type, _flags) my_alloc(_size)
49 void *my_alloc(int _size);
50 /* the 'tag' version does not work without -Gz in the linker */
51 #define free(_var, type) ExFreePool(_var)
52 //#define free(_var, type) ExFreePoolWithTag(_var, 'wfpi')
56 #define M_NOWAIT 0x0001 /* do not block */
57 #define M_ZERO 0x0100 /* bzero the allocation */
58 #endif /* _SYS_MALLOC_H_ */