![Page 1: IKO31204 Pemrograman Sistem Jilid 8: System Call fileIKO31204 Pemrograman Sistem Jilid 8: System Call Fakultas Ilmu Komputer Universitas Indonesia Sep 2012](https://reader030.vdocuments.us/reader030/viewer/2022041206/5d5d4ab188c9932a5b8b4594/html5/thumbnails/1.jpg)
IKO31204 Pemrograman Sistem
Jilid 8: System Call
Fakultas Ilmu Komputer Universitas IndonesiaSep 2012
![Page 2: IKO31204 Pemrograman Sistem Jilid 8: System Call fileIKO31204 Pemrograman Sistem Jilid 8: System Call Fakultas Ilmu Komputer Universitas Indonesia Sep 2012](https://reader030.vdocuments.us/reader030/viewer/2022041206/5d5d4ab188c9932a5b8b4594/html5/thumbnails/2.jpg)
topikSystem call
![Page 3: IKO31204 Pemrograman Sistem Jilid 8: System Call fileIKO31204 Pemrograman Sistem Jilid 8: System Call Fakultas Ilmu Komputer Universitas Indonesia Sep 2012](https://reader030.vdocuments.us/reader030/viewer/2022041206/5d5d4ab188c9932a5b8b4594/html5/thumbnails/3.jpg)
referensiHOWTO Add a system call to the 2.6 Kernel http://www.csee.umbc.edu/~chettri/421/projects/hello_syscall.html
Implementing System Call on Linux 2.6 for i386http://linuxkernel51.blogspot.com/2011/01/ implementingsystemcallonlinux26.html
System Callhttp://en.wikipedia.org/wiki/System_call
![Page 4: IKO31204 Pemrograman Sistem Jilid 8: System Call fileIKO31204 Pemrograman Sistem Jilid 8: System Call Fakultas Ilmu Komputer Universitas Indonesia Sep 2012](https://reader030.vdocuments.us/reader030/viewer/2022041206/5d5d4ab188c9932a5b8b4594/html5/thumbnails/4.jpg)
referensiCompiling Kernel Source (SysCall)http://linuxkernel51.blogspot.com/2011/01/compilingkernelsource.html
How to Invoke System Call in Applicationhttp://linuxkernel51.blogspot.com/2011/02/howtoinvokesystemcallin.html
SYSCALLS(2) Linux Programmer's Manual http://www.kernel.org/doc/manpages/online/pages/man2/syscalls.2.html
![Page 5: IKO31204 Pemrograman Sistem Jilid 8: System Call fileIKO31204 Pemrograman Sistem Jilid 8: System Call Fakultas Ilmu Komputer Universitas Indonesia Sep 2012](https://reader030.vdocuments.us/reader030/viewer/2022041206/5d5d4ab188c9932a5b8b4594/html5/thumbnails/5.jpg)
referensiSysCallshttp://www.gnu.org/software/libc/manual/html_node/SystemCalls.html
![Page 6: IKO31204 Pemrograman Sistem Jilid 8: System Call fileIKO31204 Pemrograman Sistem Jilid 8: System Call Fakultas Ilmu Komputer Universitas Indonesia Sep 2012](https://reader030.vdocuments.us/reader030/viewer/2022041206/5d5d4ab188c9932a5b8b4594/html5/thumbnails/6.jpg)
Apa itu Syscall ?
Syscall adalah adalah mekanisme yang digunakan oleh aplikasi (user level) untuk meminta layanan dari sistem operasi (kernel).
![Page 7: IKO31204 Pemrograman Sistem Jilid 8: System Call fileIKO31204 Pemrograman Sistem Jilid 8: System Call Fakultas Ilmu Komputer Universitas Indonesia Sep 2012](https://reader030.vdocuments.us/reader030/viewer/2022041206/5d5d4ab188c9932a5b8b4594/html5/thumbnails/7.jpg)
LokasiSyscallberoperasi
![Page 8: IKO31204 Pemrograman Sistem Jilid 8: System Call fileIKO31204 Pemrograman Sistem Jilid 8: System Call Fakultas Ilmu Komputer Universitas Indonesia Sep 2012](https://reader030.vdocuments.us/reader030/viewer/2022041206/5d5d4ab188c9932a5b8b4594/html5/thumbnails/8.jpg)
Wujud dari Syscall
Syscall berwujud sebuah method yang direpresentasikan sebagai nomor panggil unik yang harus didaftarkan di dalam berkas syscall_table_32.S pada source code kernel
Setiap nomor panggil dilayani oleh sebuah fungsi di dalam kernel
![Page 9: IKO31204 Pemrograman Sistem Jilid 8: System Call fileIKO31204 Pemrograman Sistem Jilid 8: System Call Fakultas Ilmu Komputer Universitas Indonesia Sep 2012](https://reader030.vdocuments.us/reader030/viewer/2022041206/5d5d4ab188c9932a5b8b4594/html5/thumbnails/9.jpg)
Memanggil Syscall
1. dapat langsung dipanggil2. menggunakan perantara library
![Page 10: IKO31204 Pemrograman Sistem Jilid 8: System Call fileIKO31204 Pemrograman Sistem Jilid 8: System Call Fakultas Ilmu Komputer Universitas Indonesia Sep 2012](https://reader030.vdocuments.us/reader030/viewer/2022041206/5d5d4ab188c9932a5b8b4594/html5/thumbnails/10.jpg)
Cth pemanggilan langsung
int syscall(int number, arg1, arg2, arg3, dst ….. );
#include <unistd.h>#include <sys/syscall.h>#include <errno.h>#include <stdio.h>
int main() { int rc; rc = syscall(SYS_chmod, "tes", 0644); if (rc == 1) fprintf(stderr, "chmod failed, errno = %d\n", errno);}
![Page 11: IKO31204 Pemrograman Sistem Jilid 8: System Call fileIKO31204 Pemrograman Sistem Jilid 8: System Call Fakultas Ilmu Komputer Universitas Indonesia Sep 2012](https://reader030.vdocuments.us/reader030/viewer/2022041206/5d5d4ab188c9932a5b8b4594/html5/thumbnails/11.jpg)
Memanggil via Library#include <syscall.h>#include <unistd.h>#include <stdio.h>#include <sys/types.h>
int main(void) {long ID;/**//* "libc" wrapped system call *//* SYS_getpid (Func No. is 20) *//**/ID = getpid();printf ("getpid()=%ld\n", ID);return(0);
}
![Page 12: IKO31204 Pemrograman Sistem Jilid 8: System Call fileIKO31204 Pemrograman Sistem Jilid 8: System Call Fakultas Ilmu Komputer Universitas Indonesia Sep 2012](https://reader030.vdocuments.us/reader030/viewer/2022041206/5d5d4ab188c9932a5b8b4594/html5/thumbnails/12.jpg)
Peta Syscall
Mapping nomor Syscall:<kernel source>/arch/x86/kernel/syscall_table_32.S (utk versi 2.6.26)
Lokasi fungsi “pelayan” bagi setiap syscall dapat bervariasi berdasarkan versi Kernelnya.NB: Googling keyword “System Call Quick Reference”
![Page 13: IKO31204 Pemrograman Sistem Jilid 8: System Call fileIKO31204 Pemrograman Sistem Jilid 8: System Call Fakultas Ilmu Komputer Universitas Indonesia Sep 2012](https://reader030.vdocuments.us/reader030/viewer/2022041206/5d5d4ab188c9932a5b8b4594/html5/thumbnails/13.jpg)
Cara membuat Syscall
1. Pilih dan berikan ID unik dan meletakkan alamat syscall baru pada table struktur data Syscall 2. Mendeklarasikan nama fungsi, struktur argumen input dan return type untuk syscall baru3. Implementasi fungsi yang akan melayani syscall tersebu
![Page 14: IKO31204 Pemrograman Sistem Jilid 8: System Call fileIKO31204 Pemrograman Sistem Jilid 8: System Call Fakultas Ilmu Komputer Universitas Indonesia Sep 2012](https://reader030.vdocuments.us/reader030/viewer/2022041206/5d5d4ab188c9932a5b8b4594/html5/thumbnails/14.jpg)
Contoh membuat Syscallhello_world
![Page 15: IKO31204 Pemrograman Sistem Jilid 8: System Call fileIKO31204 Pemrograman Sistem Jilid 8: System Call Fakultas Ilmu Komputer Universitas Indonesia Sep 2012](https://reader030.vdocuments.us/reader030/viewer/2022041206/5d5d4ab188c9932a5b8b4594/html5/thumbnails/15.jpg)
1. ID unik & nama syscall baru (I)# vi arch/x86/kernel/syscall_table_32.S
ENTRY(sys_call_table) .long sys_restart_syscall /* 0 old "setup()" system call, used for restarting */ .long sys_exit….....…..... .long sys_timerfd_settime /* 325 */ .long sys_timerfd_gettime
Baris terakhir adalah 326, maka ID unik yang bisa digunakan adalah 327. Dengan demikian isi file syscall_table_32.S menjadi:
ENTRY(sys_call_table) .long sys_restart_syscall /* 0 old "setup()" system call, used for restarting */ .long sys_exit….....…..... .long sys_timerfd_settime /* 325 */ .long sys_timerfd_gettime .long sys_hello_world
![Page 16: IKO31204 Pemrograman Sistem Jilid 8: System Call fileIKO31204 Pemrograman Sistem Jilid 8: System Call Fakultas Ilmu Komputer Universitas Indonesia Sep 2012](https://reader030.vdocuments.us/reader030/viewer/2022041206/5d5d4ab188c9932a5b8b4594/html5/thumbnails/16.jpg)
1. ID unik & nama syscall baru (II)# vi include/asmx86/unistd_32.h
#ifndef _ASM_I386_UNISTD_H_#define _ASM_I386_UNISTD_H_
#define __NR_restart_syscall 0#define __NR_exit 1….....#define __NR_timerfd_settime 325#define __NR_timerfd_gettime 326
Kita tambahkan definisi Syscall terbaru dibawah Syscall nomor 326. Dengan demikian isi file unistd_32.h menjadi:
#ifndef _ASM_I386_UNISTD_H_#define _ASM_I386_UNISTD_H_
#define __NR_restart_syscall 0#define __NR_exit 1….....#define __NR_timerfd_settime 325#define __NR_timerfd_gettime 326#define __NR_hello_world 327
![Page 17: IKO31204 Pemrograman Sistem Jilid 8: System Call fileIKO31204 Pemrograman Sistem Jilid 8: System Call Fakultas Ilmu Komputer Universitas Indonesia Sep 2012](https://reader030.vdocuments.us/reader030/viewer/2022041206/5d5d4ab188c9932a5b8b4594/html5/thumbnails/17.jpg)
2. Deklarasikan fungsi# vi include/linux/syscalls.h
…........…........int kernel_execve(const char *filename, char *const argv[], char *const envp[]);
#endif
Kita tambahkan definisi Syscall hello_world di atas fungsi kernel_execve. Dengan demikian isi file syscalls.h menjadi:
…........…........asmlinkage long sys_hello_world(void);int kernel_execve(const char *filename, char *const argv[], char *const envp[]);
#endif
![Page 18: IKO31204 Pemrograman Sistem Jilid 8: System Call fileIKO31204 Pemrograman Sistem Jilid 8: System Call Fakultas Ilmu Komputer Universitas Indonesia Sep 2012](https://reader030.vdocuments.us/reader030/viewer/2022041206/5d5d4ab188c9932a5b8b4594/html5/thumbnails/18.jpg)
3. Implemetasikan fungsi (I)Fungsi dapat diletakkan di mana saja pada source code kernel. Cth: diletakkan pada <source code kernel>/hello/# cd /usr/src/linux2.6.26# mkdir hello# cd hello# vi hello_world.c
/** * hello_world.c The hello world system call, the best system call ever. **/#include <linux/syscalls.h>
asmlinkage long sys_hello_world(){ printk("Hello World!\n"); return 0;}
# vi Makefile
objy := hello_world.o
![Page 19: IKO31204 Pemrograman Sistem Jilid 8: System Call fileIKO31204 Pemrograman Sistem Jilid 8: System Call Fakultas Ilmu Komputer Universitas Indonesia Sep 2012](https://reader030.vdocuments.us/reader030/viewer/2022041206/5d5d4ab188c9932a5b8b4594/html5/thumbnails/19.jpg)
3. Implemetasikan fungsi (II)Jangan lupa untuk memasukkan direktori hello ke dalam script otomatisasi kompilasi kernel, yaitu dalam Makefile utama kernel# cd /usr/src/linux2.6.26# vi Makefile
corey += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
Tambahkan direktori hello/ ke dalam script kompilasi Core kernel, menjadi:
corey += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ hello/
![Page 20: IKO31204 Pemrograman Sistem Jilid 8: System Call fileIKO31204 Pemrograman Sistem Jilid 8: System Call Fakultas Ilmu Komputer Universitas Indonesia Sep 2012](https://reader030.vdocuments.us/reader030/viewer/2022041206/5d5d4ab188c9932a5b8b4594/html5/thumbnails/20.jpg)
Lakukan kompilasi seperti pada Modul B1
![Page 21: IKO31204 Pemrograman Sistem Jilid 8: System Call fileIKO31204 Pemrograman Sistem Jilid 8: System Call Fakultas Ilmu Komputer Universitas Indonesia Sep 2012](https://reader030.vdocuments.us/reader030/viewer/2022041206/5d5d4ab188c9932a5b8b4594/html5/thumbnails/21.jpg)
Pemanggilan langsung dgn Syscall Number 327
#include <unistd.h>#include <sys/syscall.h>#include <errno.h>#include <stdio.h>
int main() { int rc; rc = syscall(327);}
![Page 22: IKO31204 Pemrograman Sistem Jilid 8: System Call fileIKO31204 Pemrograman Sistem Jilid 8: System Call Fakultas Ilmu Komputer Universitas Indonesia Sep 2012](https://reader030.vdocuments.us/reader030/viewer/2022041206/5d5d4ab188c9932a5b8b4594/html5/thumbnails/22.jpg)
tanya jawab