<div dir="ltr">Hi Iker Pedrosa,<div><br></div><div>In old versions of Linux kernels like 2.6.xx, the approach was different from Linux version 3.3 on wards. <br></div><div><br></div><div>There are two different approaches to implement own system call. Each approach involves several steps. The difference between two approaches is, in one approach, we implement our system call in already existing file of kernel sources. In another approach, we created our own directory in kernel source which contains our system call implementation files. Ans in this second approach, we need to modify the Kernel Makefiles and Configuration files to include our newly created directory and its contents. First let us implement using the first approach.<br>
</div><div><br></div><div>The following approach was successfully tested in Linux kernel 3.5.7 version sources for x86 32-bit architecture.<br></div><div><br></div><div>Here are the steps to create our own system call in the existing kernel sources. The paths given below are relative paths from /usr/src/linux.</div>
<div><br></div><div>1. Generally, add the function (system call) definition in kernel/sys.c file.</div><div><br></div><div>/* this is the implementation of our system call */<br></div><div><div>asmlinkage long sys_helloworld(void) {</div>
<div>       printk(KERN_EMERG &quot;Hello, world!\n&quot;);</div><div>return 0;</div><div>}</div></div><div><br></div><div>2. Add the function prototype in the header file include/linux/syscalls.h</div><div><br></div><div>
asmlinkage long sys_helloworld(void);<br></div><div><br></div><div>3. Create an entry in system call table in the file arch/x86/syscalls/syscall_32.tbl</div><div><br></div><div>350     i386    helloworld             sys_helloworld<br>
</div><div><br></div><div>Note: In my case already table had 349 offsets, so I added it as 350.</div><div><br></div><div>4. If we want to create our own kernel images, then change the EXTRAVERSION in the main Makefile available at /usr/src/linux</div>
<div><br></div><div>EXTRAVERSION = .ownsyscall</div><div><br></div><div>5. Then, build the modules from the main directory with the following.</div><div><br></div><div>make menuconfig  --- Just save and exit.</div><div>make modules</div>
<div>make modules_install</div><div>make install</div><div><br></div><div>6. Now, reboot with our own image.</div><div><br></div><div>7. Write a simple C application for calling the our own system call.</div><div><br></div>
<div><div>#include &lt;stdio.h&gt;</div><div><br></div><div>/* sys_helloworld 350 */</div><div>int main ()</div><div>{</div><div><span class="" style="white-space:pre">        </span>syscall(350); /* 350 is our system calls offset number */</div>
<div><span class="" style="white-space:pre">        </span>return 0;</div><div>}</div><div><br></div></div><div>I hope, you understand it clearly and it helps you. Based on this, you can practice the second approach. It needs of creating our own directory and files (C, Makefile, Kconfig) and modifications required in architecture specific Kconfig.</div>
<div><br></div><div>Regards,</div><div>Srinivas.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jul 18, 2013 at 2:34 PM, Iker Pedrosa <span dir="ltr">&lt;<a href="mailto:ikerpedrosam@gmail.com" target="_blank">ikerpedrosam@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Guys,<br>
<br>
I am a newbie to linux kernel and I am trying to do some of the exercises/examples of the Linux Kernel Development book by Robert Love. For the moment I&#39;m trying to create a system call (Chapter 5) but I am unable to do the first step which states the following:<br>

&quot;Add an entry to the end of the system call table.This needs to be done for each architecture that supports the system call (which, for most calls, is all the architectures).The position of the syscall in the table, starting at zero, is its system call number. For example, the tenth entry in the list is assigned syscall number nine.&quot;<br>

<br>
My problem is that I am unable to find the file that holds the table. In the book the file that needs to be changed is the entry.S but it no longers exists in v3.9. In an example that I have found on the internet, which is done using v3.0, the file to change is syscall_table_32.S. But I&#39;ve got the same problem, it doesn&#39;t exist. So anybody can help me to find the table? I know that I should be using v2.6 of the kernel but I don&#39;t know if that version will work with the distribution that I&#39;m using.<br>

<br>
The question is also in stackoverflow so if someone wants to answer there I won&#39;t have any problem. The link to the page is the following: <a href="http://stackoverflow.com/questions/17652555/where-is-the-system-call-table-in-linux-kernel-v3-9" target="_blank">http://stackoverflow.com/questions/17652555/where-is-the-system-call-table-in-linux-kernel-v3-9</a><br>

<span class="HOEnZb"><font color="#888888"><br>
--<br>
Iker Pedrosa &lt;<a href="mailto:ikerpedrosam@gmail.com">ikerpedrosam@gmail.com</a>&gt;<br>
<br>
_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
</font></span></blockquote></div><br></div>