Creating a System Call in Linux

2019-03-11 17:54发布

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.

3条回答
兄弟一词,经得起流年.
2楼-- · 2019-03-11 18:16

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

查看更多
等我变得足够好
3楼-- · 2019-03-11 18:28

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
查看更多
\"骚年 ilove
4楼-- · 2019-03-11 18:35

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.

查看更多
登录 后发表回答