2
* Copyright (C) 2006 Giridhar Pemmasani
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
18
/* set ALLOC_DEBUG to 1 to get information about memory used by both
19
* ndiswrapper and Windows driver by reading
20
* /proc/net/ndiswrapper/debug; this will also show memory leaks
21
* (memory allocated but not freed) when ndiswrapper module is
24
* ALLOC_DEBUG=2: details about individual allocations leaking is printed
25
* ALLOC_DEBUG=3: tags in ExAllocatePoolWithTag leaking printed
29
//#define ALLOC_DEBUG 1
32
enum alloc_type { ALLOC_TYPE_KMALLOC_ATOMIC, ALLOC_TYPE_KMALLOC_NON_ATOMIC,
33
ALLOC_TYPE_VMALLOC_ATOMIC, ALLOC_TYPE_VMALLOC_NON_ATOMIC,
34
ALLOC_TYPE_SLACK, ALLOC_TYPE_PAGES, ALLOC_TYPE_MAX };
36
int wrapmem_init(void);
37
void wrapmem_exit(void);
38
void *slack_kmalloc(size_t size);
39
void slack_kfree(void *ptr);
40
void wrapmem_info(void);
43
void *wrap_kmalloc(size_t size, gfp_t flags, const char *file, int line);
44
void *wrap_kzalloc(size_t size, gfp_t flags, const char *file, int line);
45
void wrap_kfree(void *ptr);
46
void *wrap_vmalloc(unsigned long size, const char *file, int line);
47
void *wrap__vmalloc(unsigned long size, gfp_t flags, pgprot_t prot,
48
const char *file, int line);
49
void wrap_vfree(void *ptr);
50
void *wrap_alloc_pages(gfp_t flags, unsigned int size,
51
const char *file, int line);
52
void wrap_free_pages(unsigned long ptr, int order);
53
int alloc_size(enum alloc_type type);
62
#define kmalloc(size, flags) \
63
wrap_kmalloc(size, flags, __FILE__, __LINE__)
64
#define kzalloc(size, flags) \
65
wrap_kzalloc(size, flags, __FILE__, __LINE__)
66
#define vmalloc(size) \
67
wrap_vmalloc(size, __FILE__, __LINE__)
68
#define __vmalloc(size, flags, prot) \
69
wrap__vmalloc(size, flags, prot, __FILE__, __LINE__)
70
#define kfree(ptr) wrap_kfree(ptr)
71
#define vfree(ptr) wrap_vfree(ptr)
73
#define wrap_get_free_pages(flags, size) \
74
wrap_alloc_pages(flags, size, __FILE__, __LINE__)
76
#define free_pages(ptr, order) wrap_free_pages(ptr, order)
79
void *wrap_ExAllocatePoolWithTag(enum pool_type pool_type, SIZE_T size,
80
ULONG tag, const char *file, int line);
81
#define ExAllocatePoolWithTag(pool_type, size, tag) \
82
wrap_ExAllocatePoolWithTag(pool_type, size, tag, __FILE__, __LINE__)
89
#define wrap_get_free_pages(flags, size) \
90
(void *)__get_free_pages(flags, get_order(size))