SlideShare a Scribd company logo
1 of 22
-
Operating System Project Report
Adding System Call To Kernel
10/24/2016
Muhammad Bilal – 140666
Tamoor Tanvir – 130888
ShahZaman Marwat - 130852
Step 1
As we will have to write sudo in start of approx. every command, So in order to
remove this difficulty, write sudo su on terminal and give your password and than
you will be free to give password on every command.
sudo su
Step 2
Download kernel either from https://www.kernel.org/pub/linux/kernel/v3.x/ or
https://www.kernel.org/ .
Note:In my case, I was using VMware and I downloaded kernel on windows, later
when I tried to copykernel from Windows to VMware Ubuntu, Paste option was
hide. So use browser of Ubuntu to download kernel.
Now your downloaded kernel will be in Download directory.
Now copying the kernel sourcefrom the downloads to the usr/src directory.
For this first go to Downloads directory
cd Downloads
Enter the following code:
cp –r linux-4.8.4 /usr/src
Step 3
Prerequisites:
Enter the following codes line by line to make sure you have all the necessary and
required packages to add a system call and then compile the kernel successfully.
apt-get update
apt-get upgrade
apt-get install kernel-package
apt-get install libncurses-dev
If prompted for a yes/No enter Y for yes and press enter to allow the download
again this may take some time depending on the internet speed.
You will get a screen like this after all the packages have been installed
Step 4
Now direct yourself to the directory of the linux-4.8.4 in usr/src with the following
command:
cd /usr/src/linux-4.8.4
Now create a new folder named hello in linux-4.8.4 directory using mkdir hello.
NOTE:You canmake this hello directory manually by going to linux-4.2.8
directory and then right click on screenand create a new folder and rename it
to hello.
Now change into hello directory to proceed further.
cd hello
Now your terminal is looking like this:
Step 5
Create a “hello.c” file in the hello folder with the following code:
vim hello.c
NOTE:In my case, whenI wrote vim hello.c, I got error that vim is not
installed, so for installing vim, you have to write apt install vim on terminal.
Once you enter the above command it will open a text editor in the terminal.
Simply paste these lines of codethere
#include <linux/kernel.h>
Asmlinkage long sys_hello(void)
{
Printk(“Hello World!n”); //printk prints the message to the kernels logs
return 0;
}
Your screen should now look like this:
Now just press Esc key to leave insert mode and then type :wq and press enter
which will save the file and exit VM editor.
Step 7
Create the Makefile in the hello directory.
vim Makefile
Using the same process as we did before, add the following line in the opened up
vim text editor and save it by first hitting the Esc key then typing :wq and then
press enter.
obj-y := hello.o
Step 9
Add the hello directory (recently you have created in linux-4.8.4 directory) to the
Main kernel Makefile.
For this first you have to step out of the hello folder back to the linux directory and
open the Makefile there for editing:
$ cd .. OR $ cd /usr/src/linux-4.8.4
$ vim Makefile
Navigate to line 893 (may vary but will be somewhere close to this number) to find
the following line:
Core-y += kernel/ mm/ fs/ ipc/ security/ cryptop/block/
Now add “hello/” at the end of it:
Core-y += kernel/ mm/ fs/ ipc/ security/ cryptop/block/ hello/
NOTE:There is a space after every slash ( / ).
This tells our compiler that the source codeof sys_hello() lies in the hello
directory.
Step 10
Add sys_hello() into the syscall table
Navigate to this directory:
$ cd usr/src/linux-4.8.4/arch/x86/entry/syscalls
Now if your OS is 32-bit. Write this on terminal gedit syscall_32.tbl
Then add the following line at the end where integer count ends and increment
integers by one (In this case, if integers end at 379, than write this line with the
start of 380) and write it
380 i386 hello sys_hello
Now if your OS is 64-bit. Write this on terminal gedit syscall_64.tbl
Then add the following line at the end where integer count ends and increment
integers by one (In this case, if integers end at 379, than write this line with the
start of 380) and write it
329 64 hello sys_hello
Step 11
Add the sys_hello() in the sysc-alls.h header file and open the syscalls.h file
for editing:
Navigate to this directory:
$ cd /usr/src/linux-4.8.4/include/linux
gedit syscalls.h
Now add the following line just before the #endif statement:
asmlinkage long sys_hello(void);
Save it and close it.
Step 12
Now create the config file:
Navigate to this directory:
$ cd /usr/src/linux-4.8.4/ and write this in terminal make menuconfig
Incase you get an error stating that you do not have the curses.hfile then simply
input the following command to download and install it and then try the previous
step:
apt-get install libncurses5-dev libncursesw5-dev
Now a screen like this should appear:
(Simply ChooseSave and then Exit to select the default values)
Step 13
Build the Kernel
This is the longest step of the process.The build will take 2 to 3 HOURS.
Navigate to this directory:
$ cd /usr/src/linux-4.8.4
To increase the speed of the build enters the command below:
export CONCURRENCY_LEVEL=3 # 1+number of cores on your processor
Now enter the following command to build the kernel make
NOTE:After writing make command to build my kernel. I facedthis error of
openssl/opensslv.h:No such file or directory, Compilation terminated.
SOLUTION:
Navigate to your home directory and now install these:
apt-get install openssl
apt-get install cl-plus-ssl
apt-get install libssl-ocaml
apt-get install libsslcommon2
apt-get install libsslcommon2-dev
apt-get install libssl-dev
apt-get install libssl-doc
apt install openssn
Now navigate to linux-4.8.4 directory and write make. Compilation will start
Step 14
Once the build is complete it will return to the main linux-4.8.4 folder directory
Now install the kernel with the following command:
Make modules_install install
Now rebootyour operating system for the newly installed linux kernel to take
effect.
reboot
After rebootto chec5k for your version of kernel that is installed type the
following command:
uname -r
My result returned: 4.8.4
Step 12
Test the system call:
Create a program that uses your system call and you may call it what ever you like.
I’m going to call mine “test.c”
Add the following codeto it:
#include <stdio.h>
#include <linux/kernel.h>
#include <sys/syscall.h>
#include <unistd.h>
int main()
{
long int sys = syscall(380); // 380 is the sys_hello number I used
to add the sys_call
printf(“System call sys_hello returned %ldn”, sys); // 0 shows that
our program returns 0 and works
return 0;
}
Then compile it using the standard gcc compiler with the following code:
gcc –o test test.c
And execute with this:
./test
The result should show this:
System call sys_hello returned 0. Now type the following command to display
the kernel message which should show “Hello World”:
dmesg
THE END

More Related Content

What's hot

Bai tap chung_chi_b_-_acc1_ver02
Bai tap chung_chi_b_-_acc1_ver02Bai tap chung_chi_b_-_acc1_ver02
Bai tap chung_chi_b_-_acc1_ver02leevo2015
 
Báo cáo kết quả nghiên cứu Magento
Báo cáo kết quả nghiên cứu MagentoBáo cáo kết quả nghiên cứu Magento
Báo cáo kết quả nghiên cứu MagentoLel Đặng Văn
 
CÁC BÀI TOÁN KHAI PHÁ DỮ LIỆU VÀ ỨNG DỤNG CỦA KHAI PHÁ DỮ LIỆU.pdf
CÁC BÀI TOÁN KHAI PHÁ DỮ LIỆU VÀ ỨNG  DỤNG CỦA KHAI PHÁ DỮ LIỆU.pdfCÁC BÀI TOÁN KHAI PHÁ DỮ LIỆU VÀ ỨNG  DỤNG CỦA KHAI PHÁ DỮ LIỆU.pdf
CÁC BÀI TOÁN KHAI PHÁ DỮ LIỆU VÀ ỨNG DỤNG CỦA KHAI PHÁ DỮ LIỆU.pdfMan_Ebook
 
chuong 4. dai so boole
chuong 4.  dai so boolechuong 4.  dai so boole
chuong 4. dai so boolekikihoho
 
Chuong 4. lap trinh hop ngu
Chuong 4. lap trinh hop nguChuong 4. lap trinh hop ngu
Chuong 4. lap trinh hop ngumituan
 
Hỗ trợ ra quyết định
Hỗ trợ ra quyết địnhHỗ trợ ra quyết định
Hỗ trợ ra quyết địnhlmphuong06
 
csdl-trigger
csdl-triggercsdl-trigger
csdl-triggerkikihoho
 
Sử dụng API Leaflet chi tiết các chức năng
Sử dụng API Leaflet chi tiết các chức năngSử dụng API Leaflet chi tiết các chức năng
Sử dụng API Leaflet chi tiết các chức năngHao CT
 
Verilog 모듈 연결하기
Verilog 모듈 연결하기Verilog 모듈 연결하기
Verilog 모듈 연결하기Jihyun Lee
 
