Skip to content

Instantly share code, notes, and snippets.

@yhnu
Created September 28, 2021 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yhnu/33abe9f268087b8753288fd535a2bf2f to your computer and use it in GitHub Desktop.
Save yhnu/33abe9f268087b8753288fd535a2bf2f to your computer and use it in GitHub Desktop.
static int print_map_list()
{
struct mm_struct *mm;
struct vm_area_struct *vma;
char path_buf[PATH_MAX];
// DEFINE_HASHTABLE(htable, 3);
// hash_init(htable);
mm = get_task_mm(current);
if (!mm)
{
return -2;
}
down_read(&mm->mmap_sem);
for (vma = mm->mmap; vma; vma = vma->vm_next) {
unsigned long start, end;
unsigned char flags[5]={0};
// unsigned long int id;
// bool bFound;
start = vma->vm_start;
end = vma->vm_end;
flags[0] = vma->vm_flags & VM_READ ? 'r' : '-';
flags[1] = vma->vm_flags & VM_WRITE ? 'w' : '-';
flags[2] = vma->vm_flags & VM_EXEC ? 'x' : '-';
flags[3] = vma->vm_flags & VM_SHARED ? 's' : 'p';
if (vma->vm_file) {
char *path;
int len;
memset(path_buf, 0, sizeof(path_buf));
path = d_path(&vma->vm_file->f_path, path_buf, sizeof(path_buf));
len = strlen(path);
if (path > 0 && !strncmp(path+len-3, ".so", strlen(".so"))) { // endswith .so
// struct so_map *cur;
// id = myhash(path);
// bFound = false;
printk("[m]%pS-%pS %s %s\n", start, end, flags, path);
// hash_for_each_possible(htable, cur, node, id) {
// if(id == cur->id) {
// //pr_info("get: element: base = %pS, name = %s, id=%ld, targetid=%ld\n", cur->base, cur->name, cur->id, id);
// if(cur->base > start) {
// cur->base = start;
// }
// bFound = true;
// break;
// }
// }
// if(!bFound) {
// struct so_map *obj;
// obj = (struct so_map*)kmalloc(sizeof(struct so_map), GFP_KERNEL);
// obj->id = id;
// obj->base = start;
// strcpy(obj->name, path);
// //pr_info("add: element: base = %d, name = %s, id=%ld\n", obj.base, obj.name, obj.id);
// hash_add(htable, &obj->node, obj->id);
// }
} else {
printk("[m]%pS-%pS %s %s\n", start, end, flags, "");
}
}
} // end for
// do {
// struct so_map *cur;
// unsigned bkt;
// hash_for_each(htable, bkt, cur, node) {
// //do it offline
// //pr_info("%s, base = %pS\n", cur->name, cur->base);
// kfree(cur);
// }
// } while(0);
up_read(&mm->mmap_sem);
mmput(mm);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment