From e94d2266425235c037016b6585478e058e8aa2e4 Mon Sep 17 00:00:00 2001 From: Anastasia Lyupa Date: Thu, 10 Oct 2013 15:08:49 +0400 Subject: [PATCH] [PROTO] update msg_process_info, add sending it and remove binary type field, add ppid field Change-Id: I738b3faf4c9427be43b10c7cff82de2aa292d4ca Signed-off-by: Anastasia Lyupa --- us_manager/pf/pf_group.c | 21 ++++++++++---- us_manager/pf/proc_filters.c | 8 +++++ us_manager/pf/proc_filters.h | 1 + writer/swap_writer_module.c | 69 ++++++++++++++++++++++---------------------- writer/swap_writer_module.h | 2 +- 5 files changed, 61 insertions(+), 40 deletions(-) diff --git a/us_manager/pf/pf_group.c b/us_manager/pf/pf_group.c index ca50fae..fe9e273 100644 --- a/us_manager/pf/pf_group.c +++ b/us_manager/pf/pf_group.c @@ -32,6 +32,7 @@ #include #include #include +#include struct pf_group { struct list_head list; @@ -217,9 +218,8 @@ EXPORT_SYMBOL_GPL(pf_unregister_probe); void call_page_fault(struct task_struct *task, unsigned long page_addr) { - struct pf_group *pfg; + struct pf_group *pfg, *pfg_first = NULL; struct sspt_proc *proc = NULL; - int install_all = 0; list_for_each_entry(pfg, &pfg_list, list) { if (check_task_f(pfg->filter, task) == NULL) @@ -228,15 +228,26 @@ void call_page_fault(struct task_struct *task, unsigned long page_addr) proc = get_proc_by_pfg(pfg, task); if (proc == NULL) { proc = new_proc_by_pfg(pfg, task); - install_all = 1; + pfg_first = pfg; } } if (proc) { - if (install_all) + if (pfg_first) { + struct dentry *dentry; + + dentry = get_dentry_by_pf(pfg_first->filter); + if (dentry == NULL) { + dentry = task->mm->exe_file ? + task->mm->exe_file->f_dentry : + NULL; + } + + proc_info_msg(task, dentry); sspt_proc_install(proc); - else + } else { sspt_proc_install_page(proc, page_addr); + } } } diff --git a/us_manager/pf/proc_filters.c b/us_manager/pf/proc_filters.c index 3922b0e..cb501a3 100644 --- a/us_manager/pf/proc_filters.c +++ b/us_manager/pf/proc_filters.c @@ -113,3 +113,11 @@ int check_pf_by_tgid(struct proc_filter *filter, pid_t tgid) { return filter->data == (void *)tgid && filter->call == &call_by_tgid; } + +struct dentry *get_dentry_by_pf(struct proc_filter *filter) +{ + if (filter->call == &call_by_dentry) + return (struct dentry *)filter->data; + + return NULL; +} diff --git a/us_manager/pf/proc_filters.h b/us_manager/pf/proc_filters.h index 3653107..94673be 100644 --- a/us_manager/pf/proc_filters.h +++ b/us_manager/pf/proc_filters.h @@ -45,5 +45,6 @@ void free_pf(struct proc_filter *pf); int check_pf_by_dentry(struct proc_filter *filter, struct dentry *dentry); int check_pf_by_tgid(struct proc_filter *filter, pid_t tgid); +struct dentry *get_dentry_by_pf(struct proc_filter *filter); #endif /* _PROC_FILTERS_H */ diff --git a/writer/swap_writer_module.c b/writer/swap_writer_module.c index 4d1ca60..148d130 100644 --- a/writer/swap_writer_module.c +++ b/writer/swap_writer_module.c @@ -187,11 +187,11 @@ static char* pack_basic_msg_fmt(char *buf, enum MSG_ID id) struct proc_info { u32 pid; - u64 start_time; + u32 ppid; + u32 start_sec; + u32 start_nsec; u64 low_addr; u64 high_addr; - u32 app_type; - u32 bin_type; char bin_path[0]; } __attribute__((packed)); @@ -230,7 +230,6 @@ static char *pack_path(char *buf, struct file *file) static char *pack_lib_obj(char *lib_obj, struct vm_area_struct *vma) { struct lib_obj *lo = (struct lib_obj *)lib_obj; - struct file *file; lo->low_addr = vma->vm_start; lo->high_addr = vma->vm_end; @@ -242,83 +241,85 @@ static char *pack_lib_obj(char *lib_obj, struct vm_area_struct *vma) static int check_vma(struct vm_area_struct *vma) { return vma->vm_file && !(vma->vm_pgoff != 0 || !(vma->vm_flags & VM_EXEC) || (vma->vm_flags & VM_ACCOUNT) || - !(vma->vm_flags & (VM_WRITE | VM_MAYWRITE)) || !(vma->vm_flags & (VM_READ | VM_MAYREAD))); } -static struct vm_area_struct *find_vma_by_dentry(struct mm_struct *mm, - struct dentry *dentry) +static struct vm_area_struct *find_vma_exe_by_dentry(struct mm_struct *mm, struct dentry *dentry) { struct vm_area_struct *vma; - down_write(&mm->mmap_sem); + down_read(&mm->mmap_sem); for (vma = mm->mmap; vma; vma = vma->vm_next) { - if (check_vma(vma) && vma->vm_file && - (vma->vm_file->f_dentry == dentry)) + if (vma->vm_file && (vma->vm_flags & VM_EXEC) && + (vma->vm_file->f_dentry == dentry)) goto out; } vma = NULL; - out: - up_write(&mm->mmap_sem); + up_read(&mm->mmap_sem); return vma; } -static char *pack_proc_info_part(char *bin_path, struct mm_struct *mm) +static char *pack_proc_info_part(char *end_path, struct mm_struct *mm) { struct proc_info_part *pip; struct vm_area_struct *vma; - char *lib_obj, *end_path = NULL; + char *lib_obj; int lib_cnt = 0; - char bin_path_def[] = ""; - - memcpy(bin_path, bin_path_def, sizeof(bin_path_def)); - end_path = bin_path + sizeof(bin_path_def); pip = (struct proc_info_part *)end_path; lib_obj = pip->libs; - down_write(&mm->mmap_sem); + down_read(&mm->mmap_sem); for (vma = mm->mmap; vma; vma = vma->vm_next) { if (check_vma(vma)) { lib_obj = pack_lib_obj(lib_obj, vma); ++lib_cnt; } } - up_write(&mm->mmap_sem); + up_read(&mm->mmap_sem); pip->lib_cnt = lib_cnt; return lib_obj; } static char *pack_proc_info(char *payload, struct task_struct *task, - void *priv) + struct dentry *dentry) { struct proc_info *pi = (struct proc_info *)payload; - struct dentry *dentry_exec = (struct dentry *)priv; - struct vm_area_struct *vma = find_vma_by_dentry(task->mm, dentry_exec); + struct vm_area_struct *vma = find_vma_exe_by_dentry(task->mm, dentry); + struct timespec current_time; + char *end_path = NULL; pi->pid = task->tgid; - - /* FIXME: */ - pi->start_time = timespec2time(&task->start_time); - pi->low_addr = vma ? vma->vm_start : 0; - pi->high_addr = vma ? vma->vm_end : 0; - pi->app_type = 1; /* TODO: hardcode for Tizen*/ - pi->bin_type = 0; /* TODO: determined in US */ - - return pack_proc_info_part(pi->bin_path, task->mm); + pi->ppid = task->real_parent->tgid; + + /* FIXME: pi->start_time: take into account task->start_time, system uptime */ + getnstimeofday(¤t_time); + pi->start_sec = (u32)current_time.tv_sec; + pi->start_nsec = (u32)current_time.tv_nsec; + + if (vma) { + pi->low_addr = vma->vm_start; + pi->high_addr = vma->vm_end; + end_path = pack_path(pi->bin_path, vma->vm_file); + } else { + pi->low_addr = 0; + pi->high_addr = 0; + end_path = pack_path(pi->bin_path, NULL); + } + return pack_proc_info_part(end_path, task->mm); } -int proc_info_msg(struct task_struct *task, void *priv) +int proc_info_msg(struct task_struct *task, struct dentry *dentry) { char *buf, *payload, *buf_end; buf = get_current_buf(); payload = pack_basic_msg_fmt(buf, MSG_PROC_INFO); - buf_end = pack_proc_info(payload, task, priv); + buf_end = pack_proc_info(payload, task, dentry); set_len_msg(buf, buf_end); diff --git a/writer/swap_writer_module.h b/writer/swap_writer_module.h index ca50216..13e8d78 100644 --- a/writer/swap_writer_module.h +++ b/writer/swap_writer_module.h @@ -52,7 +52,7 @@ void reset_discarded(void); unsigned int get_discarded_count(void); void reset_seq_num(void); -int proc_info_msg(struct task_struct *task, void *priv); +int proc_info_msg(struct task_struct *task, struct dentry *dentry); int sample_msg(struct pt_regs *regs); int entry_event(const char *fmt, struct pt_regs *regs, -- 2.7.4