debug_kmemleak.c 785 B

123456789101112131415161718192021222324252627282930
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Module kmemleak support
  4. *
  5. * Copyright (C) 2009 Catalin Marinas
  6. */
  7. #include <linux/module.h>
  8. #include <linux/kmemleak.h>
  9. #include "internal.h"
  10. void kmemleak_load_module(const struct module *mod,
  11. const struct load_info *info)
  12. {
  13. unsigned int i;
  14. /* only scan the sections containing data */
  15. kmemleak_scan_area(mod, sizeof(struct module), GFP_KERNEL);
  16. for (i = 1; i < info->hdr->e_shnum; i++) {
  17. /* Scan all writable sections that's not executable */
  18. if (!(info->sechdrs[i].sh_flags & SHF_ALLOC) ||
  19. !(info->sechdrs[i].sh_flags & SHF_WRITE) ||
  20. (info->sechdrs[i].sh_flags & SHF_EXECINSTR))
  21. continue;
  22. kmemleak_scan_area((void *)info->sechdrs[i].sh_addr,
  23. info->sechdrs[i].sh_size, GFP_KERNEL);
  24. }
  25. }