Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Enumerations | Functions
kmemleak.c File Reference
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/sched.h>
#include <linux/jiffies.h>
#include <linux/delay.h>
#include <linux/export.h>
#include <linux/kthread.h>
#include <linux/rbtree.h>
#include <linux/fs.h>
#include <linux/debugfs.h>
#include <linux/seq_file.h>
#include <linux/cpumask.h>
#include <linux/spinlock.h>
#include <linux/mutex.h>
#include <linux/rcupdate.h>
#include <linux/stacktrace.h>
#include <linux/cache.h>
#include <linux/percpu.h>
#include <linux/hardirq.h>
#include <linux/mmzone.h>
#include <linux/slab.h>
#include <linux/thread_info.h>
#include <linux/err.h>
#include <linux/uaccess.h>
#include <linux/string.h>
#include <linux/nodemask.h>
#include <linux/mm.h>
#include <linux/workqueue.h>
#include <linux/crc32.h>
#include <asm/sections.h>
#include <asm/processor.h>
#include <linux/atomic.h>
#include <linux/kmemcheck.h>
#include <linux/kmemleak.h>
#include <linux/memory_hotplug.h>

Go to the source code of this file.

Data Structures

struct  kmemleak_scan_area
 
struct  kmemleak_object
 
struct  early_log
 

Macros

#define pr_fmt(fmt)   KBUILD_MODNAME ": " fmt
 
#define MAX_TRACE   16 /* stack trace length */
 
#define MSECS_MIN_AGE   5000 /* minimum object age for reporting */
 
#define SECS_FIRST_SCAN   60 /* delay before the first scan */
 
#define SECS_SCAN_WAIT   600 /* subsequent auto scanning delay */
 
#define MAX_SCAN_SIZE   4096 /* maximum size of a scanned block */
 
#define BYTES_PER_POINTER   sizeof(void *)
 
#define gfp_kmemleak_mask(gfp)
 
#define KMEMLEAK_GREY   0
 
#define KMEMLEAK_BLACK   -1
 
#define OBJECT_ALLOCATED   (1 << 0)
 
#define OBJECT_REPORTED   (1 << 1)
 
#define OBJECT_NO_SCAN   (1 << 2)
 
#define HEX_ROW_SIZE   16
 
#define HEX_GROUP_SIZE   1
 
#define HEX_ASCII   1
 
#define HEX_MAX_LINES   2
 
#define kmemleak_warn(x...)
 
#define kmemleak_stop(x...)
 

Enumerations

enum  {
  KMEMLEAK_ALLOC, KMEMLEAK_ALLOC_PERCPU, KMEMLEAK_FREE, KMEMLEAK_FREE_PART,
  KMEMLEAK_FREE_PERCPU, KMEMLEAK_NOT_LEAK, KMEMLEAK_IGNORE, KMEMLEAK_SCAN_AREA,
  KMEMLEAK_NO_SCAN
}
 

Functions

void __ref kmemleak_alloc (const void *ptr, size_t size, int min_count, gfp_t gfp)
 
 EXPORT_SYMBOL_GPL (kmemleak_alloc)
 
void __ref kmemleak_alloc_percpu (const void __percpu *ptr, size_t size)
 
 EXPORT_SYMBOL_GPL (kmemleak_alloc_percpu)
 
void __ref kmemleak_free (const void *ptr)
 
 EXPORT_SYMBOL_GPL (kmemleak_free)
 
void __ref kmemleak_free_part (const void *ptr, size_t size)
 
 EXPORT_SYMBOL_GPL (kmemleak_free_part)
 
void __ref kmemleak_free_percpu (const void __percpu *ptr)
 
 EXPORT_SYMBOL_GPL (kmemleak_free_percpu)
 
void __ref kmemleak_not_leak (const void *ptr)
 
 EXPORT_SYMBOL (kmemleak_not_leak)
 
void __ref kmemleak_ignore (const void *ptr)
 
 EXPORT_SYMBOL (kmemleak_ignore)
 
void __ref kmemleak_scan_area (const void *ptr, size_t size, gfp_t gfp)
 
 EXPORT_SYMBOL (kmemleak_scan_area)
 
void __ref kmemleak_no_scan (const void *ptr)
 
 EXPORT_SYMBOL (kmemleak_no_scan)
 
 early_param ("kmemleak", kmemleak_boot_config)
 
void __init kmemleak_init (void)
 
 late_initcall (kmemleak_late_init)
 

Macro Definition Documentation

#define BYTES_PER_POINTER   sizeof(void *)

Definition at line 114 of file kmemleak.c.

#define gfp_kmemleak_mask (   gfp)
Value:

Definition at line 117 of file kmemleak.c.

#define HEX_ASCII   1

Definition at line 177 of file kmemleak.c.

#define HEX_GROUP_SIZE   1

Definition at line 175 of file kmemleak.c.

#define HEX_MAX_LINES   2

Definition at line 179 of file kmemleak.c.

#define HEX_ROW_SIZE   16

Definition at line 173 of file kmemleak.c.

#define KMEMLEAK_BLACK   -1

Definition at line 129 of file kmemleak.c.

#define KMEMLEAK_GREY   0

Definition at line 128 of file kmemleak.c.

#define kmemleak_stop (   x...)
Value:
do { \
kmemleak_warn(x); \
kmemleak_disable(); \
} while (0)

Definition at line 278 of file kmemleak.c.

#define kmemleak_warn (   x...)
Value:
do { \
pr_warning(x); \
dump_stack(); \
atomic_set(&kmemleak_warning, 1); \
} while (0)

Definition at line 267 of file kmemleak.c.

#define MAX_SCAN_SIZE   4096 /* maximum size of a scanned block */

Definition at line 112 of file kmemleak.c.

#define MAX_TRACE   16 /* stack trace length */

