问题
We just got a midterm project today for my "operating systems" course, we are requested to implement a system call (and I guess I assume we'll have to write a piece of code to call it).
I understand I'll need to update the table of the system calls (can't remember the name, but no biggie), as well as create a kernel module that the table will point to, but does this mean I'll have to recompile the whole kernel, so the kernel knows about my module?
I have seen that it's possible to hijack a current system call, but I suspect that I won't get credit for my assignment if I do it that way.
Just wanted to get a feel for the size of the effort I'll be making.
UPDATE: Well it kinda ended up being a hassle, they change some things from I believe 2.6.32 forward, so when I went back to a previous kernel version specific to the tutorials online I found, it was really easy to follow. If anyone catches this online and are following a tutorial, initially I would recommend downloading the same kernel in the tutorial initially, then move forward from there once you have an understanding of what you're doing. If you're really familiar with compiling kernels, etc, you might not have an issue, but this was my first time compiling a kernel, so it was a pain to compile for 2 hours and then find out something didn't work, and have to do it all over again, especially when I wasn't sure what I was/wasn't doing wrong.
回答1:
but does this mean I'll have to recompile the whole kernel, so the kernel knows about my module?
Yes, you will need to recompile the kernel.
- Implementing Linux System Calls
回答2:
You want to read:
- Linux Kernel Programming, Third Edition (Paperback) by Michael Beck (Author), Harald Bohme (Author), Mirko Dziadzka (Author), Ulrich Kunitz (Author), Robert Magnus (Author), Dirk Verworner (Author), Claus Schroter (Author), published by Addison-Wesley (Pearson Education), ISBN-10: 0201719754 , ISBN-13: 978-0201719758
and possibly as well for more details:
- Understanding the Linux Kernel, Third Edition By Daniel P. Bovet, Marco Cesati, published by O’Reilly, ISBN 10: 0-596-00565-2, ISBN 13: 9780596005658
- Linux Device Drivers, Third Edition By Jonathan Corbet, Alessandro Rubini, Greg Kroah-Hartman, published by O’Reilly, ISBN 10: 0-596-00590-3, ISBN 13: 9780596005900
回答3:
I understand I'll need to update the table of the system calls
It's /usr/src/linux/arch/i386/kernel/syscall_table.S
does this mean I'll have to recompile the whole kernel, so the kernel knows about my module?
Yes, indeed.
Just wanted to get a feel for the size of the effort I'll be making.
If you know what code you are going to write as a part of the system call, you're already done. You only have to wait out the kernel recompilation time. Here's a set of instructions:
Implementing a System Call in Linux
来源:https://stackoverflow.com/questions/3884172/creating-a-system-call-in-linux