15. USER MODE KERNEL MODE
system_call:
….
sys_xyz()
….
SYSEXIT
sys_xyz(){
…
}
xyz(){
….
SYSCALL
….
}
...
xyz();
...
API of system call system call routin
in standard library
systemcall handler systemcall service routine
15/24SystemCall in Linux
18. syscall_table.S
Add “.long sys_mycall" at the end of the list کنیممیتعریفارسیستماخوانرف نام
18/24
unistd.h
Add "#define __NR_mycall <Last_System_Call_Num+ 1>" at the end of the
list.
If the last system call defined here is:
"#define __NR_vmsplice316", then add:
"#define __NR_mycall317" at the end of the list.
And change "#define NR_syscalls 317" to:
"#define NR_syscalls 318"
syscalls.h
Add "asmlinkage long sys_mycall(int i);” at the end of the file
Modify
SystemCall in Linux
20. 20/24
Creat
testmycall.c
که ای پوشه همان در هم ار فایل اینtestmycall.hیمزسا می ، ساختیم ار.
#include<stdio.h>
#include<syscalls.h>
#include "testmycall.h"
int main(void)
{
printf("%dn", mycall(15));
}
long mycall(int i)
{
return syscall(__NR_mycall, i);
}
SystemCall in Linux
21. socket() : int socket(int domain, int type, int protocol);
create an endpoint for communication and returns a
descriptor
21/24
domain
selects the protocol family which will be used for
communication. These families are defined in
<sys/socket.h>
Local communication, IPv4 ,IPv6 , IPX - Novell , Kernel user interface
device ,ITU-T X.25 / ISO-8208 ,etc.
type
which specifies the communication semantics
SOCK_STREAM : Provides sequenced, reliable, two-way, connection-
based byte streams. An out-of-band data transmission mechanism may
be supported.
SOCK_RAW : Provides raw network protocol access.
SystemCall in Linux
22. Connect () :
int connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen);
22/24
Sockfd : number of socket discriptor
*serv_addr : address of table
addrlen : kind of addressing
Listen () : int listen(int sockfd, int backlog);
Socket Used to for listening Inline
backlog : defines the maximum length the queue of
pending connections may grow to
SystemCall in Linux
23. Refrences:
- understanding the linux kernel , 3rd edition , by Daniel P.Bovet, Marco Cesati
-Implement a Sys Call on Linux 2.6 for i386 , by Amit Choudhary
- INTEL 80386 PROGRAMMER'S REFERENCE MANUAL
-Operating Systems Design and Implementation, Third Edition, By Andrew S. Tanenbaum
-Operating System Concepts ,Abraham Silberschatz,(2013)
23/24SystemCall in Linux