(I previously published an article on the CUSEC website about the kernel, which is a follow-up article .) I once asked others how to start kernel programming. they basically said: ① If you don't need to know how the kernel works for you, why should you try it? ② You should order
(I previously published an article on the CUSEC website about the kernel, which is a follow-up article .)
I once asked others how to start kernel programming. they basically said: ① If you don't need to know how the kernel works for you, why should you try it? ② You should subscribe to the Linux kernel email list and try to understand it. ③ If you don't write code for the Linux kernel, you are wasting time.
None of these have helped me. So I listed some feasible methods here. They are also interesting about how the operating system and Linux kernel work in your project. Although I do not know much about it, at least I know more about it than I did before.
For the following methods, you only need to understand some C and assembly languages (at least copy and paste them ). I will write some small C programs and use assembly for class, although I forgot about it.
Method 1: compile your own operating system
This seems like a terrible method. But not actually! I started from the rustboot project and it is important that it is ready to work. Then I will do some simple things, such as changing the screen from red to blue, printing characters to the screen, and continuously getting keyboard interruptions to work.
MikeOS is another interesting start for me. Remember, your operating system does not have to be very professional-if you can make it change the screen color from red to purple or print a video, you will be successful.
You will definitely want to use a simulator to run your operating system, such as qemu. OSDev wiki is also a very useful website-there are many common problems you may encounter.
Method 2: write some kernel modules!
If you are ready to run Linux, it is quite easy to write some kernel modules, even if they do nothing.
Here is a message that can print "Hello, hacker school !" Source code of the module to the kernel log. It only has 18 lines of code. Basically, you only need to write an init process and a cleanup function. I don't know what the _ init and _ exit macro commands do, but I will use them!
It is difficult to compile a kernel module with certain functions. When I did this, I first decided to complete the function (for example, printing a piece of information for each packet passing through the Kernel), and then I went back to read some things on Kernel Newbies, use Google to search a lot, and then copy and paste a lot of code to figure out how to write it. Here are several examples of kernel modules. I put them in the kernel-module-fun project.
Method 3: participate in a Linux kernel internship!
The Linux kernel team participated in the GNOME female development internship program. It is an amazing, amazing, and enjoyable activity. This means that if you are a woman and willing to spend three months on kernel development, you will be able to participate in kernel development without any experience, you can also get some compensation ($5000 ). We have an introduction to Kernel Newbies.
If you are interested in this, it is very worth applying for-you can make a formatting patch for the kernel, which is very interesting. Sarah Sharp is a Linux kernel developer. she is coordinating this activity and she is very enthusiastic. You can read her blog article about how 137 patches are allowed to be added to the kernel in the first round. These patches will also be provided by you! View application instructions!
If you are not a girl, you can choose a similar activity like Google Summer of Code. (Editor's note: This sentence may arouse the dislike of female programmers)
Method 4: Read the kernel source code
It sounds like the worst suggestion-"It's too stupid to look at the source code if you want to know how the kernel works"
But in fact this method is very interesting. You don't need to know anything. When I encounter something I cannot understand, I feel powerless, but when I tell people, everyone will say, "Well, this is the legendary Linux kernel. you can't understand it!"
My friend Dave recently gave me a website LXR where you can read kernel resources and provide a lot of useful reference links. For example, if you want to know the system call of the chmod command, you can see its definition in the Linux kernel on the chmod_common definition page!
Here is part of the chmod_common code, which has some comments I have written:
Static int chmod_common (struct path * path, umode_t mode) {struct inode * inode = path-> dentry-> d_inode; struct iattr newattrs; int error; // do not know what this is. error = mnt_want_write (path-> mnt); if (error) return error; // mutex lock! Avoid conflicts! = D mutex_lock (& inode-> I _mutex); // I guess this is checking whether chmod error = security_path_chmod (path, mode) can be used; if (error) goto out_unlock; // I guess this is changing the mode value newattrs. ia_mode = (mode & S_IALLUGO) | (inode-> I _mode &~ IALLUGO); newattrs. ia_valid = ATTR_MODE | ATTR_CTIME; error = policy_change (path-> dentry, & newattrs); out_unlock: mutex_unlock (& inode-> I _mutex ); // remove the mutex lock mnt_drop_write (path-> mnt) when the lock is complete );//??? Return error ;}
I think this process is interesting and helps me clarify the significance of the kernel. I found that most of the code I read is difficult to understand, but some (such as chmod code) are understandable.
Summary:
- Jessica McKellar's blog post on Ksplice blog
- Linux Device Drivers describes itself in this way. I found that it is still a bit useful.
"This book will teach you how to write your own drivers and how to intrude into the kernel-related areas"
- If you are writing an operating system, OSDev wiki is a good website.
- Kernel Newbies has some resources for new Kernel developers, although I have some unpleasant experiences in its chat room.
- Sarah Sharp is a kernel developer responsible for the external services of the Linux kernel.
Translated by Julia Evans: Bole online-haofly