This commit is contained in:
gferg 2007-02-01 16:51:02 +00:00
parent 74e4da2812
commit f443569a04
3 changed files with 81 additions and 106 deletions

View File

@ -1697,6 +1697,17 @@ Describes the installation of GNU/Linux on the IBM RS/6000 43P
model 7248 series. </Para>
</ListItem>
<ListItem>
<Para>
<ULINK URL="../Implement-Sys-Call-Linux-2.6-i386/index.html">
Implement-Sys-Call-Linux-2.6-i386</ULink>,
<CiteTitle>Implementing a System Call on Linux 2.6 for i386</CiteTitle>
</Para><Para>
<CiteTitle>Updated: Oct 2006</CiteTitle>.
Information about implementing system calls in the Linux
operating system for i386 architecture with 2.6 kernels. </Para>
</ListItem>
<ListItem>
<Para>
<ULINK URL="../Indic-Fonts-HOWTO/index.html">

View File

@ -293,6 +293,17 @@ Details download and installation instructions for a graphics
rendering and modelling development environment using RedHat Linux. </Para>
</ListItem>
<ListItem>
<Para>
<ULINK URL="../Implement-Sys-Call-Linux-2.6-i386/index.html">
Implement-Sys-Call-Linux-2.6-i386</ULink>,
<CiteTitle>Implementing a System Call on Linux 2.6 for i386</CiteTitle>
</Para><Para>
<CiteTitle>Updated: Oct 2006</CiteTitle>.
Information about implementing system calls in the Linux
operating system for i386 architecture with 2.6 kernels. </Para>
</ListItem>
<ListItem>
<Para>
<ULINK URL="../IO-Port-Programming.html">

View File

