--- zzzz-none-000/linux-4.19.183/mm/slab.c 2021-03-24 10:07:39.000000000 +0000 +++ bcm63-7530ax-756/linux-4.19.183/mm/slab.c 2023-06-28 08:54:21.000000000 +0000 @@ -123,6 +123,10 @@ #include #include #include +#if defined(CONFIG_AVM_ENHANCED) +#include +#endif/*--- #if defined(CONFIG_AVM_ENHANCED) ---*/ + #include @@ -4489,3 +4493,59 @@ return size; } EXPORT_SYMBOL(ksize); + +#if defined(CONFIG_AVM_ENHANCED) +/** + * @brief get kmemalloc-area if addr in range + * attention! function unsaved for cachep - zone-page-spinlock necessary + * @return start (zero if not exist) + */ +unsigned long get_kmemalloc_area(unsigned long addr, unsigned long *caller, const char **cache_name, + unsigned long *size, int *freed){ + unsigned long flags, kstart; + struct kmem_cache_node *n; + unsigned int objnr, _freed = 0; + struct kmem_cache *cachep; + struct page *page = virt_to_head_page((void *)addr); + + if(!virt_addr_valid(page)) { + return 0; + } + cachep = page->slab_cache; + if(!virt_addr_valid(cachep)) { + return 0; + } + n = cachep->node[numa_mem_id()]; + if(!virt_addr_valid(n)) { + return 0; + } + if(!spin_trylock_irqsave(&n->list_lock, flags)) { + return 0; + } + objnr = obj_to_index(cachep, page, (void *)addr); + if(objnr >= cachep->num) { + spin_unlock_irqrestore(&n->list_lock, flags); + return 0; + } + if(caller) { +#if defined(CONFIG_DEBUG_SLAB_DOUBLE_FREE) || defined(CONFIG_DEBUG_SLAB_LEAK) + if (get_obj_status(page, objnr) != OBJECT_ACTIVE) { + _freed = 1; + } +#endif/*--- #if defined(CONFIG_DEBUG_SLAB_DOUBLE_FREE) || defined(CONFIG_DEBUG_SLAB_LEAK) ---*/ + *caller = +#if defined(CONFIG_DEBUG_SLAB_AVM_LITE) + _freed ? get_slab_enh(cachep, page, objnr)->free_caller : get_slab_enh(cachep, page, objnr)->caller; +#else /*--- #if defined(CONFIG_DEBUG_SLAB_AVM_LITE) ---*/ + 0UL; +#endif /*--- #else ---*//*--- #if defined(CONFIG_DEBUG_SLAB_AVM_LITE) ---*/ + } + /*--- dump_slab("slab", page, cachep, objnr); ---*/ + if(cache_name) *cache_name = cachep->name; + if(size) *size = cachep->size; + if(freed) *freed = _freed; + kstart = (unsigned long)index_to_obj(cachep, page, objnr); + spin_unlock_irqrestore(&n->list_lock, flags); + return kstart; +} +#endif /*--- #if defined(CONFIG_AVM_ENHANCED) ---*/