Ngân hàng câu hỏi trắc nghiệm kiến trúc máy tính
Ngân hàng câu hỏi trắc nghiệm kiến trúc máy tínhNgân hàng câu hỏi trắc nghiệm kiến trúc máy tính
Ngân hàng câu hỏi trắc nghiệm kiến trúc máy tínhkakalaxaxa
 
lap trinh assembly cho VXL
lap trinh  assembly cho VXLlap trinh  assembly cho VXL
lap trinh assembly cho VXLThân Khương
 
Functional dependencies PHỤ THUỘC HÀM
Functional dependencies PHỤ THUỘC HÀMFunctional dependencies PHỤ THUỘC HÀM
Functional dependencies PHỤ THUỘC HÀMJean Vũ
 
Ngân hàng câu hỏi kiến trúc máy tính
Ngân hàng câu hỏi kiến trúc máy tínhNgân hàng câu hỏi kiến trúc máy tính
Ngân hàng câu hỏi kiến trúc máy tínhCao Toa
 
Tim hieu thanh ghi in asm
Tim hieu thanh ghi in asmTim hieu thanh ghi in asm
Tim hieu thanh ghi in asmMy Đá
 

What's hot (20)

Bai tap java
Bai tap javaBai tap java
Bai tap java
 
Bai tap chung_chi_b_-_acc1_ver02
Bai tap chung_chi_b_-_acc1_ver02Bai tap chung_chi_b_-_acc1_ver02
Bai tap chung_chi_b_-_acc1_ver02
 
Báo cáo kết quả nghiên cứu Magento
Báo cáo kết quả nghiên cứu MagentoBáo cáo kết quả nghiên cứu Magento
Báo cáo kết quả nghiên cứu Magento
 
Ktmt chuong 3
Ktmt chuong 3Ktmt chuong 3
Ktmt chuong 3
 
Cơ sở dữ liệu nâng cao
Cơ sở dữ liệu nâng caoCơ sở dữ liệu nâng cao
Cơ sở dữ liệu nâng cao
 
CÁC BÀI TOÁN KHAI PHÁ DỮ LIỆU VÀ ỨNG DỤNG CỦA KHAI PHÁ DỮ LIỆU.pdf
CÁC BÀI TOÁN KHAI PHÁ DỮ LIỆU VÀ ỨNG  DỤNG CỦA KHAI PHÁ DỮ LIỆU.pdfCÁC BÀI TOÁN KHAI PHÁ DỮ LIỆU VÀ ỨNG  DỤNG CỦA KHAI PHÁ DỮ LIỆU.pdf
CÁC BÀI TOÁN KHAI PHÁ DỮ LIỆU VÀ ỨNG DỤNG CỦA KHAI PHÁ DỮ LIỆU.pdf
 
Modified booth
Modified boothModified booth
Modified booth
 
chuong 4. dai so boole
chuong 4.  dai so boolechuong 4.  dai so boole
chuong 4. dai so boole
 
Chuong 4. lap trinh hop ngu
Chuong 4. lap trinh hop nguChuong 4. lap trinh hop ngu
Chuong 4. lap trinh hop ngu
 
Ứng dụng mô hình xích Markov và chuỗi thời gian mờ trong dự báo
Ứng dụng mô hình xích Markov và chuỗi thời gian mờ trong dự báoỨng dụng mô hình xích Markov và chuỗi thời gian mờ trong dự báo
Ứng dụng mô hình xích Markov và chuỗi thời gian mờ trong dự báo
 
Hỗ trợ ra quyết định
Hỗ trợ ra quyết địnhHỗ trợ ra quyết định
Hỗ trợ ra quyết định
 
csdl-trigger
csdl-triggercsdl-trigger
csdl-trigger
 
Sử dụng API Leaflet chi tiết các chức năng
Sử dụng API Leaflet chi tiết các chức năngSử dụng API Leaflet chi tiết các chức năng
Sử dụng API Leaflet chi tiết các chức năng
 
Verilog 모듈 연결하기
Verilog 모듈 연결하기Verilog 모듈 연결하기
Verilog 모듈 연결하기
 
Luận văn: Nhận dạng cảm xúc khuôn mặt người, HAY, 9đ
Luận văn: Nhận dạng cảm xúc khuôn mặt người, HAY, 9đLuận văn: Nhận dạng cảm xúc khuôn mặt người, HAY, 9đ
Luận văn: Nhận dạng cảm xúc khuôn mặt người, HAY, 9đ
 