@ -1,97 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
<article lang="en-US"><sect1><title>Implementing a System Call on Linux 2.6 for i386</title>
<para>Amit Choudhary</para>
<para>http://amit-choudhary.blogspot.com</para>
<para>amit2030 AT gmail DOT com</para>
<para/>
<para>Version 1.0, 27 October 2006</para>
<para/>
<para>This HOWTO describes information about implementing system calls in Linux operating system for i386 architecture with 2.6 kernels. General information about the used and modified files is available as well as description of the source and makefiles and test user space C program too.</para></sect1><sect1><title>Table of contents</title>
<orderedlist>
<listitem>
<para>Introduction</para>
</listitem>
<listitem>
<para>System call</para>
</listitem>
<listitem>
<para>List of files to be modified/created</para>
</listitem>
<listitem>
<para>Kernel files to be modified</para>
</listitem>
</orderedlist>
<orderedlist>
<listitem>
<orderedlist>
<listitem>
<para>syscall_table.S</para>
</listitem>
<listitem>
<para>unistd.h</para>
</listitem>
<listitem>
<para>syscalls.h</para>
</listitem>
<listitem>
<para>Makefile</para>
</listitem>
</orderedlist>
</listitem>
<listitem>
<para>New kernel files/directories to be created</para>
</listitem>
</orderedlist>
<orderedlist>
<listitem>
<orderedlist>
<listitem>
<para>mycall</para>
</listitem>
<listitem>
<para>mycall.c</para>
</listitem>
<listitem>
<para>Makefile</para>
</listitem>
</orderedlist>
</listitem>
<listitem>
<para>New user space files, to be created, to test our system call</para>
</listitem>
</orderedlist>
<orderedlist>
<listitem>
<orderedlist>
<listitem>
<para>testmycall.h</para>
</listitem>
<listitem>
<para>testmycall.c</para>
</listitem>
</orderedlist>
</listitem>
<listitem>
<para>_syscallN macro</para>
</listitem>
<listitem>
<para>Testing our new system call</para>
</listitem>
<listitem>
<para>Questions And Suggestions</para>
</listitem>
<listitem>
<para>Copyright</para>
</listitem>
<listitem>
<para>License</para>
</listitem>
</orderedlist></sect1><sect1><title>1. Introduction</title>
<para>This document explains how to implement a new system call on linux 2.6. A system call is used by application (user) programs to request service from the operating system.</para></sect1><sect1><title>2. System call</title>
<?xml version='1.0' encoding='ISO-8859-1' ?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [
]>
<article lang="en">
<articleinfo>
<title>Implementing a System Call on Linux 2.6 for i386</title>
<author>
<firstname>Amit</firstname>
<surname>Choudhary</surname>
<affiliation>
<address><email>amit2030 AT gmail DOT com</email></address>
</affiliation>
</author>
<!-- All dates specified in ISO "YYYY-MM-DD" format -->
<pubdate>2006-10-27</pubdate>
<!-- Most recent revision goes at the top; list in descending order -->
<revhistory>
<revision>
<revnumber>1.0</revnumber>
<date>2006-10-27</date>
<authorinitials>ac</authorinitials>
<revremark>official release</revremark>
</revision>
</revhistory>
<!-- Provide a good abstract; a couple of sentences is sufficient -->
<abstract>
<para>
This HOWTO describes information about implementing system calls in
the Linux operating system for i386 architecture with 2.6 kernels.
General information about the used and modified files is available
as well as description of the source and makefiles and test user
space C program too.
</para>
</abstract>
</articleinfo>
<sect1><title>Introduction</title>
<para>This document explains how to implement a new system call on linux 2.6. A system call is used by application (user) programs to request service from the operating system.</para></sect1><sect1><title>System call</title>
<para>A system call is used by application (user) programs to request service from the operating system. The following statements illustrate why system calls are needed. An operating system can access a system's hardware directly, but a user program is not given direct access to the hardware. This is done so that the kernel can keep the system safe and secure from malicious user programs. But often, a user program requires some information from the hardware (e.g., from a web camera to show you the picture), but it cannot get the information directly. So, it requests the operating system to supply it the information. This request is made by using an appropriate system call.</para>
<para/>
<para>A system call executes in the kernel mode. Every system call has a number associated with it. This number is passed to the kernel and that's how the kernel knows which system call was made. When a user program issues a system call, it is actually calling a library routine. The library routine issues a trap to the Linux operating system by executing INT 0x80 assembly instruction. It also passes the system call number to the kernel using the EAX register. The arguments of the system call are also passed to the kernel using other registers (EBX, ECX, etc.). The kernel executes the system call and returns the result to the user program using a register. If the system call needs to supply the user program with large amounts of data, it will use another mechanism (e.g., copy_to_user call).</para></sect1><sect1><title>3. List of files to be modified/created</title>
<para>A system call executes in the kernel mode. Every system call has a number associated with it. This number is passed to the kernel and that's how the kernel knows which system call was made. When a user program issues a system call, it is actually calling a library routine. The library routine issues a trap to the Linux operating system by executing INT 0x80 assembly instruction. It also passes the system call number to the kernel using the EAX register. The arguments of the system call are also passed to the kernel using other registers (EBX, ECX, etc.). The kernel executes the system call and returns the result to the user program using a register. If the system call needs to supply the user program with large amounts of data, it will use another mechanism (e.g., copy_to_user call).</para></sect1><sect1><title>List of files to be modified/created</title>
<para>Assume that your linux source base directory is /usr/src/linux.</para>
<para/>
<para>Kernel files to be modified are listed below:</para>
@ -110,7 +63,7 @@
<para>New user space files, to be created, to test our system call are listed below:</para>
<para/>
<para>1. testmycall.c Source file that will call our system call.</para>
<para>2. testmycall.h - Header file.</para></sect1><sect1><title>4. Kernel files to be modified</title></sect1><sect1><title>4.1 syscall_table.S</title>
<para>2. testmycall.h - Header file.</para></sect1><sect1><title>Kernel files to be modified</title></sect1><sect1><title>syscall_table.S</title>
<para>Full path of the file - /usr/src/linux/arch/i386/kernel/syscall_table.S</para>
<para>This file contains system call names.</para>
<orderedlist>
@ -120,7 +73,7 @@
<listitem>
<para>Add ".long sys_mycall" at the end of the list.</para>
</listitem>
</orderedlist></sect1><sect1><title>4.2 unistd.h</title>
</orderedlist></sect1><sect1><title>unistd.h</title>
<para>Full path of the file - /usr/src/linux/include/asm-i386/unistd.h</para>
<para>This file contains the system call number that is passed to the kernel through the register (EAX) when a system call is invoked. </para>
<orderedlist>
@ -137,7 +90,7 @@
</listitem>
</orderedlist>
<para>"#define NR_syscalls 317", then change it to:</para>
<para>"#define NR_syscalls 318"</para></sect1><sect1><title>4.3 syscalls.h</title>
<para>"#define NR_syscalls 318"</para></sect1><sect1><title>syscalls.h</title>
<para>Full path of the file - /usr/src/linux/include/linux/syscalls.h</para>
<para>This file contain the declarations for system calls.</para>
<orderedlist>
@ -145,21 +98,21 @@
<para>Add the following line at the end of the file:</para>
</listitem>
</orderedlist>
<para>"asmlinkage long sys_mycall(int i);"</para></sect1><sect1><title>4.4 Makefile</title>
<para>"asmlinkage long sys_mycall(int i);"</para></sect1><sect1><title>Makefile</title>
<para>Full path of the file - /usr/src/linux/Makefile</para>
<para/>
<orderedlist>
<listitem>
<para>Add mycall/ to core-y (Search for regex: core-y.*+=). You will be creating this directory. This directory will contain the source file, header file and the Makefile for our system call.</para>
</listitem>
</orderedlist></sect1><sect1><title>5. New kernel files/directories to be created</title></sect1><sect1><title>5.1 mycall</title>
</orderedlist></sect1><sect1><title>New kernel files/directories to be created</title></sect1><sect1><title>mycall</title>
<para>Full path of the file - /usr/src/linux/mycall</para>
<para/>
<orderedlist>
<listitem>
<para>Create a new directory in /usr/src/linux and name it "mycall".</para>
</listitem>
</orderedlist></sect1><sect1><title>5.2 mycall.c</title>
</orderedlist></sect1><sect1><title>mycall.c</title>
<para>Full path of the file - /usr/src/linux/mycall/mycall.c</para>
<para/>
<orderedlist>
@ -178,13 +131,13 @@
<para>/*---End of mycall.c------*/</para>
<para/>
<para>What is asmlinkage?</para>
<para>Asmlinkage is used to look for the arguments on the kernel stack.</para></sect1><sect1><title>5.3 Makefile</title>
<para>Asmlinkage is used to look for the arguments on the kernel stack.</para></sect1><sect1><title>Makefile</title>
<para>Full path of the file - /usr/src/linux/mycall/Makefile</para>
<para>The Makefile in dir "mycall" will have only one line:</para>
<para/>
<para>#####Makefile Start#####</para>
<para>obj-y := mycall.o</para>
<para>#####Makefile End#######</para></sect1><sect1><title>6. New user space files, to be created, to test our system call</title></sect1><sect1><title>6.1 testmycall.h (new user space header file to be created)</title>
<para>#####Makefile End#######</para></sect1><sect1><title>New user space files, to be created, to test our system call</title></sect1><sect1><title>testmycall.h (new user space header file to be created)</title>
<para>testmycall.h</para>
<para/>
<orderedlist>
@ -220,7 +173,7 @@
<para>#include&lt;linux/unistd.h&gt;</para>
<para>#define __NR_mycall 317</para>
<para>_syscall1(long, mycall, int, i)</para>
<para>/*---End of header file--------*/</para></sect1><sect1><title>6.2 testmycall.c (new user space source file to be created)</title>
<para>/*---End of header file--------*/</para></sect1><sect1><title>testmycall.c (new user space source file to be created)</title>
<para>testmycall.c</para>
<para/>
<orderedlist>
@ -237,7 +190,7 @@
<para>{</para>
<para>printf("%d\n", mycall(15));</para>
<para>}</para>
<para>/*---End of C file------*/</para></sect1><sect1><title>7. _syscallN macro</title>
<para>/*---End of C file------*/</para></sect1><sect1><title>_syscallN macro</title>
<orderedlist>
<listitem>
<para>_syscall0(int,mycall) indicates that:</para>
@ -277,7 +230,7 @@
<para>return syscall(__NR_mycall, i);</para>
<para>}</para>
<para/>
<para>But the definition of _syscallN macros are different in the kernel. You can look at /usr/src/linux/include/asm-i386/unistd.h for the definition.</para></sect1><sect1><title>8. Testing our new system call</title>
<para>But the definition of _syscallN macros are different in the kernel. You can look at /usr/src/linux/include/asm-i386/unistd.h for the definition.</para></sect1><sect1><title>Testing our new system call</title>
<orderedlist>
<listitem>
<para>Step 1: Recompile and install the new kernel so that our system call becomes available to the operating system.</para>
@ -288,20 +241,20 @@
<listitem>
<para>RESULT: You should see the output as 25. This has been tested on kernel 2.6.17.13.</para>
</listitem>
</orderedlist></sect1><sect1><title>9. Questions And Suggestions</title>
</orderedlist></sect1><sect1><title>Questions And Suggestions</title>
<orderedlist>
<listitem>
<para>Please send a mail to Amit Choudhary (amit2030 AT gmail DOT com).</para>
</listitem>
</orderedlist>
<para/></sect1><sect1><title>10. Copyright.</title>
<para/></sect1><sect1><title>Copyright</title>
<para>Copyright (c) 2006 by Amit Choudhary.</para>
<para>Permission is granted to copy, distribute and/or modify this document</para>
<para>under the terms of the GNU Free Documentation License, Version 1.2</para>
<para>or any later version published by the Free Software Foundation;</para>
<para>with no Invariant Sections, no Front-Cover Texts, and no Back-Cover</para>
<para>Texts. A copy of the license is included in the section entitled "GNU</para>
<para>Free Documentation License".</para></sect1><sect1><title>11. License</title>
<para>Free Documentation License".</para></sect1><sect1><title>License</title>
<para>GNU Free Documentation License</para>
<para>Version 1.2, November 2002</para>
<para/>