Add a new system call to the kernel
Using the appropriate SYSCALL_DEFINE* macro, define a function that behaves as follows:
a) The function takes two arguments, a userspace pointer to a buffer of type char *
, an integer specifying the size of the buffer of type size_t
.
c) The function returns the length of the string copied upon sucess. If there is an issue with the size of the provided buffer, checked by proxy of the `size_t` argument, then the function returns `-EFAULT` to the user.
d) The function should take care to prevent any possibility of a buffer overflow.
Add an asmlinkage
declaration of your syscall in include/linux/syscalls.h
. There are numerous examples of other syscalls in that file for ample student inspiration.
Add an entry to the syscall table for your architecture. On x86_64, this is arch/x86/entry/syscalls/syscall_64.tbl
and on aarch64 this is include/uapi/asm-generic/unistd.h
. Take inspiration from the other syscalls.
Write an assembly language program that invokes your syscall and prints the string that is placed in the buffer by the kernel to standard output using the write syscall.
Write a C program that does exactly the same thing as the previous step.
Compile and reboot into the newly modified kernel. Make sure your C and assembly language programs work correctly. Include the output in your cover letter.
The following pages will be of interest to a student:
Conventions:
Assembly files that must be pre-processed use the extension *.S
Assembly files that are ready to be assembled use the extension *.s
Refer to the Linux kernel documentation for further guidance.
-Wall
but ideally -Wextra
and -Wpedantic
too, or even -Weverything
if you use clang) and that your code doesn’t have any warnings or errors.--base=HEAD^
on git format patch so we can tell what commit your work was based on), and then take this file, put it in your named directory, and add the email patch itself to the staged git files and commit this. Then, generate a patch from this commit. This is the second patch of the assignment.