Ngân hàng câu hỏi trắc nghiệm kiến trúc máy tính
Ngân hàng câu hỏi trắc nghiệm kiến trúc máy tínhNgân hàng câu hỏi trắc nghiệm kiến trúc máy tính
Ngân hàng câu hỏi trắc nghiệm kiến trúc máy tính
 
lap trinh assembly cho VXL
lap trinh  assembly cho VXLlap trinh  assembly cho VXL
lap trinh assembly cho VXL
 
Functional dependencies PHỤ THUỘC HÀM
Functional dependencies PHỤ THUỘC HÀMFunctional dependencies PHỤ THUỘC HÀM
Functional dependencies PHỤ THUỘC HÀM
 
Ngân hàng câu hỏi kiến trúc máy tính
Ngân hàng câu hỏi kiến trúc máy tínhNgân hàng câu hỏi kiến trúc máy tính
Ngân hàng câu hỏi kiến trúc máy tính
 
Tim hieu thanh ghi in asm
Tim hieu thanh ghi in asmTim hieu thanh ghi in asm
Tim hieu thanh ghi in asm
 

Similar to Adding System Call to Kernel

Part 4 Scripting and Virtualization (due Week 7)Objectives1. .docx
Part 4 Scripting and Virtualization (due Week 7)Objectives1. .docxPart 4 Scripting and Virtualization (due Week 7)Objectives1. .docx
Part 4 Scripting and Virtualization (due Week 7)Objectives1. .docxkarlhennesey
 
Install websphere message broker 8 RHEL 6 64 bits
Install websphere message broker 8 RHEL 6 64 bitsInstall websphere message broker 8 RHEL 6 64 bits
Install websphere message broker 8 RHEL 6 64 bitsManuel Vega
 
Installation of ubuntu, ns3 and compiling first
Installation of ubuntu, ns3 and compiling firstInstallation of ubuntu, ns3 and compiling first
Installation of ubuntu, ns3 and compiling firstJawad Khan
 
Project 2 how to install and compile os161
Project 2 how to install and compile os161Project 2 how to install and compile os161
Project 2 how to install and compile os161Xiao Qin
 
Kannel configuration step by step with Motorolla Razer
Kannel configuration step by step with Motorolla RazerKannel configuration step by step with Motorolla Razer
Kannel configuration step by step with Motorolla RazerMahtab Rasheed
 
Howtoinstallarchlinuxtousb final-120610172253-phpapp01
Howtoinstallarchlinuxtousb final-120610172253-phpapp01Howtoinstallarchlinuxtousb final-120610172253-phpapp01
Howtoinstallarchlinuxtousb final-120610172253-phpapp01decenttr
 
Installing Lamp Stack on Ubuntu Instance
Installing Lamp Stack on Ubuntu InstanceInstalling Lamp Stack on Ubuntu Instance
Installing Lamp Stack on Ubuntu Instancekamarul kawnayeen
 
How to Install ArchLinux to a USB Flashdrive in 2012
How to Install ArchLinux to a USB Flashdrive in 2012How to Install ArchLinux to a USB Flashdrive in 2012
How to Install ArchLinux to a USB Flashdrive in 2012Chukwuma Onyeije, MD, FACOG
 
Installing Hortonworks Hadoop for Windows
Installing Hortonworks Hadoop for WindowsInstalling Hortonworks Hadoop for Windows
Installing Hortonworks Hadoop for WindowsJonathan Bloom
 
Final opensource record 2019
Final opensource record 2019Final opensource record 2019
Final opensource record 2019Karthik Sekhar
 
Mantis Installation for Windows Box
Mantis Installation for Windows BoxMantis Installation for Windows Box
Mantis Installation for Windows Boxguest34a3a419
 
Mantis Installation for Windows Box
Mantis Installation for Windows BoxMantis Installation for Windows Box
Mantis Installation for Windows BoxJayanta Dash
 

Similar to Adding System Call to Kernel (20)

Part 4 Scripting and Virtualization (due Week 7)Objectives1. .docx
Part 4 Scripting and Virtualization (due Week 7)Objectives1. .docxPart 4 Scripting and Virtualization (due Week 7)Objectives1. .docx
Part 4 Scripting and Virtualization (due Week 7)Objectives1. .docx
 
Linux
LinuxLinux
Linux
 
Unix Administration 2
Unix Administration 2Unix Administration 2
Unix Administration 2
 
Install websphere message broker 8 RHEL 6 64 bits
Install websphere message broker 8 RHEL 6 64 bitsInstall websphere message broker 8 RHEL 6 64 bits
Install websphere message broker 8 RHEL 6 64 bits
 
