"Original" Linux adds system calls

Source: Internet
Author: User

First move the kernel file to/usr/src/and unzip it.

Process Reference http://www.cnblogs.com/kavs/p/4607371.html

And then.. Start adding system calls:

sudo gedit/usr/src/linux-4.0.6/kernel/sys.c

Insert header file #include <linux/linkage.h>

   1:
   2:
   3:* /
   4:int sys_leemohello (char
   5: printk (Kern_emerg"===this is Leemo's work ====="
   6: printk (Kern_emerg"==2012221107110095 Leemo"
   7:return
   8: }

sudo gedit/usr/src/linux-4.0.6/arch/x86/syscalls/syscall_32.tbl

Remember to increase the system number as above 359

sudo gedit/usr/src/linux-4.0.6/arch/x86/include/asm/syscalls.h

Compile kernel .... Process Reference http://www.cnblogs.com/kavs/p/4607371.html

Restart after compilation is complete.

Writing test Code

1, first build a folder mkdir Leemotest

2. Create the test code sudo gedit testleemohello.c type the code:

   1: #include <stdio.h>
   2:int main ()
   3: {
   4:int rs;
   5:Char * buf="Leemo";
   6: rs=syscall (359,BUF);
   7: printf ("%d%s \ n", rs,buf);
   8:if(rs==1) {
   9: printf ("system call is success!\n");
  Ten: }
One   :Else
  : printf ("sorry,failed!\n");
  :return 0;
  : }

To compile the test code:

GCC Testleemohello.c-o Testleemohello

To run the test code:

./testleemohello

Results:

then enter DMESG

The call is complete.

"Original" Linux adds system calls

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.