static void file_delete (struct VdlFile *file, bool mapping) { vdl_context_remove_file (file->context, file); vdl_linkmap_remove (file); if (mapping) { void **i; for (i = vdl_list_begin (file->maps); i != vdl_list_end (file->maps); i = vdl_list_next (file->maps, i)) { struct VdlFileMap *map = *i; struct VdlFileAddress *ret, *address = vdl_alloc_new (struct VdlFileAddress); address->key = map->mem_start_align; ret = vdl_rbfind (g_vdl.address_ranges, address); vdl_rberase (g_vdl.address_ranges, ret); vdl_alloc_delete (address); int status = system_munmap ((void *) map->mem_start_align, map->mem_size_align); if (status == -1) { VDL_LOG_ERROR ("unable to unmap map 0x%lx[0x%lx] for \"%s\"\n", map->mem_start_align, map->mem_size_align, file->filename); } } } if (vdl_context_empty (file->context)) { vdl_context_delete (file->context); } vdl_list_delete (file->deps); vdl_list_delete (file->local_scope); vdl_list_delete (file->gc_symbols_resolved_in); vdl_alloc_free (file->name); vdl_alloc_free (file->filename); vdl_alloc_free (file->phdr); vdl_list_iterate (file->maps, vdl_alloc_free); vdl_list_delete (file->maps); rwlock_delete (file->lock); file->deps = 0; file->local_scope = 0; file->gc_symbols_resolved_in = 0; file->name = 0; file->filename = 0; file->context = 0; file->phdr = 0; file->phnum = 0; file->maps = 0; file->lock = 0; vdl_alloc_delete (file); }
void system_munmap_huge_pages(void *UNUSED, void *addr, size_t size) { #ifdef HAVE_HUGETLBFS if (size & _hugepage_mask) { long r = size & _hugepage_mask; long padding = _hugepage_size - r; size += padding; } #endif system_munmap(UNUSED, addr, size); }
void alloc_destroy (struct Alloc *alloc) { struct AllocMmapChunk *tmp, *next; for (tmp = alloc->chunks; tmp != 0; tmp = next) { next = tmp->next; system_munmap (tmp->buffer, tmp->size); } alloc->chunks = 0; futex_destruct (&alloc->futex); }
static void file_delete (struct VdlFile *file, bool mapping) { vdl_context_remove_file (file->context, file); if (mapping) { void **i; for (i = vdl_list_begin (file->maps); i != vdl_list_end (file->maps); i = vdl_list_next (i)) { struct VdlFileMap *map = *i; int status = system_munmap ((void*)map->mem_start_align, map->mem_size_align); if (status == -1) { VDL_LOG_ERROR ("unable to unmap map 0x%lx[0x%lx] for \"%s\"\n", map->mem_start_align, map->mem_size_align, file->filename); } } } if (vdl_context_empty (file->context)) { vdl_context_delete (file->context); } vdl_list_delete (file->deps); vdl_list_delete (file->local_scope); vdl_list_delete (file->gc_symbols_resolved_in); vdl_alloc_free (file->name); vdl_alloc_free (file->filename); vdl_alloc_free (file->phdr); vdl_list_iterate (file->maps, vdl_alloc_free); vdl_list_delete (file->maps); file->deps = 0; file->local_scope = 0; file->gc_symbols_resolved_in = 0; file->name = 0; file->filename = 0; file->context = 0; file->phdr = 0; file->phnum = 0; file->maps = 0; vdl_alloc_delete (file); }
static void alloc_do_free (struct Alloc *alloc, uint8_t * buffer, uint32_t size) { if (size < (alloc->default_mmap_size - chunk_overhead ())) { // return to bucket list. uint8_t bucket = size_to_bucket (size); struct AllocAvailable *avail = (struct AllocAvailable *) buffer; avail->next = alloc->buckets[bucket]; alloc->buckets[bucket] = avail; REPORT_FREE (buffer); } else { struct AllocMmapChunk *tmp, *prev; for (tmp = alloc->chunks, prev = 0; tmp != 0; prev = tmp, tmp = tmp->next) { if (tmp->buffer == buffer && tmp->size == size) { if (prev == 0) { alloc->chunks = tmp->next; } else { prev->next = tmp->next; } REPORT_FREE (buffer); system_munmap (tmp->buffer, tmp->size); return; } } // this should never happen but it happens in case of a double-free REPORT_FREE (buffer); } }