Install guide
Install guideInstall guide
Install guide
 
Install guide
Install guideInstall guide
Install guide
 
Installation of ubuntu, ns3 and compiling first
Installation of ubuntu, ns3 and compiling firstInstallation of ubuntu, ns3 and compiling first
Installation of ubuntu, ns3 and compiling first
 
Project 2 how to install and compile os161
Project 2 how to install and compile os161Project 2 how to install and compile os161
Project 2 how to install and compile os161
 
Kannel configuration step by step with Motorolla Razer
Kannel configuration step by step with Motorolla RazerKannel configuration step by step with Motorolla Razer
Kannel configuration step by step with Motorolla Razer
 
Howtoinstallarchlinuxtousb final-120610172253-phpapp01
Howtoinstallarchlinuxtousb final-120610172253-phpapp01Howtoinstallarchlinuxtousb final-120610172253-phpapp01
Howtoinstallarchlinuxtousb final-120610172253-phpapp01
 
LIGGGHTS installation-guide
LIGGGHTS installation-guideLIGGGHTS installation-guide
LIGGGHTS installation-guide
 
Installing Lamp Stack on Ubuntu Instance
Installing Lamp Stack on Ubuntu InstanceInstalling Lamp Stack on Ubuntu Instance
Installing Lamp Stack on Ubuntu Instance
 
How to Install ArchLinux to a USB Flashdrive in 2012
How to Install ArchLinux to a USB Flashdrive in 2012How to Install ArchLinux to a USB Flashdrive in 2012
How to Install ArchLinux to a USB Flashdrive in 2012
 
Linux
Linux Linux
Linux
 
Installing Hortonworks Hadoop for Windows
Installing Hortonworks Hadoop for WindowsInstalling Hortonworks Hadoop for Windows
Installing Hortonworks Hadoop for Windows
 
Final opensource record 2019
Final opensource record 2019Final opensource record 2019
Final opensource record 2019
 
Mantis Installation for Windows Box
Mantis Installation for Windows BoxMantis Installation for Windows Box
Mantis Installation for Windows Box
 
Mantis Installation for Windows Box
Mantis Installation for Windows BoxMantis Installation for Windows Box
Mantis Installation for Windows Box
 
Clustering manual
Clustering manualClustering manual
Clustering manual
 
Ch02.pdf
Ch02.pdfCh02.pdf
Ch02.pdf
 

Recently uploaded

MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 

Recently uploaded (20)

MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 

Adding System Call to Kernel

  • 1. - Operating System Project Report Adding System Call To Kernel 10/24/2016 Muhammad Bilal – 140666 Tamoor Tanvir – 130888 ShahZaman Marwat - 130852
  • 2. Step 1 As we will have to write sudo in start of approx. every command, So in order to remove this difficulty, write sudo su on terminal and give your password and than you will be free to give password on every command. sudo su Step 2 Download kernel either from https://www.kernel.org/pub/linux/kernel/v3.x/ or https://www.kernel.org/ . Note:In my case, I was using VMware and I downloaded kernel on windows, later when I tried to copykernel from Windows to VMware Ubuntu, Paste option was hide. So use browser of Ubuntu to download kernel.
  • 3. Now your downloaded kernel will be in Download directory.
  • 4. Now copying the kernel sourcefrom the downloads to the usr/src directory. For this first go to Downloads directory cd Downloads Enter the following code:
  • 5. cp –r linux-4.8.4 /usr/src Step 3 Prerequisites: Enter the following codes line by line to make sure you have all the necessary and required packages to add a system call and then compile the kernel successfully. apt-get update apt-get upgrade apt-get install kernel-package apt-get install libncurses-dev
  • 6. If prompted for a yes/No enter Y for yes and press enter to allow the download again this may take some time depending on the internet speed. You will get a screen like this after all the packages have been installed Step 4 Now direct yourself to the directory of the linux-4.8.4 in usr/src with the following command: cd /usr/src/linux-4.8.4 Now create a new folder named hello in linux-4.8.4 directory using mkdir hello. NOTE:You canmake this hello directory manually by going to linux-4.2.8 directory and then right click on screenand create a new folder and rename it to hello. Now change into hello directory to proceed further.
  • 7. cd hello Now your terminal is looking like this: Step 5 Create a “hello.c” file in the hello folder with the following code: vim hello.c NOTE:In my case, whenI wrote vim hello.c, I got error that vim is not installed, so for installing vim, you have to write apt install vim on terminal.
  • 8. Once you enter the above command it will open a text editor in the terminal. Simply paste these lines of codethere #include <linux/kernel.h> Asmlinkage long sys_hello(void) { Printk(“Hello World!n”); //printk prints the message to the kernels logs return 0; } Your screen should now look like this: Now just press Esc key to leave insert mode and then type :wq and press enter which will save the file and exit VM editor.
  • 9. Step 7 Create the Makefile in the hello directory. vim Makefile Using the same process as we did before, add the following line in the opened up vim text editor and save it by first hitting the Esc key then typing :wq and then press enter. obj-y := hello.o Step 9
  • 10. Add the hello directory (recently you have created in linux-4.8.4 directory) to the Main kernel Makefile. For this first you have to step out of the hello folder back to the linux directory and open the Makefile there for editing: $ cd .. OR $ cd /usr/src/linux-4.8.4 $ vim Makefile Navigate to line 893 (may vary but will be somewhere close to this number) to find the following line: Core-y += kernel/ mm/ fs/ ipc/ security/ cryptop/block/ Now add “hello/” at the end of it: Core-y += kernel/ mm/ fs/ ipc/ security/ cryptop/block/ hello/ NOTE:There is a space after every slash ( / ).
  • 11. This tells our compiler that the source codeof sys_hello() lies in the hello directory. Step 10 Add sys_hello() into the syscall table Navigate to this directory: $ cd usr/src/linux-4.8.4/arch/x86/entry/syscalls
  • 12. Now if your OS is 32-bit. Write this on terminal gedit syscall_32.tbl Then add the following line at the end where integer count ends and increment integers by one (In this case, if integers end at 379, than write this line with the start of 380) and write it 380 i386 hello sys_hello Now if your OS is 64-bit. Write this on terminal gedit syscall_64.tbl Then add the following line at the end where integer count ends and increment integers by one (In this case, if integers end at 379, than write this line with the start of 380) and write it 329 64 hello sys_hello
  • 13. Step 11 Add the sys_hello() in the sysc-alls.h header file and open the syscalls.h file for editing: Navigate to this directory: $ cd /usr/src/linux-4.8.4/include/linux gedit syscalls.h
  • 14. Now add the following line just before the #endif statement: asmlinkage long sys_hello(void);
  • 15. Save it and close it. Step 12 Now create the config file: Navigate to this directory: $ cd /usr/src/linux-4.8.4/ and write this in terminal make menuconfig Incase you get an error stating that you do not have the curses.hfile then simply input the following command to download and install it and then try the previous step: apt-get install libncurses5-dev libncursesw5-dev
  • 16. Now a screen like this should appear: (Simply ChooseSave and then Exit to select the default values)
  • 18. Build the Kernel This is the longest step of the process.The build will take 2 to 3 HOURS. Navigate to this directory: $ cd /usr/src/linux-4.8.4 To increase the speed of the build enters the command below: export CONCURRENCY_LEVEL=3 # 1+number of cores on your processor Now enter the following command to build the kernel make NOTE:After writing make command to build my kernel. I facedthis error of openssl/opensslv.h:No such file or directory, Compilation terminated.
  • 19. SOLUTION: Navigate to your home directory and now install these: apt-get install openssl apt-get install cl-plus-ssl apt-get install libssl-ocaml apt-get install libsslcommon2 apt-get install libsslcommon2-dev apt-get install libssl-dev apt-get install libssl-doc apt install openssn
  • 20. Now navigate to linux-4.8.4 directory and write make. Compilation will start Step 14 Once the build is complete it will return to the main linux-4.8.4 folder directory Now install the kernel with the following command: Make modules_install install Now rebootyour operating system for the newly installed linux kernel to take effect. reboot
  • 21. After rebootto chec5k for your version of kernel that is installed type the following command: uname -r My result returned: 4.8.4 Step 12 Test the system call: Create a program that uses your system call and you may call it what ever you like. I’m going to call mine “test.c” Add the following codeto it: #include <stdio.h> #include <linux/kernel.h> #include <sys/syscall.h> #include <unistd.h> int main() { long int sys = syscall(380); // 380 is the sys_hello number I used to add the sys_call printf(“System call sys_hello returned %ldn”, sys); // 0 shows that our program returns 0 and works return 0; } Then compile it using the standard gcc compiler with the following code: gcc –o test test.c And execute with this: ./test The result should show this: System call sys_hello returned 0. Now type the following command to display the kernel message which should show “Hello World”: dmesg