mremap handling in case of error and creating a duplicate mapping.

- mremap can fail, in this case the old mapping is retained.
- mremap, when oldsize is 0, a new mapping is created without freeing
the old one.

See mremap(2) for details.
This commit is contained in:
Tobias Frost 2022-06-22 15:17:48 +02:00
parent f090e95e83
commit 871a79f35b

View File

@ -369,20 +369,20 @@ static void _report_pvalloc(struct task *task, struct library_symbol *libsym)
return report_alloc(task, MT_PVALLOC, ret, size, options.bt_depth, libsym);
}
static void report_mremap(struct task *task, struct library_symbol *libsym)
{
unsigned long addr = fetch_param(task, 0);
unsigned long size = fetch_param(task, 1);
report_alloc(task, MT_MUNMAP, addr, size, 0, libsym);
}
static void _report_mremap(struct task *task, struct library_symbol *libsym)
{
unsigned long size = fetch_param(task, 2);
unsigned long addr = fetch_param(task, 0);
unsigned long oldsize = fetch_param(task, 1);
unsigned long newsize = fetch_param(task, 2);
unsigned long ret = fetch_retval(task);
report_alloc(task, MT_MMAP, ret, size, options.bt_depth, libsym);
if( (void*)ret != MAP_FAILED) {
// mremap(2): if oldsize is zero and the mapping a shared mapping, a new mapping
// (Of the existing) will be created.
if (oldsize) report_alloc(task, MT_MUNMAP, addr, oldsize, 0, libsym);
report_alloc(task, MT_MMAP, ret, newsize, options.bt_depth, libsym);
}
}
static const struct function flist[] = {
@ -398,7 +398,7 @@ static const struct function flist[] = {
{ "aligned_alloc", "aligned_alloc", 1, NULL, _report_aligned_alloc },
{ "valloc", "valloc", 1, NULL, _report_valloc },
{ "pvalloc", "pvalloc", 1, NULL, _report_pvalloc },
{ "mremap", "mremap", 0, report_mremap, _report_mremap },
{ "mremap", "mremap", 0, NULL, _report_mremap },
{ "cfree", "cfree", 1, report_free, NULL },
{ "reallocarray", "reallocarray", 0, NULL, _report_reallocarray },
#if 0