This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
modifying_the_linux_kernel [2020/09/07 14:22] misterjei [Adding a System Call] |
modifying_the_linux_kernel [2021/09/17 11:36] (current) misterjei [Adding a System Call] |
||
|---|---|---|---|
| Line 4: | Line 4: | ||
| ==== Adding a System Call ==== | ==== Adding a System Call ==== | ||
| There are three major steps to adding a system call to the Linux kernel: | There are three major steps to adding a system call to the Linux kernel: | ||
| - | -Adding a new entry to the system call table for the appropriate architecture | + | -Entry to the system call table for the appropriate architecture |
| - | -Marking the function | + | -Prototype of system call & marking |
| - | -Adding the system call functions themselves | + | -Definition of system call (implementation) |
| - | === Adding an Entry to the System Call Table === | + | === 1. Entry in System Call Table === |
| Every system call must have an associated system call number which corresponds to its position in the system call table. This table is transformed / imported into the source as part of the build process. The correct table varies by architecture, | Every system call must have an associated system call number which corresponds to its position in the system call table. This table is transformed / imported into the source as part of the build process. The correct table varies by architecture, | ||
| - | / | + | '' |
| - | For example, in the x64 version of Linux, < | + | For example, in the x64 version of Linux, |
| The table has four columns: | The table has four columns: | ||
| - | < | + | **//< |
| * When the syscall machine instruction executes, it loads a unique **call number** to identify the function. | * When the syscall machine instruction executes, it loads a unique **call number** to identify the function. | ||
| Line 23: | Line 23: | ||
| * Finally, the **entry point** is the assembly signature for the call (which uses the arch-specific prefix). | * Finally, the **entry point** is the assembly signature for the call (which uses the arch-specific prefix). | ||
| - | This example uses the " | + | This example uses the " |
| - | 435 common sample_syscall __x64_sys_sample_syscall | + | < |
| + | === 2. Prototype of the System Call === | ||
| + | The kernel has no " | ||
| + | |||
| + | < | ||
| + | |||
| + | === 3. Definition of the System Call === | ||
| + | Finally, we need to add the system call definition. Thise will need to be compiled into the kernel as well. The kernel has lots of examples along these lines, which is for a system call with one parameter ('' | ||
| + | |||
| + | < | ||
| + | { | ||
| + | return sample_param + 1; // Adds 1 to the parameter and returns it | ||
| + | }</ | ||
| + | |||
| + | The '' | ||