30PDF FILE

I attached the file for project 2, but i also if you can fix the previous project 1 that you gave me before.

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

CSE 330: Operating Systems – Fall 2024
Project 2: Kernel Module and System Call
Due by September 20, 2024, 11:59 pm
Summary
Based on the VM, Ubuntu, and Linux kernel that we installed in the previous project, in Project
2, we will create a new module and a new system call to the kernel (6.10) on our Ubuntu VM.
This project will be the start of our kernel development journey, and it will help us understand
how system calls and kernel modules work in an OS.
Description
Step 1: Implement a new module for your new kernel.
As we will discuss in class, modules are an important means for extending the functionalities of
a monolithic OS kernel like Linux. In this step, you will implement a new module to add a
function to your kernel. This function should print out the name of our new kernel developer,
i.e., you, to the kernel log when the module is loaded. Obviously, this is not a typical kernel
function, but the new module you will develop here will be extended in the later projects to
implement real, useful functions.
Steps:
1. Implement a basic kernel module
You can follow this simple hello world example to create your kernel module source file
my_name.c. module_init() is called when the module is loaded and module_exit() is
called when the module is unloaded. You can place the module code (and the makefile
explained next) in a separate folder outside the Linux source code folder.
#include
#include
#include
MODULE_LICENSE(“GPL”);
MODULE_AUTHOR(“Linus Torvalds”);
static int __init example_init(void) {
printk(KERN_INFO “Hello, World!\n”);
Copyright © Ming Zhao, Ph.D.
CSE 330: Operating Systems – Fall 2024
return 0;
}
static void __exit example_exit(void) {
printk(KERN_INFO “Goodbye, World!\n”);
}
module_init(example_init);
module_exit(example_exit);
2. Implement module parameters
Use the module_param() macro to pass parameters from command-line to a kernel
module. Call this macro at the beginning of your module code.
The following code snippet explains how to use the module_param() macro:
/* The module_param() macro takes three arguments:
– The name of the variable, which also becomes the name of the
module parameter
– The type is the data type of the variable
– The last argument is perm, which denotes permissions. This can be
left as zero
static int intParameter = 0;
module_param(intParameter, int, 0);
static char *charParameter = “default”;
module_param(charParameter, charp, 0);
Your kernel module MUST accept two parameters: charParameter=”Fall” and
intParameter=2024.
Now change your module code so that when the module is loaded it prints out a
message in the following format to the kernel log:
Hello, I am , a student of CSE330 ${charParameter} ${IntParameter}.
Use printk to print to the kernel log. It is a powerful tool for kernel debugging. Refer
printk documentation for details.
Copyright © Ming Zhao, Ph.D.
CSE 330: Operating Systems – Fall 2024
3. Compile the kernel module
Create a makefile for compiling the new kernel module.
obj-m += my_name.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
After creating the makefile, you can use the ‘make’ command in the terminal to compile
your kernel module.
4. Load the kernel module
After a successful build, you will see the hello.ko file generated. Now load the kernel
module using `insmod` (with sudo).
Check the module output using the dmesg command (Kernel logs are stored under
/var/log/messages. You can also use the dmesg command. After you insert the kernel
module, the output can be checked using sudo dmesg | tail -n 1. (tail -n 1 returns the
last line in dmesg output; you can change the number to return more lines; you can also
directly check the kernel log /var/log/messages.)
Remove the module using rmmod and it should be successful. You can use lsmod to
check if the module is indeed removed.
The following snapshot shows all the commands used for testing and their outputs:
Congrats! Now you know how to create custom kernel modules.
Copyright © Ming Zhao, Ph.D.
CSE 330: Operating Systems – Fall 2024
Copyright © Ming Zhao, Ph.D.
CSE 330: Operating Systems – Fall 2024
Step 2: Implement a new system call for your new kernel.
As we will also discuss in class, system calls are the main interface for user-space software to
interact with the kernel. In this step, you will implement a new system call that simply prints out
one message in the kernel log and a user-space program that tests this system call.
Steps:
1. Make a subfolder for your new system call’s source code and makefile in your Linux
source code folder. e.g. linux-6.10/my_name
2. Create the system call source file my_syscall.c and define the new system call
A. x86: Name your function __x64_sys_my_syscall in your code file, e.g.
linux-6.10/my_name/my_syscall.c
B. ARM: Name your function __arm64_sys_my_syscall in your code file, e.g.
linux-6.10/my_name/my_syscall.c
Use printk() in your system call implementation to print out “This is the new system call
Linus Torvalds implemented.” (Replace “Linus Torvalds” with your full name).
3. Create a new makefile in the same folder. Add obj-y := my_syscall.o to your new
Makefile. e.g. linux-6.10/my_name/Makefile
4. Associate the new makefile to the kernel’s makefile. This means that you need to modify
‘linux-6.10/Makefile’. You need to search for the ‘core-y :=’ and add your folder name
after it, as shown below.
Add the new system call to the system call table.
A. x86: File Location: linux-6.10/arch/x86/entry/syscalls/syscall_64.tbl
Copyright © Ming Zhao, Ph.D.
CSE 330: Operating Systems – Fall 2024
B. ARM: File Location: linux-6.10/arch/arm/tools/syscall.tbl
Syscall table for x86
5. Add the new system call’s prototype in the system call header file. For both x86 and ARM
the file path is the same. linux-6.10/include/linux/syscalls.h
6. Update the system call numbers, which embeds the pointer to the syscall in the table
A. File: linux-6.10/include/uapi/asm-generic/unistd.h for both x86 and ARM
Copyright © Ming Zhao, Ph.D.
CSE 330: Operating Systems – Fall 2024
B. File: linux-6.10/arch/arm64/include/asm/unistd.h for ARM only
7. Recompile your kernel following the steps we did in Project 1 (this will take a while):
A. make -j4
B. sudo make modules_install -j4
C. sudo make install -j4
D. sudo update-grub
8. Reboot your VM into the new kernel.
9. Write a userspace program syscall_in_userspace_test.c for invoking your new system call
following this template.
10. Compile the userspace program and run it.
gcc -o syscall_in_userspace syscall_in_userspace_test.c
./syscall_in_userspace
After you invoke the system call, the expected output from dmesg | tail should be like:
Copyright © Ming Zhao, Ph.D.
CSE 330: Operating Systems – Fall 2024
Tips:
● It is highly recommended to take VM snapshots after you complete each major step in
order to keep a working backup.
● Periodically delete outdated kernel versions if you are running out of space
○ dpkg –list ‘linux-image-*’
○ Find all the kernels that are lower than your current kernel. When you know which
kernel to remove, continue below to remove it. (Do not remove the original kernel
that comes with Ubuntu so you have a working backup.)
Run the commands below to remove the kernel you selected.
sudo apt-get purge linux-image-x.x.x-x-generic
○ sudo update-grub2
○ Reboot your VM
● Also delete the outdated system-level logs in order to avoid low disk space
errors/warnings. This can be accomplished by typing sudo dmesg -C into your terminal.
Testing

In order to test your project we have provided you with the grading scripts. These are
available on a GitHub repository. If you have not used git before you can use this link to
familiarize yourself.
● In order to clone the Github repository follow the below steps
○ git clone https://github.com/visa-lab/CSE330-OS.git
○ cd CSE330-OS/
○ git checkout project-2
● Use test_module.sh to check the correctness of your kernel module
○ The script will ensure your kernel module source files adhere to the directory
structure, compile your module, load it, and unload it.
○ The script will print a detailed log after testing each part of the rubrics and point
out reasons if grade points were deducted.
○ Here is a screenshot of a test that passess all checks:
Copyright © Ming Zhao, Ph.D.
CSE 330: Operating Systems – Fall 2024
● Use test_syscall.sh to test your syscall submission
○ The script will ensure your screenshot adheres to the directory structure and
validate the screenshot is present for testing. Graders will check the correctness
of the screenshot separately.
○ Here is a screenshot of a test that passess all checks:
Note:
We will check your code in addition to running the test script, so passing the testing
script does not guarantee getting all the grade points. But if your submission fails to pass
the above scripts entirely, you will receive zero grade points.
Submission Requirements & Guidelines
Project 2 is due by September 20, 2024. Submit your work following the below guidelines:
● Submit the following in a zip file to Canvas:
○ Source code:
■ kernel module – Make a directory named ‘kernel_module’, and submit
your code file named ‘my_name.c’ and your Makefile.
■ system call – Make a directory named ‘kernel_syscall’, and submit your
code file named ‘my_syscall.c’ and your Makefile.
■ user-space test program – Make a directory named ‘userspace’, and
submit your code file named ‘syscall_in_userspace_test.c’.
○ Screenshot of the outputs:
■ The screenshot should include the output from Step 2 Implementing a
new system call. It should show the invocation of your userspace program
and the expected output in dmesg:
“This is the new system call implemented.”
■ You can use VirtualBox’s screenshot function to take a screenshot (to take
a screenshot in VirtualBox, go to View-> Take Screenshot).
■ For UTM You can use the macOS keyboard shortcut to take a screenshot
(Command + Shift + 3).
Copyright © Ming Zhao, Ph.D.
CSE 330: Operating Systems – Fall 2024
■ You MUST make a directory named ‘screenshots’ and MUST save one
screenshot with the following name: syscall_output.png
○ Project-1 resubmission:
■ This is only applicable for students who lost points in Project-1 and want
to take this opportunity for regrade.
■ Make a directory ‘Project1’
■ There MUST be two screenshots with the following names:
● lsb_release.png
● uname.png
● You MUST name the zip file following the naming convention
“Project-2-YourASUID>.zip”, e.g., Project-2-1225754101.zip
○ You should use the following command to create your zip file:
zip -r Project-2-1225754101.zip kernel_module/ kernel_syscall/ screenshots/
userspace/
Note: Add ‘Project1/’ in the above command if you are resubmitting Project1:
zip -r Project-2-1225754101.zip kernel_module/ kernel_syscall/ screenshots/
userspace/ Project1/
○ Note that the extension automatically added by Canvas to your zip file’s name is
okay.
● Do not submit any other source code
● Do not submit any binary
● If your submissions do not adhere to submission guidelines and naming conventions you
will receive zero grade points
Grading Rubrics
Criteria
Kernel Module (my_name)
1. Kernel module should load
without errors
2. Expected output should
appear in dmesg with
student’s name and the
provided module parameters
Test
Pts
./test_my_name.sh
Module load
successfully (20)
Check for the student’s name and
correctness of both module parameters.
Expected output:
Hello, I am Linus Torvalds, a student of
CSE330 Fall 2024.
Expected output
matches (20)
Copyright © Ming Zhao, Ph.D.
Module unloads
successfully (10)
CSE 330: Operating Systems – Fall 2024
3. Kernel module should
unload without errors
System Call (my_syscall)
The expected output should
appear in dmesg with the
student’s name
gcc -o syscall_in_userspace_test
syscall_in_userspace_test.c
50
./syscall_in_userspace_test
dmesg
Check for the student’s name. Expected
output: This is the new system call Linus
Torvalds implemented.
Submission Content
Zip file should contain only the
required screenshots and
source code.
./test_zip_contents.sh
Checking Directory: kernel_module
– Directory Found: kernel_module
– File Found:
kernel_module/my_name.c
– File Found:
kernel_module/Makefile
Checking Directory: kernel_syscall
– Directory Found: kernel_syscall
– File Found:
kernel_syscall/my_syscall.c
– File Found:
kernel_syscall/Makefile
Checking Directory: userspace
– Directory Found: userspace
– File Found:
userspace/syscall_in_userspace_test.c
Checking Directory: screenshots
– Directory Found: screenshots
– File Found:
screenshots/syscall_output.png
Summary
——————————————————-
Copyright © Ming Zhao, Ph.D.
-5 pts for
unwanted files
CSE 330: Operating Systems – Fall 2024
Got 4 out of 4 expected directories
Got 6 out of 6 expected files
Policies
● Late submissions will absolutely not be graded (unless you have verifiable proof of
emergency). It is much better to submit partial work on time and get partial credit for
your work than to submit late for no credit.
● Every student needs to work independently on this exercise. We encourage high-level
discussions among students to help each other understand the concepts and principles.
However, a code-level discussion is prohibited and plagiarism will directly lead to failure
of this course. We will use anti-plagiarism tools to detect violations of this policy.
● The use of generative AI tools is not allowed to complete any portion of the
assignment.
Copyright © Ming Zhao, Ph.D.
CSE 330: Operating Systems – Fall 2024
Project 1: Virtual Machine and Linux
Due by September 06, 2024 11:59 pm September 08, 2024 11:59 pm
Summary
The first project is a warm-up exercise to help you prepare and become familiar with the virtual
machine (VM) and Linux software that you will use extensively for your kernel development
throughout this semester. In this exercise, you need to create a new VM, install a Linux-based
OS on the VM, and install the latest kernel in this Linux system. We will use this VM, OS, kernel
for all the future projects of this course.
Description
Step 1: Create a new VM in VirtualBox.
We will use VMs extensively throughout the projects of this course. They make our lives much
easier as kernel developers. We can conveniently test our new kernels without crashing the
physical machines and take VM snapshots to save the progress of our work. In addition to
completing this step as required in the project, I encourage you to play with your VM and get
familiar with these useful features.
Notes:
● We will work on a 64-bit kernel in our projects, so make sure your VM is 64-bit too.
● Kernel compilation is time-consuming, but it can be accelerated by using multiple CPUs
to compile it in parallel, so give your VM as many cores as your physical machine has.
● Give your VM more than 50-75GB of the virtual disk because building a new kernel
requires a lot of space. But use dynamic allocation so that its actual storage usage grows
as needed.
● Download VirtualBox: https://www.virtualbox.org/wiki/Downloads
● VirtualBox User Manual: https://www.virtualbox.org/manual/
● If you use a Mac with ARM-based CPUs such as M1, M2, and M3, we suggest you use
UTM, instead of VIrtualBox, to create your VM, because VirtualBox has known issues
with supporting this type of system. Reference: https://mac.getutm.app/
Copyright © Ming Zhao, Ph.D.
CSE 330: Operating Systems – Fall 2024
Step 2: Install Ubuntu 24.04 or 24.04.1 on your new VM.
Ubuntu is one of the major GNU/Linux distributions and it is quite user-friendly. In this step, you
will install Ubuntu (either version 24.04 LTS or version 24.04.1 LTS) on your new VM which will
be used for all the projects of this course. (LTS means that this version will be supported for a
long term. 24.04 is the latest LTS version of Ubuntu, released on April 25, 2024. (24.04.1 was
released August 29, 2024, during the window of time given to complete the project so we will
allow either 24.04 or 24.04.1).
Run the following command, lsb_release -a, in a terminal to check the Ubuntu version and
verify you are using Ubuntu 24.04 LTS or Ubuntu 24.04.1 LTS.
Sample Output (from 24.04 LTS):
Notes:


Download Ubuntu
○ x86: Download Ubuntu Desktop | Download | Ubuntu
○ ARM: Download ARM Ubuntu
Installation tutorial :
○ x86:
https://ubuntu.com/tutorials/how-to-run-ubuntu-desktop-on-a-virtual-machineusing-virtualbox#1-overview
○ ARM: https://docs.getutm.app/guides/ubuntu/
Copyright © Ming Zhao, Ph.D.
CSE 330: Operating Systems – Fall 2024
Step 3: Compile and install a new kernel on your new Ubuntu
In this step, you will upgrade the kernel in your VM to the latest stable version which will be
used as the basis for all your kernel development this semester. The below steps should be done
inside the VM.
Basic instructions:
Prepare the environment.
1. Download the long-term stable kernel’s (6.10) source code from linux-6.10.tar.gz
2. Uncompress the file into a folder using tar -xvf linux-6.10.tar.gz. This is your Linux source
code folder.
3. Install the necessary dependencies for kernel compilation such as git, fakeroot,
build-essential, ncurses-dev, xz-utils, libssl-dev, bc, flex, libelf-dev, bison. Hint: You can
use apt-get to install these packages. Refers to this howto.
4.
5.
6.
7.
8.
Compile the kernel. We will perform all the following steps in your Linux source code
folder.
Configure the kernel. We will start with the current kernel’s config file which can be
found at /boot/config-$(uname -r). Copy it to your Linux source code folder. Name this
file as “.config”. This is the configuration file that the kernel compilation will use. Use
make oldconfig to start the configuration process. Press enter to accept all the default
options.
Use make menuconfig to make the following kernel configuration changes and save your
changes when prompted. These changes should be reflected in the .config file. You can
also modify it directly.
For grading purposes, change the new kernel’s version name to include your name. For
example, if your name is Linus Torvalds, your local version string should be
“CSE330Fall2024LinusTorvalds”. You can find this setting in “General setup” -> “Local
version”
Check that the “Symmetric multi-processing support” option is enabled to allow your
kernel to use the multiple cores that your VM has.
Disable the configuration that embeds trusted security keys directly into the kernel
image, which can be used to verify kernel modules before loading them. We don’t need
this feature, so we remove it. In menuconfig, you can find it in Cryptographic API ->
Certificates for signature checking -> “Additional X.509 keys for default system keyring”
and “X.509 certificates to be preloaded into the system blacklist keyring”. Delete the
strings for both options (the parentheses should be empty) and save the changes.
Copyright © Ming Zhao, Ph.D.
CSE 330: Operating Systems – Fall 2024
9. Build the kernel by executing the command make -j4 (this may take a long time, a few
hours, when you do it for the first time). Press enter to accept all the default options.The
-j flag enables parallel compilation to speed up the process. The number after -j specifies
how many threads to use for parallel compilation. You should set it based on the number
of CPUs that your VM has.
Hint: you can check if your compilation is successful by the command make after above
make -j4. It should not report any errors.
10. Build the kernel modules by executing the command make modules -j4
Install the kernel. Now we have successfully compiled the new kernel and its modules.
Next, we install them to the default system folders so they can be used to boot up the
system. Access to these require admin privileges, so you need to use sudo to execute the
following commands.
11. Install the new kernel modules by executing the command make modules_install -j4.
12. Install the new kernel image by executing the command make install -j4.
13. Configure the GRUB boot-loader so it can load the new kernel image that you just built.
By running the update-grub command, GRUB should find all the bootable kernels and
add them to the GRUB menu. Restart Linux and select the new kernel’s entry from the
GRUB menu list. By default the GRUB menu will not be shown; to see it, in
/etc/default/grub change GRUB_TIMEOUT=-1 (or long press shift when reboot) and run
update-grub again; then when you reboot, you should see the menu.
Reboot the VM.
14. Upon next login, check the current running kernel version using uname -a and verify
that you are using your new kernel.
Sample Output (from 24.04 LTS):
References:


Command-line tools are important for kernel development. For example, the above Step
3 requires the use of a variety of command-line tools. To help you become familiar with
the command-line interface, try to do everything from a shell terminal, instead of using
the GUI.
If you don’t know what command to use, the quickest way to find is through a search
Copyright © Ming Zhao, Ph.D.
CSE 330: Operating Systems – Fall 2024



engine. If you don’t understand the usage of a command, the easiest way is to run man
followed by the command name.
There are many Linux command-line references on the Web. Here is a good one:
http://wireless.ictp.it/school_2003/docs/linux/linux_guides/linux_command_reference.
pdf
Follow the principle of least privilege and do not do everything as the admin user. Use
sudo to elevate your privilege only when necessary. Learn how to properly use sudo:
https://help.ubuntu.com/community/RootSudo
Linux boot process
Submission Requirements & Guidelines
Project 1 is due by September 06, 2024 September 08, 2024. Submit your work following the
below guidelines:
● Submission: Submit the following in a Zip file to Canvas:
○ Screenshots of the outputs.
■ You should have one screenshot of the output from step 2 and one
screenshot of the output from step 3.
■ You can use VirtualBox’s screenshot function to take a screenshot (to take
a screenshot in VirtualBox, go to View-> Take Screenshot).
■ For UTM you can use the macOS keyboard shortcut to take a screenshot
(Command + Shift + 3).
■ There MUST be two screenshots with the following names:
● lsb_release.png
● uname.png
Copyright © Ming Zhao, Ph.D.
CSE 330: Operating Systems – Fall 2024
● Canvas submission rules:
○ Create a .zip file with all your submission to include all the aforementioned
screenshots. You should use the following command to create your zip file
(replace the student ID with your actual one):
■ zip Project-1-1225754101.zip uname.png lsb_release.png
○ You MUST name the zip file following the below naming convention.
“Project-1-.zip” e.g., Project-1-1225754101.zip
Note: Any extensions automatically generated by Canvas due to multiple
submission attempts will be managed by the grading script.
○ Do not submit any other source code
○ Do not submit any binaries
● If your submission does not adhere to submission guidelines and naming conventions,
autograding will fail and you will receive zero points.
Testing
● Run the following commands show in the screenshot below in your terminal to obtain
test scripts we have provided to you:
You can alternatively, you HTTPs link to the Github repository to avoid setting up SSH
keys in order to use the repository.
● Use test_zip_contents.sh to ensure your submission adheres to the file layout described
in this document. If any of the screenshots are missing, the script will inform you as well
as giving a summary of the correctness once it is finished running.
● You can refer to the README for instructions on how to use the script.
● If your submission fails to pass test_zip_contents.sh script check during grading you will
receive zero points.
Copyright © Ming Zhao, Ph.D.
CSE 330: Operating Systems – Fall 2024
Grading Rubrics
Criteria
Test
Pts
lsb_release -a
Ubuntu is installed
The output contains the correct
Ubuntu version
New kernel is installed
1. The output contains the
updated kernel version
2. Name in the output should
match with the student’s name.
3. Must be SMP
Expected output (for 24.04 LTS):
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 24.04 LTS
Release:
24.04
Codename: noble
50
uname -a
Check both the kernel version and SMP. Expected
output: Linux vboxuser-VirtualBox
6.10.0CSE330Fall2024LinusTorvalds #1 SMP Tue Jul
30 18:43:02 MST 2024 x86_64 x86_64 x86_64
GNU/Linux
50
./test_zip_contents.sh
Submission Content
-5 pts for
Checking for files
unwanted
1. Zip file should contain only the – File Found: lsb_release.png
files
required screenshots.
– File Found: uname.png
Summary ——————————————————-Got 2 out of 2 expected files
Policies
1. Late submissions will absolutely not be graded (unless you have verifiable proof of
emergency). It is much better to submit partial work on time and get partial credit for
your work than to submit late for no credit.
2. Every student needs to work independently on this exercise. We encourage high-level
discussions among students to help each other understand the concepts and principles.
Copyright © Ming Zhao, Ph.D.
CSE 330: Operating Systems – Fall 2024
However, a code-level discussion is prohibited and plagiarism will directly lead to failure
of this course. We will use anti-plagiarism tools to detect violations of this policy.
3. The use of generative AI tools is not allowed to complete any portion of the
assignment.
Copyright © Ming Zhao, Ph.D.

Are you stuck with your online class?
Get help from our team of writers!

Order your essay today and save 20% with the discount code RAPID