Adding linux kernel system call based on kernel-4.14.14
sudo dnf install aria2
aria2c -x9 https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.14.14.tar.xz
vim arch/x86/entry/syscalls/syscall_64.tbl
#[ADD] 338 64 my_syscall sys_my_syscall
I write a syscall function here,you can download sys.c and copy the function into kernel/sys.c
cat sys.c >> kernel/sys.c
Or you can write your own sys_my_syscall
asmlinkage long sys_my_syscall(int pid);
make oldconfig
make -j12
sudo make modules_install
sudo make install
sudo reboot
Choice linux-kernel-4.14.14 after reboot.
gcc use.c -o use
./use
Input a pid and see the result.
struct task_struct *pid_task(struct pid *pid, enum pid_type type) {
struct task_struct *result = NULL;
if (pid) {
struct hlist_node *first;
first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
lockdep_tasklist_lock_is_held());
if (first) result = hlist_entry(first, struct task_struct, pids[(type)].node);
}
return result;
}
printk("\nCode Segment start = 0x%lx, end = 0x%lx, Size = %ld B\n"
"Data Segment start = 0x%lx, end = 0x%lx, Size = %ld B\n"
"Heap Segment Start = 0x%lx, end = 0x%lx, Size = %ld B\n"
"Stack Segment start = 0x%lx\n"
"Total physical pages maped = %ld, physical memory size = %ld KB\n"
"PGD = 0x%lx\n",
mm->start_code, mm->end_code, text,
mm->start_data, mm->end_data, mm->data,
mm->start_brk, mm->brk, mm->brk – mm→start_brk,
mm->start_stack, mm→stack_vm*4,
resident, resident*4,
mm→pgd);