Cara nak tambah syscall sendiri ke dalam linux kernel. Melibatkan recompile kernel
////////////////////////////////////////////////////////////////////////////////////
// 1) source_path/arch/x86/syscalls/syscall_32.tbl
# The format is:
#
356 i386 memfd_create sys_memfd_create
357 i386 mhsyscall sys_mhsyscall ( new line)
////////////////////////////////////////////////////////////////////////////////////
// 2) source_path/include/linux/syscalls.h
// last line
asmlinkage long sys_opsyscall(const char *test);
#endif
////////////////////////////////////////////////////////////////////////////////////
// 3) source_path/mhsyscall/mhfzsyscall.c ( nama c file suka hati)
#include
#include
//The system call
asmlinkage long sys_mhsyscall(const char *test)
{
printk(KERN_ALERT "Called with string: %s\n", test);
// 0 for success
return 0;
}
////////////////////////////////////////////////////////////////////
// 4) source_path/mhsyscall/Makefile
// Include the object in the kernel core
obj-y := mhfzsyscall.o
/////////////////////////////////////////////////////////////////////////
// 5) source_path/Makefile
# Objects we will link into vmlinux / subdirs we need to visit
init-y := init/
drivers-y := drivers/ sound/ firmware/
net-y := net/
libs-y := lib/
core-y := usr/ mhsyscall/ ( edit line )
//////////////////////////////////////////////////////////////
// 6) compile
# make
///////////////////////////////////////////////////////
// 7) userspace binary to call mhsyscall (pemanggil.c)
#include
int main(){
syscall(357, "Mesage from user space program");
return 0;
}
// gcc -o pemanggil pemanggil.c
ref https://www.youtube.com/watch?v=5rr_VoQCOgE&feature=youtu.be
////////////////////////////////////////////////////////////////////////////////////
// 1) source_path/arch/x86/syscalls/syscall_32.tbl
# The format is:
#
356 i386 memfd_create sys_memfd_create
357 i386 mhsyscall sys_mhsyscall ( new line)
////////////////////////////////////////////////////////////////////////////////////
// 2) source_path/include/linux/syscalls.h
// last line
asmlinkage long sys_opsyscall(const char *test);
#endif
////////////////////////////////////////////////////////////////////////////////////
// 3) source_path/mhsyscall/mhfzsyscall.c ( nama c file suka hati)
#include
#include
//The system call
asmlinkage long sys_mhsyscall(const char *test)
{
printk(KERN_ALERT "Called with string: %s\n", test);
// 0 for success
return 0;
}
////////////////////////////////////////////////////////////////////
// 4) source_path/mhsyscall/Makefile
// Include the object in the kernel core
obj-y := mhfzsyscall.o
/////////////////////////////////////////////////////////////////////////
// 5) source_path/Makefile
# Objects we will link into vmlinux / subdirs we need to visit
init-y := init/
drivers-y := drivers/ sound/ firmware/
net-y := net/
libs-y := lib/
core-y := usr/ mhsyscall/ ( edit line )
//////////////////////////////////////////////////////////////
// 6) compile
# make
///////////////////////////////////////////////////////
// 7) userspace binary to call mhsyscall (pemanggil.c)
#include
int main(){
syscall(357, "Mesage from user space program");
return 0;
}
// gcc -o pemanggil pemanggil.c
ref https://www.youtube.com/watch?v=5rr_VoQCOgE&feature=youtu.be
No comments:
Post a Comment
Terima kasih