Created
November 11, 2016 18:55
-
-
Save yodalee/7b7d35fb0b702764d9556c0f491e509f to your computer and use it in GitHub Desktop.
AOS HW2 system call that collect info of caller process
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <linux/kernel.h> | |
#include <linux/init.h> | |
#include <linux/sched.h> | |
#include <linux/syscalls.h> | |
#include <uapi/linux/errno.h> | |
#include <asm/uaccess.h> | |
#include <linux/string.h> | |
#include <linux/list.h> | |
#include <linux/sched.h> | |
#include "dummysyscall.h" | |
long sys_dummy(struct prinfo *info) { | |
struct prinfo kinfo; | |
struct task_struct *task = NULL; | |
struct list_head *list = NULL; | |
pid_t childpid = 0; | |
pid_t pid_young = 32768; | |
pid_t pid_old = 0; | |
if (copy_from_user(&kinfo, info, sizeof(struct prinfo))) { | |
return -EFAULT; | |
} | |
kinfo.state = current->state; | |
kinfo.nice = task_nice(current); | |
kinfo.pid = current->pid; | |
kinfo.parent_pid = current->parent->pid; | |
// find child with largest pid | |
printk("current pid %d\n", current->pid); | |
list_for_each(list, ¤t->children) { | |
task = list_entry(list, struct task_struct, sibling); | |
printk("child pid %d\n", task->pid); | |
if (task && task->pid > childpid) { | |
childpid = task->pid; | |
} | |
} | |
// find younger/older sibling | |
printk("current pid %d\n", current->pid); | |
list_for_each(list, ¤t->parent->children) { | |
task = list_entry(list, struct task_struct, sibling); | |
printk("sibling pid %d\n", task->pid); | |
if (task->pid > current->pid && task->pid < pid_young) { | |
pid_young = task->pid; | |
} | |
if (task->pid < current->pid && task->pid > pid_old) { | |
pid_old = task->pid; | |
} | |
} | |
kinfo.youngest_child_pid = childpid; | |
kinfo.younger_sibling_pid = pid_young; | |
kinfo.older_sibling_pid = pid_old; | |
kinfo.start_time = current->start_time; | |
kinfo.user_time = current->utime; | |
kinfo.sys_time = current->stime; | |
kinfo.cutime = current->signal->cutime; | |
kinfo.cstime = current->signal->cstime; | |
kinfo.uid = current->cred->uid.val; | |
strncat(kinfo.comm, current->comm, 16); | |
if (copy_to_user(info, &kinfo, sizeof(struct prinfo))) { | |
return -EFAULT; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment