07 Creating A System Call in Linux
07 Creating A System Call in Linux
Tushar B. Kute,
http://tusharkute.com
x86 Protection Rings
Privileged instructions
Can be executed only
When current privileged
Level (CPL) is 0
Operating system
kernel
Level 0
Operating system
services Level 1
Level 2
Applications
Level 3
Monolithic Kernel
re
ca
tur
ll
n
– NT.
entry
Kernel
many many things
Micro Kernel
• Micro-kernel is “micro”
– Services are User
Services
program
implemented as regular
process.
re
ca
tur
ll
– Micro-kernel get
n
services on behalf of
entry
users by messaging with
the service processes. kernel
re
• Makes a system call with ca
tur
ll
n
parameters.
• The call mechanism switches entry
code to kernel mode.
Kernel in protected
• Execute system call. memory
Interrupt
service
HW Device Sys_call_table routines
Interrupt
VM manager’s
HW implementation of the pager
boundary
Library function vs. System Call
strace and ltrace
strace
/linux-3.18.7 scripts
Documentation
acorn 802
atm adfs asm-alpha appletalk
alpha block affs adfs atm
asm-arm affs
arm cdrom autofs asm-generic ax25
i386 char autofs4 autofs bridge
asm-i386 autofs4
ia64 dio bfs asm-ia64 core
m68k fc4 code bfs decnet
asm-m68k code
mips i2c cramfs asm-mips econet
mips64 i2o devfs cramfs ethernet
asm-mips64 devfs
ppc ide devpts linux ipv4
s390 ieee1394 efs devpts ipv6
math-emu efs
sh isdn ext2 net ipx
sparc macintosh fat ext2 irda
pcmcia fat
sparc64 misc hfs scsi khttpd
net hpfs hfs lapb
video … hpfs …
… … …
Define a new system call
#include <linux/kernel.h>
asmlinkage long sys_hello(void)
{
printk(KERN_INFO “Hello world\n”);
return 0;
}
Create Makefile
• cd include/linux/
• gedit syscalls.h
– add the following line to the end of the file just
before the #endif statement at the very bottom.
– asmlinkage long sys_hello(void);
• This defines the prototype of the function of our
system call.”asmlinkage” is a key word used to indicate
that all parameters of the function would be
available on the stack.
• Now compile the linux source code according to the
standard procedure.
Test the system call
Blogs
Web Resources
http://digitallocha.blogspot.in
http://tusharkute.com
http://kyamputar.blogspot.in