mirror of
https://github.com/sstefani/mtrace.git
synced 2025-12-06 16:56:41 +08:00
Consider page size in report_mmap / report_unmap.
mmaps are full of quirks ;-) - mmap(2) will always allocate whole memory pages, even if the caller only reuqests a partial page. This is considered by calculating the "real" size of the mmap. - munmap(2) also operates on pages, unmapping every page it "touches.", so the size parameter is adjusted if needed.
This commit is contained in:
parent
4007678321
commit
61a32cf95e
20
report.c
20
report.c
@ -241,6 +241,9 @@ static void _report_calloc(struct task *task, struct library_symbol *libsym)
|
|||||||
report_alloc(task, MT_MALLOC, ret, size, options.bt_depth, libsym);
|
report_alloc(task, MT_MALLOC, ret, size, options.bt_depth, libsym);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static ssize_t arch_pagesize = -1;
|
||||||
|
|
||||||
static void _report_mmap(struct task *task, struct library_symbol *libsym)
|
static void _report_mmap(struct task *task, struct library_symbol *libsym)
|
||||||
{
|
{
|
||||||
unsigned long ret = fetch_retval(task);
|
unsigned long ret = fetch_retval(task);
|
||||||
@ -249,6 +252,11 @@ static void _report_mmap(struct task *task, struct library_symbol *libsym)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
unsigned long size = fetch_param(task, 1);
|
unsigned long size = fetch_param(task, 1);
|
||||||
|
if (unlikely(arch_pagesize==-1)) arch_pagesize=getpagesize();
|
||||||
|
// fixup size, if size is not a multiple of the pagesize, we get the "partial" page too. -
|
||||||
|
if (size % arch_pagesize) {
|
||||||
|
size += arch_pagesize - size % arch_pagesize;
|
||||||
|
}
|
||||||
|
|
||||||
report_alloc(task, MT_MMAP, ret, size, options.bt_depth, libsym);
|
report_alloc(task, MT_MMAP, ret, size, options.bt_depth, libsym);
|
||||||
}
|
}
|
||||||
@ -277,6 +285,12 @@ static void _report_mmap64(struct task *task, struct library_symbol *libsym)
|
|||||||
else
|
else
|
||||||
size.l = fetch_param(task, 1);
|
size.l = fetch_param(task, 1);
|
||||||
|
|
||||||
|
if (unlikely(arch_pagesize == -1)) arch_pagesize=getpagesize();
|
||||||
|
// fixup size, if size is not a multiple of the pagesize, we get the "partial" page too. -
|
||||||
|
if (size.l % arch_pagesize) {
|
||||||
|
size.l += arch_pagesize - size.l % arch_pagesize;
|
||||||
|
}
|
||||||
|
|
||||||
report_alloc(task, MT_MMAP64, ret, size.l, options.bt_depth, libsym);
|
report_alloc(task, MT_MMAP64, ret, size.l, options.bt_depth, libsym);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,6 +298,12 @@ static void report_munmap(struct task *task, struct library_symbol *libsym)
|
|||||||
{
|
{
|
||||||
unsigned long addr = fetch_param(task, 0);
|
unsigned long addr = fetch_param(task, 0);
|
||||||
unsigned long size = fetch_param(task, 1);
|
unsigned long size = fetch_param(task, 1);
|
||||||
|
if (unlikely(arch_pagesize==-1)) arch_pagesize=getpagesize();
|
||||||
|
|
||||||
|
// fixup size, if needed: all pages in [addr, addr+size] are unmapped -- see munmap(2)
|
||||||
|
if (size % arch_pagesize) {
|
||||||
|
size += arch_pagesize - size % arch_pagesize;
|
||||||
|
}
|
||||||
|
|
||||||
report_alloc(task, MT_MUNMAP, addr, size, 0, libsym);
|
report_alloc(task, MT_MUNMAP, addr, size, 0, libsym);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user