Definition at line 108 of file kmemleak.c.

#define MSECS_MIN_AGE   5000 /* minimum object age for reporting */

Definition at line 109 of file kmemleak.c.

#define OBJECT_ALLOCATED   (1 << 0)

Definition at line 166 of file kmemleak.c.

#define OBJECT_NO_SCAN   (1 << 2)

Definition at line 170 of file kmemleak.c.

#define OBJECT_REPORTED   (1 << 1)

Definition at line 168 of file kmemleak.c.

#define pr_fmt (   fmt)    KBUILD_MODNAME ": " fmt

Definition at line 64 of file kmemleak.c.

#define SECS_FIRST_SCAN   60 /* delay before the first scan */

Definition at line 110 of file kmemleak.c.

#define SECS_SCAN_WAIT   600 /* subsequent auto scanning delay */

Definition at line 111 of file kmemleak.c.

Enumeration Type Documentation

anonymous enum
Enumerator:
KMEMLEAK_ALLOC 
KMEMLEAK_ALLOC_PERCPU 
KMEMLEAK_FREE 
KMEMLEAK_FREE_PART 
KMEMLEAK_FREE_PERCPU 
KMEMLEAK_NOT_LEAK 
KMEMLEAK_IGNORE 
KMEMLEAK_SCAN_AREA 
KMEMLEAK_NO_SCAN 

Definition at line 232 of file kmemleak.c.

Function Documentation

early_param ( "kmemleak"  ,
kmemleak_boot_config   
)
EXPORT_SYMBOL ( kmemleak_not_leak  )
EXPORT_SYMBOL ( kmemleak_ignore  )
EXPORT_SYMBOL ( kmemleak_scan_area  )
EXPORT_SYMBOL ( kmemleak_no_scan  )
EXPORT_SYMBOL_GPL ( kmemleak_alloc  )
EXPORT_SYMBOL_GPL ( kmemleak_alloc_percpu  )
EXPORT_SYMBOL_GPL ( kmemleak_free  )
EXPORT_SYMBOL_GPL ( kmemleak_free_part  )
EXPORT_SYMBOL_GPL ( kmemleak_free_percpu  )
void __ref kmemleak_alloc ( const void ptr,
size_t  size,
int  min_count,
gfp_t  gfp 
)

kmemleak_alloc - register a newly allocated object : pointer to beginning of the object : size of the object : minimum number of references to this object. If during memory scanning a number of references less than is found, the object is reported as a memory leak. If is 0, the object is never reported as a leak. If is -1, the object is ignored (not scanned and not reported as a leak) : kmalloc() flags used for kmemleak internal memory allocations

This function is called from the kernel allocators when a new object (memory block) is allocated (kmem_cache_alloc, kmalloc, vmalloc etc.).

Definition at line 889 of file kmemleak.c.

void __ref kmemleak_alloc_percpu ( const void __percpu ptr,
size_t  size 
)

kmemleak_alloc_percpu - register a newly allocated __percpu object : __percpu pointer to beginning of the object : size of the object

This function is called from the kernel percpu allocator when a new object (memory block) is allocated (alloc_percpu). It assumes GFP_KERNEL allocation.

Definition at line 910 of file kmemleak.c.

void __ref kmemleak_free ( const void ptr)

kmemleak_free - unregister a previously registered object : pointer to beginning of the object

This function is called from the kernel allocators when an object (memory block) is freed (kmem_cache_free, kfree, vfree etc.).

Definition at line 936 of file kmemleak.c.

void __ref kmemleak_free_part ( const void ptr,
size_t  size 
)

kmemleak_free_part - partially unregister a previously registered object : pointer to the beginning or inside the object. This also represents the start of the range to be freed : size to be unregistered

This function is called when only a part of a memory block is freed (usually from the bootmem allocator).

Definition at line 956 of file kmemleak.c.

void __ref kmemleak_free_percpu ( const void __percpu ptr)

kmemleak_free_percpu - unregister a previously registered __percpu object : __percpu pointer to beginning of the object

This function is called from the kernel percpu allocator when an object (memory block) is freed (free_percpu).

Definition at line 974 of file kmemleak.c.

void __ref kmemleak_ignore ( const void ptr)

kmemleak_ignore - ignore an allocated object : pointer to beginning of the object

Calling this function on an object will cause the memory block to be ignored (not scanned and not reported as a leak). This is usually done when it is known that the corresponding block is not a leak and does not contain any references to other allocated memory blocks.

Definition at line 1016 of file kmemleak.c.

void __init kmemleak_init ( void  )

Definition at line 1754 of file kmemleak.c.

void __ref kmemleak_no_scan ( const void ptr)

kmemleak_no_scan - do not scan an allocated object : pointer to beginning of the object

This function notifies kmemleak not to scan the given memory block. Useful in situations where it is known that the given object does not contain any references to other objects. Kmemleak will not scan such objects reducing the number of false negatives.

Definition at line 1058 of file kmemleak.c.

void __ref kmemleak_not_leak ( const void ptr)

kmemleak_not_leak - mark an allocated object as false positive : pointer to beginning of the object

Calling this function on an object will cause the memory block to no longer be reported as leak and always be scanned.

Definition at line 996 of file kmemleak.c.

void __ref kmemleak_scan_area ( const void ptr,
size_t  size,
gfp_t  gfp 
)

kmemleak_scan_area - limit the range to be scanned in an allocated object : pointer to beginning or inside the object. This also represents the start of the scan area : size of the scan area : kmalloc() flags used for kmemleak internal memory allocations

This function is used when it is known that only certain parts of an object contain references to other objects. Kmemleak will only scan these areas reducing the number false negatives.

Definition at line 1038 of file kmemleak.c.

late_initcall ( kmemleak_late_init  )