-static void set_ip_kp_addr(struct us_ip *ip, struct page_probes *page_p, const struct file_probes *file_p)
+static void set_ip_kp_addr(struct us_ip *ip, struct page_probes *page_p, const struct sspt_file *file)
{
- unsigned long addr = file_p->vm_start + page_p->offset + ip->offset;
+ unsigned long addr = file->vm_start + page_p->offset + ip->offset;
ip->retprobe.kp.addr = ip->jprobe.kp.addr = addr;
}
-static void page_p_set_all_kp_addr(struct page_probes *page_p, const struct file_probes *file_p)
+static void page_p_set_all_kp_addr(struct page_probes *page_p, const struct sspt_file *file)
{
struct us_ip *ip;
unsigned long addr;
list_for_each_entry(ip, &page_p->ip_list, list) {
- addr = file_p->vm_start + page_p->offset + ip->offset;
+ addr = file->vm_start + page_p->offset + ip->offset;
ip->retprobe.kp.addr = ip->jprobe.kp.addr = addr;
// printk("### pp_set_all_kp_addr: start=%x, page_offset=%x, ip_offset=%x, addr=%x\n",
// file_p->vm_start, page_p->offset, ip->offset, addr);
static const char *NA = "N/A";
-static void print_file_probes(const struct file_probes *file_p)
+static void print_file_probes(const struct sspt_file *file)
{
int i, table_size;
struct page_probes *page_p = NULL;
struct hlist_node *node = NULL;
struct hlist_head *head = NULL;
- if (file_p == NULL) {
+ if (file == NULL) {
printk("### file_p == NULL\n");
return;
}
- table_size = (1 << file_p->page_probes_hash_bits);
- const char *name = (file_p->dentry) ? file_p->dentry->d_iname : NA;
+ table_size = (1 << file->page_probes_hash_bits);
+ const char *name = (file->dentry) ? file->dentry->d_iname : NA;
printk("### print_file_probes: path=%s, d_iname=%s, table_size=%d, vm_start=%x\n",
- file_p->path, name, table_size, file_p->vm_start);
+ file->path, name, table_size, file->vm_start);
for (i = 0; i < table_size; ++i) {
- head = &file_p->page_probes_table[i];
+ head = &file->page_probes_table[i];
hlist_for_each_entry_rcu(page_p, node, head, hlist) {
print_page_probes(page_p);
}
static void print_proc_probes(const struct sspt_procs *procs)
{
- struct file_probes *file_p;
+ struct sspt_file *file;
printk("### print_proc_probes\n");
- list_for_each_entry(file_p, &procs->file_list, list) {
- print_file_probes(file_p);
+ list_for_each_entry(file, &procs->file_list, list) {
+ print_file_probes(file);
}
printk("### print_proc_probes\n");
}
return bits;
}
-struct file_probes *file_p_new(const char *path, struct dentry *dentry, int page_cnt)
+struct sspt_file *file_p_new(const char *path, struct dentry *dentry, int page_cnt)
{
- struct file_probes *obj = kmalloc(sizeof(*obj), GFP_ATOMIC);
+ struct sspt_file *obj = kmalloc(sizeof(*obj), GFP_ATOMIC);
if (obj) {
int i, table_size;
return obj;
}
-void file_p_del(struct file_probes *file_p)
+void file_p_del(struct sspt_file *file)
{
struct hlist_node *p, *n;
struct hlist_head *head;
struct page_probes *page_p;
- int i, table_size = (1 << file_p->page_probes_hash_bits);
+ int i, table_size = (1 << file->page_probes_hash_bits);
for (i = 0; i < table_size; ++i) {
- head = &file_p->page_probes_table[i];
+ head = &file->page_probes_table[i];
hlist_for_each_entry_safe(page_p, p, n, head, hlist) {
hlist_del(&page_p->hlist);
page_p_del(page_p);
}
}
- kfree(file_p->page_probes_table);
- kfree(file_p);
+ kfree(file->page_probes_table);
+ kfree(file);
}
-static void file_p_add_page_p(struct file_probes *file_p, struct page_probes *page_p)
+static void file_p_add_page_p(struct sspt_file *file, struct page_probes *page_p)
{
- hlist_add_head(&page_p->hlist, &file_p->page_probes_table[hash_ptr(page_p->offset, file_p->page_probes_hash_bits)]);
+ hlist_add_head(&page_p->hlist, &file->page_probes_table[hash_ptr(page_p->offset, file->page_probes_hash_bits)]);
}
-struct file_probes *file_p_copy(const struct file_probes *file_p)
+struct sspt_file *file_p_copy(const struct sspt_file *file)
{
- struct file_probes *file_p_out;
+ struct sspt_file *file_out;
- if (file_p == NULL) {
+ if (file == NULL) {
printk("### WARNING: file_p == NULL\n");
return NULL;
}
- file_p_out = kmalloc(sizeof(*file_p_out), GFP_ATOMIC);
- if (file_p_out) {
+ file_out = kmalloc(sizeof(*file_out), GFP_ATOMIC);
+ if (file_out) {
struct page_probes *page_p = NULL;
struct hlist_node *node = NULL;
struct hlist_head *head = NULL;
int i, table_size;
- INIT_LIST_HEAD(&file_p_out->list);
- file_p_out->dentry = file_p->dentry;
- file_p_out->path = file_p->path;
- file_p_out->loaded = 0;
- file_p_out->vm_start = 0;
- file_p_out->vm_end = 0;
+ INIT_LIST_HEAD(&file_out->list);
+ file_out->dentry = file->dentry;
+ file_out->path = file->path;
+ file_out->loaded = 0;
+ file_out->vm_start = 0;
+ file_out->vm_end = 0;
- file_p_out->page_probes_hash_bits = file_p->page_probes_hash_bits;
- table_size = (1 << file_p_out->page_probes_hash_bits);
+ file_out->page_probes_hash_bits = file->page_probes_hash_bits;
+ table_size = (1 << file_out->page_probes_hash_bits);
- file_p_out->page_probes_table =
- kmalloc(sizeof(*file_p_out->page_probes_table)*table_size, GFP_ATOMIC);
+ file_out->page_probes_table =
+ kmalloc(sizeof(*file_out->page_probes_table)*table_size, GFP_ATOMIC);
for (i = 0; i < table_size; ++i) {
- INIT_HLIST_HEAD(&file_p_out->page_probes_table[i]);
+ INIT_HLIST_HEAD(&file_out->page_probes_table[i]);
}
// copy pages
for (i = 0; i < table_size; ++i) {
- head = &file_p->page_probes_table[i];
+ head = &file->page_probes_table[i];
hlist_for_each_entry(page_p, node, head, hlist) {
- file_p_add_page_p(file_p_out, page_p_copy(page_p));
+ file_p_add_page_p(file_out, page_p_copy(page_p));
}
}
}
- return file_p_out;
+ return file_out;
}
-static struct page_probes *file_p_find_page_p(struct file_probes *file_p, unsigned long offset)
+static struct page_probes *file_p_find_page_p(struct sspt_file *file, unsigned long offset)
{
struct hlist_node *node;
struct hlist_head *head;
struct page_probes *page_p;
- head = &file_p->page_probes_table[hash_ptr(offset, file_p->page_probes_hash_bits)];
+ head = &file->page_probes_table[hash_ptr(offset, file->page_probes_hash_bits)];
hlist_for_each_entry(page_p, node, head, hlist) {
if (page_p->offset == offset) {
return page_p;
return NULL;
}
-static struct page_probes *file_p_find_page_p_or_new(struct file_probes *file_p, unsigned long offset)
+static struct page_probes *file_p_find_page_p_or_new(struct sspt_file *file, unsigned long offset)
{
- struct page_probes *page_p = file_p_find_page_p(file_p, offset);
+ struct page_probes *page_p = file_p_find_page_p(file, offset);
if (page_p == NULL) {
page_p = page_p_new(offset);
- file_p_add_page_p(file_p, page_p);
+ file_p_add_page_p(file, page_p);
}
return page_p;
}
-struct page_probes *file_p_find_page_p_mapped(struct file_probes *file_p, unsigned long page)
+struct page_probes *file_p_find_page_p_mapped(struct sspt_file *file, unsigned long page)
{
unsigned long offset;
- if (file_p->vm_start > page || file_p->vm_end < page) {
+ if (file->vm_start > page || file->vm_end < page) {
// TODO: or panic?!
printk("ERROR: file_p[vm_start..vm_end] <> page: file_p[vm_start=%x, vm_end=%x, path=%s, d_iname=%s] page=%x\n",
- file_p->vm_start, file_p->vm_end, file_p->path, file_p->dentry->d_iname, page);
+ file->vm_start, file->vm_end, file->path, file->dentry->d_iname, page);
return NULL;
}
- offset = page - file_p->vm_start;
+ offset = page - file->vm_start;
- return file_p_find_page_p(file_p, offset);
+ return file_p_find_page_p(file, offset);
}
-void file_p_add_probe(struct file_probes *file_p, struct ip_data *ip_d)
+void file_p_add_probe(struct sspt_file *file, struct ip_data *ip_d)
{
unsigned long offset = ip_d->offset & PAGE_MASK;
- struct page_probes *page_p = file_p_find_page_p_or_new(file_p, offset);
+ struct page_probes *page_p = file_p_find_page_p_or_new(file, offset);
// FIXME: delete ip
struct us_ip *ip = create_ip_by_ip_data(ip_d);
page_p_add_ip(page_p, ip);
}
-struct page_probes *get_page_p(struct file_probes *file_p, unsigned long offset_addr)
+struct page_probes *get_page_p(struct sspt_file *file, unsigned long offset_addr)
{
unsigned long offset = offset_addr & PAGE_MASK;
- struct page_probes *page_p = file_p_find_page_p_or_new(file_p, offset);
+ struct page_probes *page_p = file_p_find_page_p_or_new(file, offset);
spin_lock(&page_p->lock);
#include <linux/types.h>
-struct file_probes {
+struct sspt_file {
struct list_head list; // for proc_probes
struct dentry *dentry;
char *path;
};
-struct file_probes *file_p_new(const char *path, struct dentry *dentry, int page_cnt);
-struct file_probes *file_p_copy(const struct file_probes *file_p);
-void file_p_del(struct file_probes *file_p);
+struct sspt_file *file_p_new(const char *path, struct dentry *dentry, int page_cnt);
+struct sspt_file *file_p_copy(const struct sspt_file *file);
+void file_p_del(struct sspt_file *file);
-struct page_probes *file_p_find_page_p_mapped(struct file_probes *file_p, unsigned long page);
-void file_p_add_probe(struct file_probes *file_p, struct ip_data *ip_d);
+struct page_probes *file_p_find_page_p_mapped(struct sspt_file *file, unsigned long page);
+void file_p_add_probe(struct sspt_file *file, struct ip_data *ip_d);
-struct page_probes *get_page_p(struct file_probes *file_p, unsigned long offset_addr);
+struct page_probes *get_page_p(struct sspt_file *file, unsigned long offset_addr);
void put_page_p(struct page_probes *page_p);
#endif /* __FILE_PROBES__ */
void proc_p_free(struct sspt_procs *procs)
{
- struct file_probes *file_p, *n;
- list_for_each_entry_safe(file_p, n, &procs->file_list, list) {
- list_del(&file_p->list);
- file_p_del(file_p);
+ struct sspt_file *file, *n;
+ list_for_each_entry_safe(file, n, &procs->file_list, list) {
+ list_del(&file->list);
+ file_p_del(file);
}
kfree(procs);
}
}
-static void proc_p_add_file_p(struct sspt_procs *procs, struct file_probes *file_p)
+static void proc_p_add_file_p(struct sspt_procs *procs, struct sspt_file *file)
{
- list_add(&file_p->list, &procs->file_list);
+ list_add(&file->list, &procs->file_list);
}
-struct file_probes *proc_p_find_file_p_by_dentry(struct sspt_procs *procs,
+struct sspt_file *proc_p_find_file_p_by_dentry(struct sspt_procs *procs,
const char *pach, struct dentry *dentry)
{
- struct file_probes *file_p;
+ struct sspt_file *file;
- list_for_each_entry(file_p, &procs->file_list, list) {
- if (file_p->dentry == dentry) {
- return file_p;
+ list_for_each_entry(file, &procs->file_list, list) {
+ if (file->dentry == dentry) {
+ return file;
}
}
- file_p = file_p_new(pach, dentry, 10);
- proc_p_add_file_p(procs, file_p);
+ file = file_p_new(pach, dentry, 10);
+ proc_p_add_file_p(procs, file);
- return file_p;
+ return file;
}
void proc_p_add_dentry_probes(struct sspt_procs *procs, const char *pach,
struct dentry* dentry, struct ip_data *ip_d, int cnt)
{
int i;
- struct file_probes *file_p = proc_p_find_file_p_by_dentry(procs, pach, dentry);
+ struct sspt_file *file = proc_p_find_file_p_by_dentry(procs, pach, dentry);
for (i = 0; i < cnt; ++i) {
- file_p_add_probe(file_p, &ip_d[i]);
+ file_p_add_probe(file, &ip_d[i]);
}
}
struct sspt_procs *proc_p_copy(struct sspt_procs *procs, struct task_struct *task)
{
- struct file_probes *file_p;
+ struct sspt_file *file;
struct sspt_procs *procs_out = proc_p_create(procs->dentry, task->tgid);
- list_for_each_entry(file_p, &procs->file_list, list) {
- proc_p_add_file_p(procs_out, file_p_copy(file_p));
+ list_for_each_entry(file, &procs->file_list, list) {
+ proc_p_add_file_p(procs_out, file_p_copy(file));
}
return procs_out;
}
-struct file_probes *proc_p_find_file_p(struct sspt_procs *procs, struct vm_area_struct *vma)
+struct sspt_file *proc_p_find_file_p(struct sspt_procs *procs, struct vm_area_struct *vma)
{
- struct file_probes *file_p;
+ struct sspt_file *file;
- list_for_each_entry(file_p, &procs->file_list, list) {
- if (vma->vm_file->f_dentry == file_p->dentry) {
- return file_p;
+ list_for_each_entry(file, &procs->file_list, list) {
+ if (vma->vm_file->f_dentry == file->dentry) {
+ return file;
}
}
void proc_p_add_dentry_probes(struct sspt_procs *procs, const char *pach,
struct dentry* dentry, struct ip_data *ip_d, int cnt);
-struct file_probes *proc_p_find_file_p_by_dentry(struct sspt_procs *procs,
+struct sspt_file *proc_p_find_file_p_by_dentry(struct sspt_procs *procs,
const char *pach, struct dentry *dentry);
-struct file_probes *proc_p_find_file_p(struct sspt_procs *procs, struct vm_area_struct *vma);
+struct sspt_file *proc_p_find_file_p(struct sspt_procs *procs, struct vm_area_struct *vma);
#endif /* __PROC_PROBES__ */
return task_inst_info->unres_ips_count + task_inst_info->unres_vtps_count;
}
-static void set_mapping_file(struct file_probes *file_p,
+static void set_mapping_file(struct sspt_file *file,
const struct sspt_procs *procs,
const struct task_struct *task,
const struct vm_area_struct *vma);
.flag_retprobe = 1
};
- struct file_probes *file_p = proc_p_find_file_p_by_dentry(procs, name, dentry);
- struct page_probes *page_p = get_page_p(file_p, offset_addr);
+ struct sspt_file *file = proc_p_find_file_p_by_dentry(procs, name, dentry);
+ struct page_probes *page_p = get_page_p(file, offset_addr);
struct us_ip *ip = page_p_find_ip(page_p, offset_addr & ~PAGE_MASK);
- if (!file_p->loaded) {
- set_mapping_file(file_p, procs, task, vma);
- file_p->loaded = 1;
+ if (!file->loaded) {
+ set_mapping_file(file, procs, task, vma);
+ file->loaded = 1;
}
if (ip == NULL) {
- struct file_probes *file_p = proc_p_find_file_p_by_dentry(procs, name, dentry);
- file_p_add_probe(file_p, &pd);
+ struct sspt_file *file = proc_p_find_file_p_by_dentry(procs, name, dentry);
+ file_p_add_probe(file, &pd);
/* if addr mapping, that probe install, else it be installed in do_page_fault handler */
if (page_present(mm, addr)) {
ip = page_p_find_ip(page_p, offset_addr & ~PAGE_MASK);
- set_ip_kp_addr(ip, page_p, file_p);
+ set_ip_kp_addr(ip, page_p, file);
// TODO: error
ret = register_usprobe_my(task, ip);
EXPORT_SYMBOL_GPL (imi_sum_time);
EXPORT_SYMBOL_GPL (imi_sum_hit);
-static void set_mapping_file(struct file_probes *file_p,
+static void set_mapping_file(struct sspt_file *file,
const struct sspt_procs *procs,
const struct task_struct *task,
const struct vm_area_struct *vma)
int app_flag = (vma->vm_file->f_dentry == procs->dentry);
char *p;
// if we installed something, post library info for those IPs
- p = strrchr(file_p->path, '/');
+ p = strrchr(file->path, '/');
if(!p) {
- p = file_p->path;
+ p = file->path;
} else {
p++;
}
- file_p->vm_start = vma->vm_start;
- file_p->vm_end = vma->vm_end;
+ file->vm_start = vma->vm_start;
+ file->vm_end = vma->vm_end;
pack_event_info(DYN_LIB_PROBE_ID, RECORD_ENTRY, "dspdd",
task->tgid, p, vma->vm_start,
void print_vma(struct mm_struct *mm);
static int register_us_page_probe(struct page_probes *page_p,
- const struct file_probes *file_p,
+ const struct sspt_file *file,
const struct task_struct *task)
{
int err = 0;
if (page_p_is_install(page_p)) {
printk("page %x in %s task[tgid=%u, pid=%u] already installed\n",
- page_p->offset, file_p->dentry->d_iname, task->tgid, task->pid);
+ page_p->offset, file->dentry->d_iname, task->tgid, task->pid);
print_vma(task->mm);
return 0;
}
page_p_assert_install(page_p);
- page_p_set_all_kp_addr(page_p, file_p);
+ page_p_set_all_kp_addr(page_p, file);
list_for_each_entry(ip, &page_p->ip_list, list) {
err = register_usprobe_my(task, ip);
vma = find_vma(mm, page);
if (vma && check_vma(vma)) {
- struct file_probes *file_p = proc_p_find_file_p(procs, vma);
- if (file_p) {
+ struct sspt_file *file = proc_p_find_file_p(procs, vma);
+ if (file) {
struct page_probes *page_p;
- if (!file_p->loaded) {
- set_mapping_file(file_p, procs, task, vma);
- file_p->loaded = 1;
+ if (!file->loaded) {
+ set_mapping_file(file, procs, task, vma);
+ file->loaded = 1;
}
- page_p = file_p_find_page_p_mapped(file_p, page);
+ page_p = file_p_find_page_p_mapped(file, page);
if (page_p) {
- register_us_page_probe(page_p, file_p, task);
+ register_us_page_probe(page_p, file, task);
}
}
}
mm_read_unlock(mm, atomic, lock);
}
-static void install_file_probes(struct task_struct *task, struct mm_struct *mm, struct file_probes *file_p)
+static void install_file_probes(struct task_struct *task, struct mm_struct *mm, struct sspt_file *file)
{
struct page_probes *page_p = NULL;
struct hlist_node *node = NULL;
struct hlist_head *head = NULL;
- int i, table_size = (1 << file_p->page_probes_hash_bits);
+ int i, table_size = (1 << file->page_probes_hash_bits);
for (i = 0; i < table_size; ++i) {
- head = &file_p->page_probes_table[i];
+ head = &file->page_probes_table[i];
hlist_for_each_entry_rcu(page_p, node, head, hlist) {
if (page_present(mm, page_p->offset)) {
- register_us_page_probe(page_p, file_p, task);
+ register_us_page_probe(page_p, file, task);
}
}
}
for (vma = mm->mmap; vma; vma = vma->vm_next) {
if (check_vma(vma)) {
- struct file_probes *file_p = proc_p_find_file_p(procs, vma);
- if (file_p) {
- if (!file_p->loaded) {
- set_mapping_file(file_p, procs, task, vma);
- file_p->loaded = 1;
+ struct sspt_file *file = proc_p_find_file_p(procs, vma);
+ if (file) {
+ if (!file->loaded) {
+ set_mapping_file(file, procs, task, vma);
+ file->loaded = 1;
}
- install_file_probes(task, mm, file_p);
+ install_file_probes(task, mm, file);
}
}
}
mm_read_unlock(mm, atomic, lock);
}
-static int check_install_pages_in_file(struct task_struct *task, struct file_probes *file_p)
+static int check_install_pages_in_file(struct task_struct *task, struct sspt_file *file)
{
int i;
- int table_size = (1 << file_p->page_probes_hash_bits);
+ int table_size = (1 << file->page_probes_hash_bits);
struct page_probes *page_p;
struct hlist_node *node, *tmp;
struct hlist_head *head;
for (i = 0; i < table_size; ++i) {
- head = &file_p->page_probes_table[i];
+ head = &file->page_probes_table[i];
hlist_for_each_entry_safe (page_p, node, tmp, head, hlist) {
if (page_p->install) {
return 1;
return 0;
}
-static int unregister_us_file_probes(struct task_struct *task, struct file_probes *file_p, enum US_FLAGS flag)
+static int unregister_us_file_probes(struct task_struct *task, struct sspt_file *file, enum US_FLAGS flag)
{
int i, err = 0;
- int table_size = (1 << file_p->page_probes_hash_bits);
+ int table_size = (1 << file->page_probes_hash_bits);
struct page_probes *page_p;
struct hlist_node *node, *tmp;
struct hlist_head *head;
for (i = 0; i < table_size; ++i) {
- head = &file_p->page_probes_table[i];
+ head = &file->page_probes_table[i];
hlist_for_each_entry_safe (page_p, node, tmp, head, hlist) {
err = unregister_us_page_probe(task, page_p, flag);
if (err != 0) {
}
if (flag != US_DISARM) {
- file_p->loaded = 0;
+ file->loaded = 0;
}
return err;
static int uninstall_us_proc_probes(struct task_struct *task, struct sspt_procs *procs, enum US_FLAGS flag)
{
int err;
- struct file_probes *file_p;
+ struct sspt_file *file;
- list_for_each_entry_rcu(file_p, &procs->file_list, list) {
- err = unregister_us_file_probes(task, file_p, flag);
+ list_for_each_entry_rcu(file, &procs->file_list, list) {
+ err = unregister_us_file_probes(task, file, flag);
if (err != 0) {
// TODO:
return err;
vma = find_vma(mm, start);
if (vma && check_vma(vma)) {
- struct file_probes *file_p;
+ struct sspt_file *file;
unsigned long end = start + len;
- file_p = proc_p_find_file_p(procs, vma);
- if (file_p) {
+ file = proc_p_find_file_p(procs, vma);
+ if (file) {
if (vma->vm_start == start || vma->vm_end == end) {
- unregister_us_file_probes(task, file_p, US_NOT_RP2);
- file_p->loaded = 0;
+ unregister_us_file_probes(task, file, US_NOT_RP2);
+ file->loaded = 0;
} else {
unsigned long page;
struct page_probes *page_p;
for (page = vma->vm_start; page < vma->vm_end; page += PAGE_SIZE) {
- page_p = file_p_find_page_p_mapped(file_p, page);
+ page_p = file_p_find_page_p_mapped(file, page);
if (page_p) {
unregister_us_page_probe(task, page_p, US_NOT_RP2);
}
}
- if (check_install_pages_in_file(task, file_p)) {
- file_p->loaded = 0;
+ if (check_install_pages_in_file(task, file)) {
+ file->loaded = 0;
}
}
}