How to Add Your Own System Calls

  1. Create a directory under the /usr/src/linux/ directory to hold your code.
  2. Put any include files in /usr/include/sys/ and /usr/include/linux/.
  3. Add the relocatable module produced by the link of your new kernel code to the <#1832#> ARCHIVES<#1832#> and the subdirectory to the <#1833#> SUBDIRS<#1833#> lines of the top level Makefile. See fs/Makefile, target fs.o for an example.
  4. Add a <#1851#> #define __NR_<#1834#> xx<#1834#><#1851#> to unistd.h to assign a call number for your system call, where <#1835#> xx<#1835#>, the index, is something descriptive relating to your system call. It will be used to set up the vector through <#1836#> sys_call_table<#1836#> to invoke you code.
  5. Add an entry point for your system call to the <#1837#> sys_call_table<#1837#> in sys.h. It should match the index (<#1838#> xx<#1838#>) that you assigned in the previous step. The <#1839#> NR_syscalls<#1839#> variable will be recalculated automatically.
  6. Modify any kernel code in kernel/fs/mm/, etc.\ to take into account the environment needed to support your new code.
  7. Run make from the top level to produce the new kernel incorporating your new code.
At this point, you will have to either add a syscall to your libraries, or use the proper <#1852#> _syscall<#1841#> n<#1841#>()<#1852#> macro in your user program for your programs to access the new system call. The <#1842#> 386DX Microprocessor Programmer's Reference Manual<#1842#> is a helpful reference, as is James Turley's <#1843#> Advanced 80386 Programming Techniques.<#1843#> See the Annotated bibliography in Appendix~#bibliography#1844>. %