void quadd_process_mmap(struct vm_area_struct *vma, pid_t pid) { int is_file_exists; struct file *vm_file; struct path *path; char *file_name, *tmp_buf = NULL; struct quadd_mmap_data sample; size_t length, length_aligned; if (!vma) return; if (!(vma->vm_flags & VM_EXEC)) return; tmp_buf = kzalloc(PATH_MAX + sizeof(u64), GFP_ATOMIC); if (!tmp_buf) return; vm_file = vma->vm_file; if (vm_file) { path = &vm_file->f_path; file_name = d_path(path, tmp_buf, PATH_MAX); if (IS_ERR(file_name)) goto out; length = strlen(file_name) + 1; is_file_exists = 1; } else { const char *name = NULL; name = arch_vma_name(vma); if (!name) { struct mm_struct *mm = vma->vm_mm; if (!mm) { name = "[vdso]"; } else if (vma->vm_start <= mm->start_brk && vma->vm_end >= mm->brk) { name = "[heap]"; } else if (vma->vm_start <= mm->start_stack && vma->vm_end >= mm->start_stack) { name = "[stack]"; } } if (name) strcpy(tmp_buf, name); else sprintf(tmp_buf, "[vma:%08lx-%08lx]", vma->vm_start, vma->vm_end); file_name = tmp_buf; length = strlen(file_name) + 1; is_file_exists = 0; } length_aligned = ALIGN(length, sizeof(u64)); sample.pid = pid; sample.user_mode = 1; sample.addr = vma->vm_start; sample.len = vma->vm_end - vma->vm_start; put_mmap_sample(&sample, file_name, length_aligned, vma->vm_pgoff, is_file_exists); out: kfree(tmp_buf); }
void show_pid_maps(struct task_struct *task) { struct task_struct *t; struct mm_struct *mm; struct vm_area_struct *vma; struct file *file; unsigned long long pgoff = 0; unsigned long ino = 0; dev_t dev = 0; int tpid = 0; char path_buf[256]; printk(KERN_ALERT "-----------------------------------------------------------\n"); if((0 == strcmp(current->comm, "BIServer"))|| (0 == strcmp(current->comm, "MainServer")) || (0 == strcmp(current->comm, "PDSServer")) || (0 == strcmp(current->comm, "AppUpdate"))) { printk(KERN_ALERT "* task->pid (%d)\n", task->pid); } else { printk(KERN_ALERT "* dump maps on pid (%d)\n", task->pid); } printk(KERN_ALERT "-----------------------------------------------------------\n"); if (!down_read_trylock(&task->mm->mmap_sem)) { printk(KERN_ALERT "down_read_trylock() failed... do not dump pid maps info\n"); return; } vma = task->mm->mmap; while (vma) { file = vma->vm_file; if (file) { struct inode *inode = file->f_dentry->d_inode; dev = inode->i_sb->s_dev; ino = inode->i_ino; pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT; } else { dev = 0; ino = 0; pgoff = 0; } printk(KERN_ALERT "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %-10lu ", vma->vm_start, vma->vm_end, vma->vm_flags & VM_READ ? 'r' : '-', vma->vm_flags & VM_WRITE ? 'w' : '-', vma->vm_flags & VM_EXEC ? 'x' : '-', vma->vm_flags & VM_MAYSHARE ? 's' : 'p', pgoff, MAJOR(dev), MINOR(dev), ino); if (file) { char* p = d_path(&(file->f_path),path_buf, 256); if (!IS_ERR(p)) printk("%s", p); } else { const char *name = arch_vma_name(vma); mm = vma->vm_mm; tpid = 0; if (!name) { if (mm) { if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) { name = "[heap]"; } else if (vma->vm_start <= mm->start_stack && vma->vm_end >= mm->start_stack) { name = "[stack]"; } else { t = task; do{ if (vma->vm_start <= t->user_ssp && vma->vm_end >= t->user_ssp){ tpid = t->pid; name = t->comm; break; } }while_each_thread(task, t); } } else { name = "[vdso]"; } } if (name) { if (tpid) printk("[tstack: %s: %d]", name, tpid); else printk("%s", name); } } printk( "\n"); vma = vma->vm_next; }
int quadd_get_current_mmap(pid_t pid) { int is_file_exists; struct vm_area_struct *vma; struct file *vm_file; struct path *path; char *file_name; struct task_struct *task; struct mm_struct *mm; struct quadd_mmap_data sample; size_t length, length_aligned; char *tmp_buf; rcu_read_lock(); task = pid_task(find_vpid(pid), PIDTYPE_PID); rcu_read_unlock(); if (!task) { pr_err("Process not found: %d\n", pid); return -ESRCH; } mm = task->mm; if (!mm) { pr_warn("mm is not existed for task: %d\n", pid); return 0; } pr_info("Get mapped memory objects\n"); tmp_buf = kzalloc(PATH_MAX + sizeof(u64), GFP_ATOMIC); if (!tmp_buf) return -ENOMEM; for (vma = mm->mmap; vma; vma = vma->vm_next) { if (!(vma->vm_flags & VM_EXEC)) continue; vm_file = vma->vm_file; if (vm_file) { path = &vm_file->f_path; file_name = d_path(path, tmp_buf, PATH_MAX); if (IS_ERR(file_name)) continue; length = strlen(file_name) + 1; is_file_exists = 1; } else { const char *name = NULL; name = arch_vma_name(vma); if (!name) { mm = vma->vm_mm; if (!mm) { name = "[vdso]"; } else if (vma->vm_start <= mm->start_brk && vma->vm_end >= mm->brk) { name = "[heap]"; } else if (vma->vm_start <= mm->start_stack && vma->vm_end >= mm->start_stack) { name = "[stack]"; } } if (name) strcpy(tmp_buf, name); else sprintf(tmp_buf, "[vma:%08lx-%08lx]", vma->vm_start, vma->vm_end); file_name = tmp_buf; length = strlen(file_name) + 1; is_file_exists = 0; } length_aligned = ALIGN(length, sizeof(u64)); sample.pid = pid; sample.user_mode = 1; sample.addr = vma->vm_start; sample.len = vma->vm_end - vma->vm_start; put_mmap_sample(&sample, file_name, length_aligned, vma->vm_pgoff, is_file_exists); } kfree(tmp_buf); return 0; }
static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid) { struct mm_struct *mm = vma->vm_mm; struct file *file = vma->vm_file; struct proc_maps_private *priv = m->private; vm_flags_t flags = vma->vm_flags; unsigned long ino = 0; unsigned long long pgoff = 0; unsigned long start, end; dev_t dev = 0; const char *name = NULL; if (file) { struct inode *inode = file_inode(vma->vm_file); dev = inode->i_sb->s_dev; ino = inode->i_ino; pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT; } /* We don't show the stack guard page in /proc/maps */ start = vma->vm_start; if (stack_guard_page_start(vma, start)) start += PAGE_SIZE; end = vma->vm_end; if (stack_guard_page_end(vma, end)) end -= PAGE_SIZE; seq_setwidth(m, 25 + sizeof(void *) * 6 - 1); seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ", start, end, flags & VM_READ ? 'r' : '-', flags & VM_WRITE ? 'w' : '-', flags & VM_EXEC ? 'x' : '-', flags & VM_MAYSHARE ? 's' : 'p', pgoff, MAJOR(dev), MINOR(dev), ino); /* * Print the dentry name for named mappings, and a * special [heap] marker for the heap: */ if (file) { seq_pad(m, ' '); seq_path(m, &file->f_path, "\n"); goto done; } if (vma->vm_ops && vma->vm_ops->name) { name = vma->vm_ops->name(vma); if (name) goto done; } name = arch_vma_name(vma); if (!name) { pid_t tid; if (!mm) { name = "[vdso]"; goto done; } if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) { name = "[heap]"; goto done; } tid = pid_of_stack(priv, vma, is_pid); if (tid != 0) { /* * Thread stack in /proc/PID/task/TID/maps or * the main process stack. */ if (!is_pid || (vma->vm_start <= mm->start_stack && vma->vm_end >= mm->start_stack)) { name = "[stack]"; } else { /* Thread stack in /proc/PID/maps */ seq_pad(m, ' '); seq_printf(m, "[stack:%d]", tid); } goto done; } if (vma_get_anon_name(vma)) { seq_pad(m, ' '); seq_print_vma_name(m, vma); } } done: if (name) { seq_pad(m, ' '); seq_puts(m, name); } seq_putc(m, '\n'); }
static ssize_t package_show(struct kobject *kobj, struct attribute *attr, char *buf) { ssize_t ret = 0; struct task_struct* process; struct mm_struct* mm; struct vm_area_struct* vm_area; struct file* file; int i; char *packbuf = NULL, *pack = NULL; char *binbuf = NULL, *bin = NULL; char *pathbuf = NULL, *path = NULL; char* p_data = NULL; int data_len = 0; int failed = 0; if(package_held_pid == -1) return 0; if(current->tgid != digest_manager_pid) return 0; sphinx_printk("held pid 2: %d\n", package_held_pid); do { packbuf = kmalloc(PATH_MAX, GFP_KERNEL); if(packbuf == NULL) break; binbuf = kmalloc(PATH_MAX, GFP_KERNEL); if(binbuf == NULL) break; pathbuf = kmalloc(PATH_MAX, GFP_KERNEL); if(pathbuf == NULL) break; p_data = kmalloc(DGSTMGRD_DATALIST_LENGTH, GFP_KERNEL); if(p_data == NULL) break; /* --- */ memset(packbuf, 0, PATH_MAX); memset(binbuf, 0, PATH_MAX); memset(pathbuf, 0, PATH_MAX); memset(p_data, 0, PATH_MAX); read_lock(&tasklist_lock); do { process = find_task_by_vpid(package_held_pid); if(process == NULL) break; if(process->mm == NULL) break; if(process->mm->mmap == NULL) break; bin = sphinx_detect_binary(process, binbuf); if(bin == NULL) break; if(!( strstr(bin, LOCAL_SPHINX_DIR_SYSTEMBIN) == bin || strstr(bin, LOCAL_SPHINX_DIR_SYSTEMSHBIN) == bin || strstr(bin, LOCAL_SPHINX_DIR_VENDORBIN) == bin || strstr(bin, LOCAL_SPHINX_DIR_SYSTEMAPP) == bin || strstr(bin, LOCAL_SPHINX_DIR_VENDORAPP) == bin || (strstr(bin, LOCAL_SPHINX_DIR_DATAAPP) == bin && strstr(bin, LOCAL_SPHINX_SUFFIX_APK) != NULL) || (strstr(bin, LOCAL_SPHINX_DIR_DATAAPPPRIVATE) == bin && strstr(bin, LOCAL_SPHINX_SUFFIX_APK) != NULL ) )) { break; } if(strcmp(bin, LOCAL_SPHINX_PATH_APPPROCESS) == 0) { pack = sphinx_detect_package(process, packbuf); if(pack == NULL) break; } mm = process->mm; vm_area = mm->mmap; for(i = 0; i < mm->map_count; i++, vm_area = vm_area->vm_next) { if(vm_area == NULL) break; if(vm_area->vm_flags & VM_EXEC) { file = vm_area->vm_file; if(file != NULL) { path = d_path(&file->f_path, pathbuf, PATH_MAX); if(path == NULL || (long)path == ENAMETOOLONG) { failed = 1; break; } sphinx_printk("path : %s\n", path); if(strcmp(path, "/dev/ashmem/dalvik-jit-code-cache") == 0) continue; if(strstr(path, LOCAL_SPHINX_DIR_SYSTEM) == path) continue; if(strstr(path, LOCAL_SPHINX_DIR_DATADATA) == path && strstr(path, "/lib/") != NULL && strstr(path, ".so") != NULL) { int l = strlen(path); if(data_len + l + 1 >= DGSTMGRD_DATALIST_LENGTH) { ret = 0; break; } snprintf(p_data + data_len, DGSTMGRD_DATALIST_LENGTH - 1, "\n%s", path); data_len = data_len + l + 1; } } else { const char *name = arch_vma_name(vm_area); if(name == NULL) { if(vm_area->vm_flags & VM_MAYSHARE) { failed = 1; break; } continue; } sphinx_printk("name : %s\n", name); if(strcmp(name, "[vectors]") != 0) { failed = 1; break; } } } } if(failed == 1) break; ret = strlen(bin); if(ret > 0) { sprintf(buf, "%s", bin); if(data_len > 0) { sprintf(buf + ret, "%s", p_data); ret += data_len; } } } while(0); read_unlock(&tasklist_lock); } while(0); if(pathbuf != NULL) { kfree(pathbuf); pathbuf = NULL; } if(binbuf != NULL) { kfree(binbuf); binbuf = NULL; } if(packbuf != NULL) { kfree(packbuf); packbuf = NULL; } if(p_data != NULL) { kfree(p_data); p_data = NULL; } /* --- */ package_held_pid = -1; sphinx_printk("package_show returns : %d\n", ret); return ret; }
void count_cpu_time(void) { if (unlikely(debug_cpu_usage_enable == 1 && (1000*(jiffies_64 - Last_checked_jiffies)/HZ >= CPU_USAGE_CHECK_INTERVAL_MS))) { struct task_struct * p = current; struct pt_regs *regs = get_irq_regs(); char cpu_info_msg[128] = {0}; int len = sizeof(cpu_info_msg); show_cpu_usage_and_freq(cpu_info_msg, len); if (likely(p != 0)) { if (regs != 0) { if (regs->ARM_pc <= TASK_SIZE) /* User space */ { struct mm_struct *mm = p->mm; struct vm_area_struct *vma; struct file *map_file = NULL; /* Parse vma information */ vma = find_vma(mm, regs->ARM_pc); if (vma != NULL) { map_file = vma->vm_file; if (map_file) /* memory-mapped file */ { printk(KERN_INFO "%sLR=0x%08lx PC=0x%08lx[U][%4d][%s][%s+0x%lx]\r\n", cpu_info_msg, regs->ARM_lr, regs->ARM_pc, (unsigned int) p->pid, p->comm, map_file->f_path.dentry->d_iname, regs->ARM_pc - vma->vm_start);/*Kernel-SC-add-cpuFreq-info-02**/ } else { const char *name = arch_vma_name(vma); if (!name) { if (mm) { if (vma->vm_start <= mm->start_brk && vma->vm_end >= mm->brk) { name = "heap"; } else if (vma->vm_start <= mm->start_stack && vma->vm_end >= mm->start_stack) { name = "stack"; } } else { name = "vdso"; } } printk(KERN_INFO "%sLR=0x%08lx PC=0x%08lx[U][%4d][%s][%s]\r\n", cpu_info_msg, regs->ARM_lr, regs->ARM_pc, (unsigned int) p->pid, p->comm, name);/*Kernel-SC-add-cpuFreq-info-02**/ } } } else /* Kernel space */ { printk(KERN_INFO "%sLR=0x%08lx PC=0x%08lx[K][%4d][%s]", cpu_info_msg, regs->ARM_lr, regs->ARM_pc, (unsigned int) p->pid, p->comm);/*Kernel-SC-add-cpuFreq-info-02**/ #ifdef CONFIG_KALLSYMS print_symbol("[%s]\r\n", regs->ARM_pc); #else printk(KERN_INFO "\r\n"); /* KERNEL-SC-debug-msg-00* */ #endif } } else /* Can't get PC & RA address */ { printk(KERN_INFO "%s[%s]\r\n", cpu_info_msg, p->comm);/*Kernel-SC-add-cpuFreq-info-02**/ } } else /* Can't get process information */ { printk(KERN_INFO "%sERROR: p=0x%08lx regs=0x%08lx\r\n", cpu_info_msg, (long)p, (long)regs);/*Kernel-SC-add-cpuFreq-info-02**/ } } }
void count_cpu_time(void){ if (unlikely(debug_cpu_usage_enable == 1 && (1000*(jiffies_64 - Last_checked_jiffies)/HZ >= CPU_USAGE_CHECK_INTERVAL_MS))) { struct task_struct * p = current; struct pt_regs *regs = get_irq_regs(); /*Kernel-SC-add-cpuFreq-info-01+[*/ unsigned long cpu_freq = acpuclk_get_rate(smp_processor_id()); unsigned long cpu_curr_freq = (unsigned long) cpufreq_quick_get(smp_processor_id()); /*Kernel-SC-add-cpuFreq-info-01+]*/ if (likely(p != 0)) { if (regs != 0) { if (regs->ARM_pc <= TASK_SIZE) /* User space */ { struct mm_struct *mm = p->mm; struct vm_area_struct *vma; struct file *map_file = NULL; /* Parse vma information */ vma = find_vma(mm, regs->ARM_pc); if (vma != NULL) { map_file = vma->vm_file; if (map_file) /* memory-mapped file */ { printk(KERN_INFO "[CPU] %3ld%% LR=0x%08lx PC=0x%08lx [U][%4d][%s][%s+0x%lx] CPUFreq=%lu CurrFreq=%lu\r\n", get_cpu_usage(), regs->ARM_lr, regs->ARM_pc, (unsigned int) p->pid, p->comm, map_file->f_path.dentry->d_iname, regs->ARM_pc - vma->vm_start, cpu_freq, cpu_curr_freq);/*Kernel-SC-add-cpuFreq-info-01**/ } else { const char *name = arch_vma_name(vma); if (!name) { if (mm) { if (vma->vm_start <= mm->start_brk && vma->vm_end >= mm->brk) { name = "heap"; } else if (vma->vm_start <= mm->start_stack && vma->vm_end >= mm->start_stack) { name = "stack"; } } else { name = "vdso"; } } printk(KERN_INFO "[CPU] %3ld%% LR=0x%08lx PC=0x%08lx [U][%4d][%s][%s] CPUFreq=%lu CurrFreq=%lu\r\n", get_cpu_usage(), regs->ARM_lr, regs->ARM_pc, (unsigned int) p->pid, p->comm, name, cpu_freq, cpu_curr_freq);/*Kernel-SC-add-cpuFreq-info-01**/ } } } else /* Kernel space */ { printk(KERN_INFO "[CPU] %3ld%% LR=0x%08lx PC=0x%08lx [K][%4d][%s] CPUFreq=%lu CurrFreq=%lu", get_cpu_usage(), regs->ARM_lr, regs->ARM_pc, (unsigned int) p->pid, p->comm, cpu_freq, cpu_curr_freq);/*Kernel-SC-add-cpuFreq-info-01**/ #ifdef CONFIG_KALLSYMS print_symbol("[%s]\r\n", regs->ARM_pc); #else printk("\r\n"); #endif } } else /* Can't get PC & RA address */ { printk(KERN_INFO "[CPU] %3ld%% [%s] CPUFreq=%lu CurrFreq=%lu\r\n", get_cpu_usage(), p->comm, cpu_freq, cpu_curr_freq);/*Kernel-SC-add-cpuFreq-info-01**/ } } else /* Can't get process information */ { printk(KERN_INFO "[CPU] %3ld%% ERROR: p=0x%08lx, regs=0x%08lx CPUFreq=%lu CurrFreq=%lu\r\n", get_cpu_usage(), (long)p, (long)regs, cpu_freq, cpu_curr_freq);/*Kernel-SC-add-cpuFreq-info-01**/ } } }