Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can someone please help me witht his and also provide screenshots so I can see, I have no idea what to start or what its

can someone please help me witht his and also provide screenshots so I can see, I have no idea what to start or what its asking

Add a Static System Call to the Linux Kernel

Write a new static system call to incorporate to your custom Linux Kernel. The system call you write should take one argument and return the process state information for that process, its child processes, child threads and sibling processes. The prototype for your system call will be:

asmlinkage long sys_pinfo(struct pinfo *info);

pid_t is defined in /usr/include/sys/types.h and /usr/include/linux/types.h for user-space programs and in /usr/src/linux/include/linux/types.h(/usr/src/linux/include/uapi/asm-generic/posix_types.h) for kernel-space routines.

Also see /usr/include/asm-generic/posix_types.h

Define struct pinfo in /usr/src/linux/include/linux/pinfo.h as part of your solution (localize it for your test C program):

#include

struct pinfo {

pid_t pid; /* process id */

long state; /* current state of process */

long nice; /* process nice value */

pid_t parent_pid; /* process id of parent */

int nr_children; /* total number of child processes */

int nr_threads; /* total number of child threads */

pid_t youngest_child_pid; /* pid of youngest child */

pid_t younger_sibling_pid; /* pid of younger sibling */

pid_t older_sibling_pid; /* pid of older sibling */

unsigned long start_time; /* process start time */

long user_time; /* CPU time spent in user mode */

long sys_time; /* CPU time spent in system mode */

long cutime; /* total user time of children */ long cstime; /* total system time of children */

long uid; /* user id of process owner */

char comm[16]; /* name of program executed */

};

Sibling processes are those sharing the same parent. Younger, youngest and older comparisons between processes are made based on their start time.

Your system call should return 0 unless an error occurs. Your code should handle errors that can occur but not handle any errors that cannot occur. At a minimum, your system call should detect the following conditions and respond as described:

If the address for the pinfo structure is null, return -22.

If a value to be set in pinfo is accessible through a pointer which is null, set the corresponding field value in pinfo to -1. For example, the youngest_child_pid should be set to -1 if the process does not have a child. The referenced error code is defined as EINVAL in /usr/src/linux/include/uapi/asm-generic/errno-base.h /usr/src/linux/include/linux/errno.h /usr/src/linux/usr/include/asm/errno.h.

Each system call must be assigned a number which becomes its position in the system call vector. You must identify an available spot for your new system call in the vector for x86_64 system calls (see /usr/src/linux/arch/x86/syscalls/syscall_64.tbl and /usr/src/linux/include/uapi/asm-generic/unistd.h)

Linux maintains a list of all processes in a doubly linked list. Each entry in this list is a task_struct structure, which is defined in /usr/src/linux/include/linux/sched.h.

In /usr/src/linux/include/asm-generic/current.h, current is defined to inline a function which returns the address of the task_struct of the currently running process. All of the information to be returned in the pinfo structure can be determined by starting with current. Note that current.h includes /usr/src/linux/include/linux/thread_info.h

See /usr/src/linux/arch/x86/include/asm/thread_info.h

See code in:

/usr/src/linux/arch/x86/syscalls/syscall_64.tbl

/usr/src/linux/arch/x86/syscalls/syscall_32.tbl

Also see:

/usr/src/linux/include/uapi/asm-generic/unistd.h

/usr/include/asm/unistd.h

/usr/src/linux/include/linux/syscalls.h

/usr/src/linux/kernel/kallsyms.c

Add the following line below the entry that starts with 326 to /usr/src/linux/arch/x86/syscalls/syscall_64.tbl

327 common mypinfo sys_pinfo

Add the following lines to /usr/src/linux/include/linux/syscalls.h at the proper spots:

struct pinfo;

#include

asmlinkage long sys_pinfo(struct pinfo *info);

Create a directory in /usr/src/linux and call it pinfo. This directory should contain the implementation of your new static system call.

Edit the main Makefile in /usr/src/linux/Makefile and add the new pinfo/ directory to the following line:

core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ pinfo/

Create a Makefile in /usr/src/linux/pinfo with the following line in it:

obj-y := pinfo.o

Develop and implement the code of your new static system call in /usr/src/linux/pinfo.c The following should serve as a base template. Make sure to author and properly document your code in this source file.

See /usr/src/linux/include/linux/cred.h

See /usr/src/linux/include/linux/uidgid.h

struct pinfo;

#include

#include

#include

#include

#include

#include

#include

#include

#include

asmlinkage long sys_pinfo(struct pinfo *info)

{

// Local Declarations

if(info == NULL)

return -22;

// Main Logic

return 0;

}

Build your custom kernel and re-deploy it following the same steps you performed in Assignment 1 when you initially built and deployed the custom kernel in your system. Then make sure to boot your system from the custom made kernel that now includes the new system call and proceed to run your test program to verify the correctness of your new system call routine.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions