/
usr
/
share
/
systemtap
/
runtime
/
linux
/
/usr/share/systemtap/runtime/linux
mkdir
upload
Name
Size
Mode
Actions
uprobes/
-
0755
rm
uprobes2/
-
0755
rm
access_process_vm.h
4311
0644
edit
dl
rm
addr-map.c
9749
0644
edit
dl
rm
alloc.c
15900
0644
edit
dl
rm
arith.c
16799
0644
edit
dl
rm
autoconf-514-panic.c
68
0644
edit
dl
rm
autoconf-access_ok_2args.c
90
0644
edit
dl
rm
autoconf-alloc-percpu-align.c
118
0644
edit
dl
rm
autoconf-asm-syscall.c
51
0644
edit
dl
rm
autoconf-atomic_fetch_add_unless.c
94
0644
edit
dl
rm
autoconf-bio-bi_opf.c
824
0644
edit
dl
rm
autoconf-blk-types.c
359
0644
edit
dl
rm
autoconf-compat-utimbuf.c
53
0644
edit
dl
rm
autoconf-compat_sigaction.c
448
0644
edit
dl
rm
autoconf-constant-tsc.c
63
0644
edit
dl
rm
autoconf-cpu-clock.c
1277
0644
edit
dl
rm
autoconf-dpath-path.c
121
0644
edit
dl
rm
autoconf-files_lookup_fd_raw.c
136
0644
edit
dl
rm
autoconf-from_kuid_munged.c
191
0644
edit
dl
rm
autoconf-fs_supers-hlist.c
354
0644
edit
dl
rm
autoconf-generated-compile.c
56
0644
edit
dl
rm
autoconf-genhd.c
201
0644
edit
dl
rm
autoconf-get-kretprobe.c
107
0644
edit
dl
rm
autoconf-get_user_pages-flags.c
1549
0644
edit
dl
rm
autoconf-get_user_pages-notask_struct.c
1301
0644
edit
dl
rm
autoconf-get_user_pages_remote-flags.c
1550
0644
edit
dl
rm
autoconf-get_user_pages_remote-flags_locked.c
1331
0644
edit
dl
rm
autoconf-get_user_pages_remote-notask_struct.c
1438
0644
edit
dl
rm
autoconf-grsecurity.c
219
0644
edit
dl
rm
autoconf-hlist-4args.c
296
0644
edit
dl
rm
autoconf-hlist_add_tail_rcu.c
112
0644
edit
dl
rm
autoconf-hrtimer-getset-expires.c
126
0644
edit
dl
rm
autoconf-hrtimer-rel.c
87
0644
edit
dl
rm
autoconf-hw_breakpoint_context.c
315
0644
edit
dl
rm
autoconf-inode-private.c
173
0644
edit
dl
rm
autoconf-inode-rwsem.c
172
0644
edit
dl
rm
autoconf-inode-uretprobes.c
264
0644
edit
dl
rm
autoconf-kernel_read-new-args.c
1030
0644
edit
dl
rm
autoconf-kprobe-symbol-name.c
90
0644
edit
dl
rm
autoconf-ktime-get-real.c
98
0644
edit
dl
rm
autoconf-linux-sched_headers.c
1678
0644
edit
dl
rm
autoconf-local-clock.c
1282
0644
edit
dl
rm
autoconf-lockdown-debugfs.c
102
0644
edit
dl
rm
autoconf-lockdown-kernel.c
90
0644
edit
dl
rm
autoconf-mm-context-vdso-base.c
117
0644
edit
dl
rm
autoconf-mm-context-vdso.c
114
0644
edit
dl
rm
autoconf-mm-shmempages.c
72
0644
edit
dl
rm
autoconf-mmap_lock.c
175
0644
edit
dl
rm
autoconf-module-sect-attrs.c
158
0644
edit
dl
rm
autoconf-module_layout.c
52
0644
edit
dl
rm
autoconf-mod_kallsyms.c
51
0644
edit
dl
rm
autoconf-nameidata.c
96
0644
edit
dl
rm
autoconf-netfilter-4_1.c
769
0644
edit
dl
rm
autoconf-netfilter-4_4.c
1460
0644
edit
dl
rm
autoconf-netfilter-313b.c
602
0644
edit
dl
rm
autoconf-netfilter.c
422
0644
edit
dl
rm
autoconf-old-inode-uprobes.c
357
0644
edit
dl
rm
autoconf-oneachcpu-retry.c
957
0644
edit
dl
rm
autoconf-pagefault_disable.c
137
0644
edit
dl
rm
autoconf-pde_data.c
226
0644
edit
dl
rm
autoconf-perf-structpid.c
444
0644
edit
dl
rm
autoconf-procfs-owner.c
158
0644
edit
dl
rm
autoconf-proc_ops.c
566
0644
edit
dl
rm
autoconf-rcu_is_watching.c
385
0644
edit
dl
rm
autoconf-real-parent.c
427
0644
edit
dl
rm
autoconf-regset.c
239
0644
edit
dl
rm
autoconf-relay-umode_t.c
730
0644
edit
dl
rm
autoconf-relay_buf-per_cpu_ptr.c
920
0644
edit
dl
rm
autoconf-ring_buffer-flags.c
112
0644
edit
dl
rm
autoconf-ring_buffer_lost_events.c
296
0644
edit
dl
rm
autoconf-ring_buffer_read_prepare.c
181
0644
edit
dl
rm
autoconf-save-stack-trace-no-bp.c
498
0644
edit
dl
rm
autoconf-save-stack-trace.c
501
0644
edit
dl
rm
autoconf-set_fs.c
221
0644
edit
dl
rm
autoconf-smpcall-4args.c
166
0644
edit
dl
rm
autoconf-smpcall-5args.c
169
0644
edit
dl
rm
autoconf-stack-trace-save-regs.c
176
0644
edit
dl
rm
autoconf-stacktrace_ops-int-address.c
409
0644
edit
dl
rm
autoconf-stacktrace_ops-warning.c
188
0644
edit
dl
rm
autoconf-syscall_get_args_3args.c
239
0644
edit
dl
rm
autoconf-task-state.c
550
0644
edit
dl
rm
autoconf-task-uid.c
152
0644
edit
dl
rm
autoconf-task_work-struct.c
219
0644
edit
dl
rm
autoconf-time32-old.c
52
0644
edit
dl
rm
autoconf-time32.c
53
0644
edit
dl
rm
autoconf-timerfd.c
232
0644
edit
dl
rm
autoconf-trace-printk.c
151
0644
edit
dl
rm
autoconf-tracepoint-has-data.c
493
0644
edit
dl
rm
autoconf-tracepoint-strings.c
233
0644
edit
dl
rm
autoconf-uaccess.c
28
0644
edit
dl
rm
autoconf-uapi-mount.c
52
0644
edit
dl
rm
autoconf-udelay_simple.c
90
0644
edit
dl
rm
autoconf-uidgid.c
50
0644
edit
dl
rm
autoconf-unwind-stack-trace.c
326
0644
edit
dl
rm
autoconf-uprobe-get-pc.c
374
0644
edit
dl
rm
autoconf-utrace-regset.c
273
0644
edit
dl
rm
autoconf-utrace-via-tracepoints.c
1712
0644
edit
dl
rm
autoconf-vm-area-pte.c
141
0644
edit
dl
rm
autoconf-walk-stack.c
217
0644
edit
dl
rm
autoconf-x86-fs.c
90
0644
edit
dl
rm
autoconf-x86-gs.c
90
0644
edit
dl
rm
autoconf-x86-uniregs.c
140
0644
edit
dl
rm
autoconf-x86-xfs.c
91
0644
edit
dl
rm
common_session_state.h
3249
0644
edit
dl
rm
compat_net.h
858
0644
edit
dl
rm
compat_structs.h
4409
0644
edit
dl
rm
compat_unistd.h
68384
0644
edit
dl
rm
copy.c
2717
0644
edit
dl
rm
debug.h
2978
0644
edit
dl
rm
io.c
5291
0644
edit
dl
rm
itrace.c
14874
0644
edit
dl
rm
kprobes.c
25126
0644
edit
dl
rm
loc2c-runtime.h
29874
0644
edit
dl
rm
map_list.h
1220
0644
edit
dl
rm
map_runtime.h
5266
0644
edit
dl
rm
namespaces.h
7128
0644
edit
dl
rm
netfilter.c
1410
0644
edit
dl
rm
perf.c
7596
0644
edit
dl
rm
perf.h
1272
0644
edit
dl
rm
perf_event_counter_context.c
336
0644
edit
dl
rm
perf_probe_handler_nmi.c
278
0644
edit
dl
rm
perf_read.h
959
0644
edit
dl
rm
print.c
11402
0644
edit
dl
rm
probe_lock.h
1807
0644
edit
dl
rm
regs-ia64.c
3741
0644
edit
dl
rm
regs.c
13490
0644
edit
dl
rm
runtime.h
12591
0644
edit
dl
rm
runtime_context.h
6089
0644
edit
dl
rm
runtime_defines.h
1041
0644
edit
dl
rm
stap_mmap_lock.h
343
0644
edit
dl
rm
stat_runtime.h
1774
0644
edit
dl
rm
stp_tls.h
1181
0644
edit
dl
rm
stp_tracepoint.c
11481
0644
edit
dl
rm
stp_tracepoint.h
2270
0644
edit
dl
rm
syscalls-common.h
976
0644
edit
dl
rm
task_finder.c
53860
0644
edit
dl
rm
task_finder2.c
57640
0644
edit
dl
rm
task_finder_map.c
5194
0644
edit
dl
rm
task_finder_stubs.c
2442
0644
edit
dl
rm
task_work_compatibility.h
1283
0644
edit
dl
rm
timer.c
2200
0644
edit
dl
rm
timer.h
1383
0644
edit
dl
rm
timer_compatibility.h
2317
0644
edit
dl
rm
uprobes-common.c
15573
0644
edit
dl
rm
uprobes-common.h
1653
0644
edit
dl
rm
uprobes-inc.h
484
0644
edit
dl
rm
uprobes-inode.c
34086
0644
edit
dl
rm
Edit:
/usr/share/systemtap/runtime/linux/alloc.c
(15900B)
/* -*- linux-c -*- * Memory allocation functions * Copyright (C) 2005-2018 Red Hat Inc. * * This file is part of systemtap, and is free software. You can * redistribute it and/or modify it under the terms of the GNU General * Public License (GPL); either version 2, or (at your option) any * later version. */ #ifndef _STAPLINUX_ALLOC_C_ #define _STAPLINUX_ALLOC_C_ #include <linux/percpu.h> #include "stp_helper_lock.h" static long _stp_allocated_net_memory = 0; /* Default, and should be "safe" from anywhere. */ #define STP_ALLOC_FLAGS ((GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN) \ & ~__GFP_WAIT) /* May only be used in context that can sleep. __GFP_NORETRY is to suppress the oom-killer from kicking in. */ #define STP_ALLOC_SLEEP_FLAGS (GFP_KERNEL | __GFP_NORETRY) /* #define DEBUG_MEMALLOC_MIGHT_SLEEP */ /* * If DEBUG_MEMALLOC_MIGHT_SLEEP is defined (stap -DDEBUG_MEMALLOC_MIGHT_SLEEP ...) * then all memory allocation operations are assumed to sleep. This * can be used to check whether any memory allocations occur in atomic * context, which is discouraged on realtime kernels. */ /* #define DEBUG_MEM */ /* * If DEBUG_MEM is defined (stap -DDEBUG_MEM ...) then full memory * tracking is used. Each allocation is recorded and matched with * a free. Also a fence is set around the allocated memory so overflows * and underflows can be detected. Errors are written to the system log * with printk. * * NOTE: if youy system is slow or your script makes a very large number * of allocations, you may get a warning in the system log: * BUG: soft lockup - CPU#1 stuck for 11s! [staprun:28269] * This is an expected side-effect of the overhead of tracking, especially * with a simple linked list of allocations. Optimization * would be nice, but DEBUG_MEM is only for testing. */ static long _stp_allocated_memory = 0; #ifdef DEBUG_MEM static STP_DEFINE_SPINLOCK(_stp_mem_lock); #define MEM_MAGIC 0xc11cf77f #define MEM_FENCE_SIZE 32 enum _stp_memtype { MEM_KMALLOC, MEM_VMALLOC, MEM_PERCPU }; typedef struct { char *alloc; char *free; } _stp_malloc_type; static const _stp_malloc_type _stp_malloc_types[] = { {"kmalloc", "kfree"}, {"vmalloc", "vfree"}, {"alloc_percpu", "free_percpu"} }; struct _stp_mem_entry { struct list_head list; int32_t magic; enum _stp_memtype type; size_t len; void *addr; }; #define MEM_DEBUG_SIZE (2*MEM_FENCE_SIZE+sizeof(struct _stp_mem_entry)) static LIST_HEAD(_stp_mem_list); static void _stp_check_mem_fence (char *addr, int size) { char *ptr; int i; ptr = addr - MEM_FENCE_SIZE; while (ptr < addr) { if (*ptr != 0x55) { printk("SYSTEMTAP ERROR: Memory fence corrupted before allocated memory\n"); printk("at addr %p. (Allocation starts at %p)", ptr, addr); return; } ptr++; } ptr = addr + size; while (ptr < addr + size + MEM_FENCE_SIZE) { if (*ptr != 0x55) { printk("SYSTEMTAP ERROR: Memory fence corrupted after allocated memory\n"); printk("at addr %p. (Allocation ends at %p)", ptr, addr + size - 1); return; } ptr++; } } static void *_stp_mem_debug_setup(void *addr, size_t size, enum _stp_memtype type) { struct list_head *p; struct _stp_mem_entry *m; unsigned long flags; memset(addr, 0x55, MEM_FENCE_SIZE); addr += MEM_FENCE_SIZE; memset(addr + size, 0x55, MEM_FENCE_SIZE); p = (struct list_head *)(addr + size + MEM_FENCE_SIZE); m = (struct _stp_mem_entry *)p; m->magic = MEM_MAGIC; m->type = type; m->len = size; m->addr = addr; stp_spin_lock_irqsave(&_stp_mem_lock, flags); list_add(p, &_stp_mem_list); stp_spin_unlock_irqrestore(&_stp_mem_lock, flags); return addr; } /* Percpu allocations don't have the fence. Implementing it is problematic. */ static void _stp_mem_debug_percpu(struct _stp_mem_entry *m, void *addr, size_t size) { struct list_head *p = (struct list_head *)m; unsigned long flags; m->magic = MEM_MAGIC; m->type = MEM_PERCPU; m->len = size; m->addr = addr; stp_spin_lock_irqsave(&_stp_mem_lock, flags); list_add(p, &_stp_mem_list); stp_spin_unlock_irqrestore(&_stp_mem_lock, flags); } static void _stp_mem_debug_free(void *addr, enum _stp_memtype type) { int found = 0; struct list_head *p, *tmp; struct _stp_mem_entry *m = NULL; unsigned long flags; if (!addr) { /* Passing NULL to these *free() functions is safe */ switch (type) { case MEM_KMALLOC: case MEM_PERCPU: case MEM_VMALLOC: return; } } stp_spin_lock_irqsave(&_stp_mem_lock, flags); list_for_each_safe(p, tmp, &_stp_mem_list) { m = list_entry(p, struct _stp_mem_entry, list); if (m->addr == addr) { list_del(p); found = 1; break; } } stp_spin_unlock_irqrestore(&_stp_mem_lock, flags); if (!found) { printk("SYSTEMTAP ERROR: Free of unallocated memory %p type=%s\n", addr, _stp_malloc_types[type].free); return; } if (m->magic != MEM_MAGIC) { printk("SYSTEMTAP ERROR: Memory at %p corrupted!!\n", addr); return; } if (m->type != type) { printk("SYSTEMTAP ERROR: Memory allocated with %s and freed with %s\n", _stp_malloc_types[m->type].alloc, _stp_malloc_types[type].free); } switch (m->type) { case MEM_KMALLOC: _stp_check_mem_fence(addr, m->len); kfree(addr - MEM_FENCE_SIZE); break; case MEM_PERCPU: free_percpu(addr); kfree(p); break; case MEM_VMALLOC: _stp_check_mem_fence(addr, m->len); vfree(addr - MEM_FENCE_SIZE); break; default: printk("SYSTEMTAP ERROR: Attempted to free memory at addr %p len=%d with unknown allocation type.\n", addr, (int)m->len); } return; } static void _stp_mem_debug_validate(void *addr) { int found = 0; struct list_head *p, *tmp; struct _stp_mem_entry *m = NULL; unsigned long flags; stp_spin_lock_irqsave(&_stp_mem_lock, flags); list_for_each_safe(p, tmp, &_stp_mem_list) { m = list_entry(p, struct _stp_mem_entry, list); if (m->addr == addr) { found = 1; break; } } stp_spin_unlock_irqrestore(&_stp_mem_lock, flags); if (!found) { printk("SYSTEMTAP ERROR: Couldn't validate memory %p\n", addr); return; } if (m->magic != MEM_MAGIC) { printk("SYSTEMTAP ERROR: Memory at %p corrupted!!\n", addr); return; } switch (m->type) { case MEM_KMALLOC: _stp_check_mem_fence(addr, m->len); break; case MEM_PERCPU: /* do nothing */ break; case MEM_VMALLOC: _stp_check_mem_fence(addr, m->len); break; default: printk("SYSTEMTAP ERROR: Attempted to validate memory at addr %p len=%d with unknown allocation type.\n", addr, (int)m->len); } return; } #endif /* #define STP_MAXMEMORY 8192 */ /* * If STP_MAXMEMORY is defined to a value (stap -DSTP_MAXMEMORY=8192 * ...) then every memory allocation is checked to make sure the * systemtap module doesn't use more than STP_MAXMEMORY of memory. * STP_MAXMEMORY is specified in kilobytes, so, for example, '8192' * means that the systemtap module won't use more than 8 megabytes of * memory. * * Note 1: This size does include the size of the module itself, plus * any additional allocations. * * Note 2: Since we can't be ensured that the module transport is set * up when a memory allocation problem happens, this code can't * directly report an error back to a user (so instead it uses * 'printk'). If the modules transport has been set up, the code that * calls the memory allocation functions * (_stp_kmalloc/_stp_kzalloc/etc.) should report an error directly to * the user. * * Note 3: This only tracks direct allocations by the systemtap * runtime. This does not track indirect allocations (such as done by * kprobes/uprobes/etc. internals). */ #ifdef STP_MAXMEMORY #ifdef STAPCONF_MODULE_LAYOUT #define _STP_MODULE_CORE_SIZE (THIS_MODULE->core_layout.size) #elif defined(STAPCONF_GRSECURITY) #define _STP_MODULE_CORE_SIZE (THIS_MODULE->core_size_rw) #else #define _STP_MODULE_CORE_SIZE (THIS_MODULE->core_size) #endif #endif static void *_stp_kmalloc_gfp(size_t size, gfp_t gfp_mask) { void *ret; #ifdef DEBUG_MEMALLOC_MIGHT_SLEEP might_sleep(); #endif #ifdef STP_MAXMEMORY if ((_STP_MODULE_CORE_SIZE + _stp_allocated_memory + size) > (STP_MAXMEMORY * 1024)) { return NULL; } #endif #ifdef DEBUG_MEM ret = kmalloc(size + MEM_DEBUG_SIZE, gfp_mask); if (likely(ret)) { _stp_allocated_memory += size; ret = _stp_mem_debug_setup(ret, size, MEM_KMALLOC); } #else ret = kmalloc(size, gfp_mask); if (likely(ret)) { _stp_allocated_memory += size; } #endif return ret; } static void *_stp_kmalloc(size_t size) { return _stp_kmalloc_gfp(size, STP_ALLOC_FLAGS); } static void *_stp_kzalloc_gfp(size_t size, gfp_t gfp_mask) #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15) { void *ret; #ifdef STP_MAXMEMORY if ((_STP_MODULE_CORE_SIZE + _stp_allocated_memory + size) > (STP_MAXMEMORY * 1024)) { return NULL; } #endif #ifdef DEBUG_MEM ret = kmalloc(size + MEM_DEBUG_SIZE, gfp_mask); if (likely(ret)) { _stp_allocated_memory += size; ret = _stp_mem_debug_setup(ret, size, MEM_KMALLOC); memset (ret, 0, size); } #else ret = kmalloc(size, gfp_mask); if (likely(ret)) { _stp_allocated_memory += size; memset (ret, 0, size); } #endif /* DEBUG_MEM */ return ret; } #else /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15) */ { void *ret; #ifdef STP_MAXMEMORY if ((_STP_MODULE_CORE_SIZE + _stp_allocated_memory + size) > (STP_MAXMEMORY * 1024)) { return NULL; } #endif #ifdef DEBUG_MEM ret = kzalloc(size + MEM_DEBUG_SIZE, gfp_mask); if (likely(ret)) { _stp_allocated_memory += size; ret = _stp_mem_debug_setup(ret, size, MEM_KMALLOC); } #else ret = kzalloc(size, gfp_mask); if (likely(ret)) { _stp_allocated_memory += size; } #endif return ret; } #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15) */ static void *_stp_kzalloc(size_t size) { return _stp_kzalloc_gfp(size, STP_ALLOC_FLAGS); } #ifndef STAPCONF_VZALLOC static void *vzalloc(unsigned long size) { void *ret = vmalloc(size); if (ret) memset(ret, 0, size); return ret; } #endif static void *_stp_vzalloc(size_t size) { void *ret; #ifdef STP_MAXMEMORY if ((_STP_MODULE_CORE_SIZE + _stp_allocated_memory + size) > (STP_MAXMEMORY * 1024)) { return NULL; } #endif #ifdef DEBUG_MEM ret = vzalloc(size + MEM_DEBUG_SIZE); if (likely(ret)) { _stp_allocated_memory += size; ret = _stp_mem_debug_setup(ret, size, MEM_VMALLOC); } #else ret = vzalloc(size); if (likely(ret)) { _stp_allocated_memory += size; } #endif return ret; } #ifndef STAPCONF_VMALLOC_NODE static void *vmalloc_node(unsigned long size, int node __attribute__((unused))) { return vmalloc(size); } #endif #ifndef STAPCONF_VZALLOC_NODE static void *vzalloc_node(unsigned long size, int node) { void *ret = vmalloc_node(size, node); if (ret) memset(ret, 0, size); return ret; } #endif static void *_stp_vzalloc_node(size_t size, int node) { void *ret; #ifdef STP_MAXMEMORY if ((_STP_MODULE_CORE_SIZE + _stp_allocated_memory + size) > (STP_MAXMEMORY * 1024)) { return NULL; } #endif #ifdef DEBUG_MEM ret = vzalloc_node(size + MEM_DEBUG_SIZE, node); if (likely(ret)) { _stp_allocated_memory += size; ret = _stp_mem_debug_setup(ret, size, MEM_VMALLOC); } #else ret = vzalloc_node(size, node); if (likely(ret)) { _stp_allocated_memory += size; } #endif return ret; } #ifdef PCPU_MIN_UNIT_SIZE #define _STP_MAX_PERCPU_SIZE PCPU_MIN_UNIT_SIZE #else #define _STP_MAX_PERCPU_SIZE 131072 #endif /* Note, calls __alloc_percpu which may sleep and always uses GFP_KERNEL. */ static void *_stp_alloc_percpu(size_t size) { void *ret; if (size > _STP_MAX_PERCPU_SIZE) return NULL; #ifdef STP_MAXMEMORY if ((_STP_MODULE_CORE_SIZE + _stp_allocated_memory + (size * num_possible_cpus())) > (STP_MAXMEMORY * 1024)) { return NULL; } #endif #ifdef STAPCONF_ALLOC_PERCPU_ALIGN ret = __alloc_percpu(size, 8); #else ret = __alloc_percpu(size); #endif #ifdef DEBUG_MEM if (likely(ret)) { struct _stp_mem_entry *m = kmalloc(sizeof(struct _stp_mem_entry), GFP_KERNEL); if (unlikely(m == NULL)) { free_percpu(ret); return NULL; } _stp_allocated_memory += size * num_possible_cpus(); _stp_mem_debug_percpu(m, ret, size); } #else if (likely(ret)) { _stp_allocated_memory += size * num_possible_cpus(); } #endif return ret; } #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12) #define _stp_kmalloc_node(size,node) _stp_kmalloc(size) #define _stp_kmalloc_node_gfp(size,node,gfp) _stp_kmalloc_gfp(size,gfp) #define _stp_kzalloc_node(size,node) _stp_kzalloc(size) #define _stp_kzalloc_node_gfp(size,node,gfp) _stp_kzalloc_gfp(size,gfp) #else static void *_stp_kmalloc_node_gfp(size_t size, int node, gfp_t gfp_mask) { void *ret; #ifdef DEBUG_MEMALLOC_MIGHT_SLEEP might_sleep(); #endif #ifdef STP_MAXMEMORY if ((_STP_MODULE_CORE_SIZE + _stp_allocated_memory + size) > (STP_MAXMEMORY * 1024)) { return NULL; } #endif #ifdef DEBUG_MEM ret = kmalloc_node(size + MEM_DEBUG_SIZE, gfp_mask, node); if (likely(ret)) { _stp_allocated_memory += size; ret = _stp_mem_debug_setup(ret, size, MEM_KMALLOC); } #else ret = kmalloc_node(size, gfp_mask, node); if (likely(ret)) { _stp_allocated_memory += size; } #endif return ret; } static void *_stp_kzalloc_node_gfp(size_t size, int node, gfp_t gfp_mask) { /* This used to be simply: * return _stp_kmalloc_node_gfp(size, node, gfp_mask | __GFP_ZERO); * but rhel5-era kernels BUG out on that flag. (PR14957) * * We could make a big #if-alternation for kernels which have support * for kzalloc_node (kernel commit 979b0fea), as in _stp_kzalloc_gfp, * but IMO that's needlessly complex. * * So for now, just malloc and zero it manually. */ void *ret = _stp_kmalloc_node_gfp(size, node, gfp_mask); #ifdef DEBUG_MEMALLOC_MIGHT_SLEEP might_sleep(); #endif if (likely(ret)) { memset (ret, 0, size); } return ret; } static void *_stp_kmalloc_node(size_t size, int node) { return _stp_kmalloc_node_gfp(size, node, STP_ALLOC_FLAGS); } static void *_stp_kzalloc_node(size_t size, int node) { return _stp_kzalloc_node_gfp(size, node, STP_ALLOC_FLAGS); } #endif /* LINUX_VERSION_CODE */ static void _stp_kfree(void *addr) { #ifdef DEBUG_MEMALLOC_MIGHT_SLEEP might_sleep(); #endif #ifdef DEBUG_MEM _stp_mem_debug_free(addr, MEM_KMALLOC); #else kfree(addr); #endif } static void _stp_vfree(void *addr) { #ifdef DEBUG_MEMALLOC_MIGHT_SLEEP might_sleep(); #endif #ifdef DEBUG_MEM _stp_mem_debug_free(addr, MEM_VMALLOC); #else vfree(addr); #endif } static void _stp_free_percpu(void *addr) { #ifdef DEBUG_MEMALLOC_MIGHT_SLEEP might_sleep(); #endif #ifdef DEBUG_MEM _stp_mem_debug_free(addr, MEM_PERCPU); #else free_percpu(addr); #endif } static void _stp_mem_debug_done(void) { #ifdef DEBUG_MEM struct list_head *p, *tmp; struct _stp_mem_entry *m; unsigned long flags; stp_spin_lock_irqsave(&_stp_mem_lock, flags); list_for_each_safe(p, tmp, &_stp_mem_list) { m = list_entry(p, struct _stp_mem_entry, list); list_del(p); printk("SYSTEMTAP ERROR: Memory %p len=%d allocation type: %s. Not freed.\n", m->addr, (int)m->len, _stp_malloc_types[m->type].alloc); if (m->magic != MEM_MAGIC) { printk("SYSTEMTAP ERROR: Memory at %p len=%d corrupted!!\n", m->addr, (int)m->len); /* Don't free. Too dangerous */ goto done; } switch (m->type) { case MEM_KMALLOC: _stp_check_mem_fence(m->addr, m->len); kfree(m->addr - MEM_FENCE_SIZE); break; case MEM_PERCPU: free_percpu(m->addr); kfree(p); break; case MEM_VMALLOC: _stp_check_mem_fence(m->addr, m->len); vfree(m->addr - MEM_FENCE_SIZE); break; default: printk("SYSTEMTAP ERROR: Attempted to free memory at addr %p len=%d with unknown allocation type.\n", m->addr, (int)m->len); } } done: stp_spin_unlock_irqrestore(&_stp_mem_lock, flags); return; #endif } #endif /* _STAPLINUX_ALLOC_C_ */
Save
cmd:
run