Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone fix and check if my .c file and Makefile are correct? Need 2 things: .c file with the name LastNameLKM.c Makefile you use

Can someone fix and check if my ".c" file and "Makefile" are correct?
Need 2 things:
".c" file with the name "LastNameLKM.c"
Makefile you use to build it
My screenshots:
image text in transcribed
image text in transcribed
Instructions:
image text in transcribed
image text in transcribed
There is also a "Writeup" that is also required (check last photo below).
NEED:
LastNameLKM.c
Makefile
Writeup
Extra information:
You will implement a loadable kernel module that uses Linux data structures
to display details about the processes executing in the kernel.
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
i #include 2 #include 3 #include 4 5 6 /'This function is called when the module is loaded. */ 7 int simple_init(void) 8 { 9 printk(KERN_INFO "Loading Test Module"); 10 return 0; 11 } 12 13 / *This function is called when the module is removed. / 14 void simple_exit(void) 15 { 16 printk(KERN_INFO "Removing Test Module"); 18 19 / "Macros for registering module entry and exit points. / 28 module_init(simple_init); 21 module_exit (simple_exit); 22 23 MODULE LICENSE ( "GPL"); 24 MODULE DESCRIPTION("Simple Module"); 25 MODULE AUTHOR("SGG"); 26 27 17 } 1 obj-m * simple.o 2 3 all: 4 make -C /lib/modules/$(shell uname -r)/build M $(PWD) modules 5 6 clean: make -C /lib/modules/$(shell uname -r)/build M $(PWD) clean In this assignment you will write a LKM for the Linux kernel that displays the following details for all the processes whose PID is greater than an integer given by the user as a module parameter: 126 points PROCESS NAME PID STATE PRIORITY STATIC-PRIORITY NORMAL-PRIORITY As shown below, the PID is given as arguments while inserting the module in the kernel. p.prodon azonte/Desktop pudo nunod Process 1 ko .pl-2500 45205-/ The next screenshot shows the required details for a process, its child processes (may have 0 or more), and its parent process. You are expected to keep a similar format (not an exact one) for your output which is readable. Your programs must compile and run under Xubuntu (or another variant of Ubuntu) 20.04. 14723 1 126 120 120 2 1 126 126 120 PID 14733 STATE 1 PRIO 120 ST_PRIO NORM_PRIO 120 120 2 2 1 120 120 126 PID 14980 STATE 1 PRIO 120 ST_PRIO NORM_PRIO 120 120 2 2 1 120 120 120 [21665.443053] kworker/1:1 [21665.443053) PARENT [21665.443055j kthreadd [21665.443055] [21605.443656) PROCESS [21605.443057j kworker/6:2 [21665.443059 PARENT [21665.443060j kthreadd [21665.443661] PROCESS (21665.443062 worker/u16:2 [21605.443063) PARENT [21665.443063) kthreadd [21665.443064] 21665.4430651 PROCESS [21605.443067) kworker/u16:3 121605.443068) PARENT [21605.443069] kthreadd [21665.443070) [21605.443071) PROCESS [21665.443071] kworker/u16:0 (21665.443073] PARENT [21665.443074] kthreadd [21605.443075) [21605.443076) PROCESS [21665.443078) sudo [21605.443079] CHILD [21665.4430881 sudo 21605. 443080) PARENT PID STATE 1 PRIO 120 ST_PRIO NORM_PRIO 120 120 15467 2 1 126 120 120 PID 15866 STATE 1 PRIO 126 ST_PRIO NORM_PRIO 120 120 2 1 120 120 120 PID 16711 STATE 1 PRIO 126 ST_PRIO NORM_PRIO 120 120 16716 1 126 120 120 1 Background The kernel is a program that forms the core of a computer's operating system, with control over everything in the system. It performs tasks such as running processes, allocating resources, interfacing with hardware, and all other tasks that happen behind the scenes in "kernel space". In contrast, everything the user does is executed in "user space". This separation prevents user data and kernel data from interfering with each other and causing instability or security issues. Kernel modules are pieces of code which provide functionality to the kernel. The word "loadable" is prefixed to kernel module to show that it eases the process of integrating the module with the kernel. Typically, if functionality is to be provided in the kernel, it has to incorporated by compiling the kernel with the proposed changes. Loadable Kernel Modules (LKM) ease that process by providing the facility to integrate with the existing kernel instead of requiring kernel re-compilation. The best way to start is with the sample LKM provided on the text book's website (also posted on Canvas), and then add your own functionality, In this assignment you will write a LKM for the Linux kernel that displays certain details of the processes along with its parent and children) executing in the kernel. As an important step to implementing the program, you should review the section on include files to get an idea of what functionality is available. From there, start to develop the actual source code, while reading the documentation for any functions you used. Much of the documentation exists as source code with the Linux kernel, meaning that you will need to read the code yourself. The assignment source code should be relatively short but uses features you will have to research on your own (such as passing a value to a LKM, or how to manipulate the list of running proce 888). Expect that a significant part of your time on this assignment will be spent reading/researching/understanding LKM documentation and reviewing kernel source code files The website for Linux kernel source is Any lines numbers mentioned in this document refer to Linux 5.11. The specific version of the Linux kernel on your machine may different slightly. This document is separated into five sections: Background, Running a LKM, Requirements, Include Files, and Submission. You have almost finished reading the Background section already. In Requirements, we will discuss what is expected of you in this homework. In Running a LKM, a basic demonstration of an LKM is given. In Include Files, we discuss several header files that include functionality related to file and directory manipulation. Lastly, Submission discusses how your source code should be submitted on Canvas. 1.1 Accessing Kernel Source Code To find the version of your kernel, use the command "uname-r". Below the version is shown as 5.11.0- 34-generic. The screenshot comes from a VM running an up to date (9/28/21) install of Xubuntu 20.04.3 (which can be checked by running "sb_release -a"). The bit of text after 5.11 (the major and minor version information) indicates the patch version. Depending on how up to date your machine is, you may see a more recent kernel version. When you submit your write up, you will be asked to list the version of the kernel you use to find line numbers. (The version is important since line numbers change as updates occur.) To see source code for different kernels, use: and find the version closest to the one installed on your VM. Following from the screen shot above where the machine was running 5.11.0-32-generic", we would use the 5.11version below. Also shown in the list is v5.11.1 which would be a newer version (the screenshot's version ends in 0 not 1). index oft 6.40 2 44 ...scroll scroll... 11 111 Once the source code is downloaded, extract it to a local folder. You will then be able to navigate within that folder to view different files. Shown below is an example of looking up task_struct from the file linux/sched.h (see the section on Include Files later). (If you are not using the v5.11 files, then most likely the file will look different!) struct STWO tract ST 2 Running a LKM As a first step in this assignment, we suggest trying to get a simple module to run. A simple module such as the sample provided by the textbook! The textbook (Operating System Concepts 9e) provides additional information on creating and running LKMS on page 96. Reading that section of the book is strongly recommended. Next, we give a stort summery of the basic instructions to run an LKM. Note that we need to use a so-called "makefile" to manage the compilation of modules. Do not try to use an IDE such as CLion or NetBeans. Four basic commands are needed for dealing with LKMS: 1) "make" to create the binary files. 2) insmod to insert the LKM into the running kernerl, 3) dmesg to view the kernel log file, and 4) rmmod to remove a loaded LKM. See below: make sudo insmod simple. ko dmesg sudo rmmod simple As seen below, running make compiles the LKM into an insertable ko file. It runs the makefile for the module (see the Makefiles subsection for more information). We then do the insert with insmod which means that it is running. To see the results (printf won't work), we use dmesg to view the log (where the output from commands like printk will go). There will be a lot of information shown when using dmeng... direct INI Robel Le w FIE So we typically need to scroll down to find the output from our module. In the screen shot below, the last line ("Loading Module") is the output from the LKM we compiled and inserted. To remove the LKM, we finally issue the rimod command (we could also reboot). ALS STATUS re rotate SOTSTE Bantal Vi 2.1 Makefiles A makefile is a file containing a set of directives used with the make tool to automate the build process for a file or a set of files. For example, assume we have a codebase that has hundreds of files with lots of 3 dependencies between them. Generally, we would compile each file, generate an object file and link all the object files together to generate an executable. Even if there is a small change in one of the files, we would have to recompile and link them which is quite a cumbersome and inefficient process. Using Makefiles, you can ensure that only the files that have been modified since the last build and those which are dependent on the changed files are the ones which are compiled. For this assignment, you will use a specially set up makefile. See Algorithm 2 below. In this make file, we have two targets, all and clean. Rather than being dependent on a specific file, they are more actions that the makefile can execute. In this case, all is used to build the file, while clean is to clean the build outputs. For us, we would only need to type "make" in the correct folder to use this makefile. The top most line is special, it says "obj-m += simple.o". This say takes the result of compiling the file simple.c (which will be called simple.o), and combine it with the default binaries for creating an module. This produces the .ko file that represents a built LKM that you can load into the operating system. Algorithm 1 Sample LKM makofile (from Operating System Concepts by Silberschatz, Galvin, Gagne) obj-+ + simple o make c/lib/modules/8( shell uname -r)/build M 8 (PWD) modules clean: make c/lib/modules/$(shell uname -1)/build M-8 (PWD) clean 0 WARNING: do not use this makefile within a path that includes a space *) in it's name, or the module will not build! For example, don't create a folder called "HW M5" on your desktop and develop within it. The space between "HW" and "M5" will cause the build to fail. 3 Requirements (36 points total] In this assignment you will write a LKM for the Linux kernel that displays the following details for all that processes whose PID is greater than an integer given by the user as a module parameter: 126 points . PROCESS NAME PID STATE . PRIORITY .STATIC-PRIORITY NORMAL PRIORITY As shown below, the PID is given an arguments while inserting the module in the kernel. The next screenshot shows the required details for a process, its child processes (may have or more), and its parent process. You are expected to keep a similar format (not an exact one) for your output which is Teadable. Your programs must compile and run under Xubuntu (or another variant of Ubuntu) 20.04. 16 12 1.30 1 14731 po STATE 1 126 ST SIDOR PRIO 130 23 170 120 10 FIL 14501 1 120 STOP:10 128 120 12 443839) TRAF PAREM kthread PROCESS kworker12 PARENT thread PROCESS korer? PARENT kthread PROCESS kworkers PAREM three PECESS 4301kwerkere PAREN! 2160.041074kthreads 216.6410751 (16.641078) PROCESS 2160.0410 sude (109) CHILD 120.443010) Sudo (2 4400 PM PID 35451 STATE 1 10 128 12 ST JOHOR DO 130 220 2 PED 15102 STATE 12 10 120 120 119 S1_2010 320 120 1.28 1471 ST 1 10 120 ST. PRIO 13 1471 1 120 32 120 3.1 Writeup (10 points] You are to provide a short write up that illustrates what you found when looking at the Linux source files and documentation. As you will experience, the information about the kernel is somewhat fragmented, which your write up and pull together and complete. Include the following: The version number of your kernel you used to find the line numbers (typically the version you found on the kernel website). 10 points but needed to grade others . Main source file: list each function that you defined and describe its purpose. Typically this would be functions for init and exit, plus any helpers you created. Task_struct: at a high level, document each of the struct attributes that your use in your program (e.g., pid, state, prio, etc). . For each header file (except linux/module.h), document each function/macrostruct you use: - Functions: Include the function's signature, what file/line it is defined, and a description (include parameters and return values). Example (self-contained, well styled, and readable): printf Defined on line 133 in stdio.h. Signature: int printf(const char *format, ...): Parameters: The first parameter (format) takes a string, followed by any number of other parameters (see below) Description: This string will be displayed as standard console output. The string may contain special formatting called control characters. For example, including "%c indicates a position in the string where a character should appear. The variable containing the string should be passed as the second parameter. The function may take any number of parameters, where the first is always the main string, and everything else is a value that may be substituted into it. After completion, the function returns the number of displayed (an int). - Macro: same as function. Struct: Indicate what file/line it is defined, and document each of the attributes used. The purpose of the write up is show the research" you did when creating your program. Do not quote (or paraphrase) any 3rd party documentation - use your own words and understanding. Although there is no mandatory format, please be professional. Your document should be self-contained, well styled (eg., no comic sans, random font sizes), and readable (eg, minimal spelling or grammar errors)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

To fix your c file and Makefile for the loadable kernel module LKM in Linux lets go through both step by step including necessary corrections and impr... 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

Students also viewed these Databases questions