The Linux Kernel Hackers' Guide

The HyperNews Linux KHG Discussion Pages

# Linux Kernel Hackers' Guide

Due to the fact that nearly every post to this site recently has been either by rude cracker-wannabes asking how to break into other people's systems or a request for basic technical support, posting to the KHG has been disabled, probably permanently. For now, you can read old posts, but you cannot send replies. In any case, there are now far better resources available.

## Go get the real thing!

Alessandro Rubini wrote Linux Device Drivers, which is what the KHG could have been (maybe) but isn't. If you have a question and can't find the answer here, go get a copy of Linux Device Drivers and read it--chances are that when you are done, you will not need to ask a question here.

Run, don't walk to get a copy of this book.

## The Linux Kernel

Go read The Linux Kernel if you want an introduction to the Linux kernel that is better than the KHG. It is a great complement to Linux Device Drivers. Read it.

## Table of Contents

Tour of the Linux Kernel
  This is a somewhat incomplete tour of the Linux Kernel, based on Linux 1.0.9 and the 1.1.x development series. Most of it is still relevant.
Device Drivers
  The most common Linux kernel programming task is writing a new device driver. The great majority of the code in the kernel is new device drivers; between 1.2.13 and 2.0 the size of the source code more than doubled, and most of that was from adding device drivers.
Filesystems
  Adding a filesystem to Linux doesn't have to involve magic...
Linux Memory Management
  A few outdated documents, and one completely new one by David Miller on the Linux cache flush architecture.
How System Calls Work on Linux/i86
  Although this was written while Linux 0.99.2 was current, it still applies. A few filenames may need updating. find is your friend--just respond with the changes and they will be added.
Other Sources of Information
  The KHG is just one collection of information about the Linux kernel. There are others!

## Membership and Subscription

At the bottom of the page, you will notice two hyperlinks (among several others): Subscribe and Members. Using the KHG to its fullest involves these two hyperlinks, even though you are not required to be a member to read these pages and post responses.

### Membership

HyperNews membership is site-wide. That is, you only need to sign up and become a member once for the entire KHG. It doesn't take much to be a member. Each member is identified by a unique name, which can either be a nickname or an email address. We suggest using your email address; that way it will be unique and easy to remember. On the other hand, you may want to choose a nickname if you expect to be changing your email address at any time.

We also want your real name, email address, and home page (if you have one). You can give us your phone and address if you want. You will be asked to choose a password. You can change any of these items at any time by clicking on the Membership hyperlink again.

### Subscription

Subscribing to a page puts you on a mailing list to be sent notification of any new responses to the page to which you are subscribed. You subscribe separately to each page in which you are interested by clicking the Subscription link on the page to which you want to subscribe. You are also subscribed, by default, to pages that you write.

When you subscribe to a page, you subscribe to that page and all of its responses.

## Contributing

Please respond to these pages if you have something to add. Think of posting a response rather like posting to an email list, except that an editor might occasionally come along to clean things up and/or put them in the main documents' bodies. So if you would post it to an email list in a similar discussion, it is probably appropriate to post here.

In order to make reading these pages a pleasure for everyone, any incomprehensible, unrelated, outdated, abusive, or other completely unnecessary post may be removed by an administrator. So if you have a message that would be inappropriate on a mailing list, it's probably also inappropriate here.

The administrators have the final say on what's appropriate. We don't expect this to become an issue...

## About the new KHG

The Linux Kernel Hackers' Guide has changed quite a bit since its original conception four years ago. I struggled along with the help of many other hackers to produce a document that lived primarily on paper, and was intended to document the kernel in much the same way that a program's user guide is intended to document the program for users.

It was less successful than most user guides, for a number of reasons:

- I was working on it part time, and was otherwise busy.
- The Linux kernel is a moving target.
- I am not personally capable of documenting the entire Linux kernel.
- I became far too concerned with making the typesetting pretty, getting bogged down in details and making the document typographically noisy at the same time.

I floundered around, trying to be helpful, and made at least one right decision: most of the people who needed to read the old KHG needed to write device drivers, and the most fully-developed part of the KHG was the device driver section.

There is a clear need for further development of the KHG, and it's clear that my making it a monolithic document stood in the way of progress. The KHG is now a series of more or less independent web pages, with places for readers to leave comments and corrections that can be incorporated in the document at the maintainer's leisure--and are available to readers before they are incorporated.

The KHG is now completely web-based. There will be no official paper version. You need kernel source code nearby to read the KHG anyway, and I want to shift the emphasis from officially documenting the Linux kernel to being a learning resource about the Linux kernel--one that may well be useful to other people who want to document one part or another of the Linux kernel more fully, as well as to people who just want to hack the kernel.

Enjoy!

Copyright (C) 1996,1997 Michael K. Johnson, johnsonm@redhat.com

Messages

349. Loading shared objects - How? by Wesley Terpstra
342. How can I see the current kernel configuration? by Melwin
  1. My mouse no work in X windows by alfonso santana
340. The crash(1M) command in Linux? by Dmitry
338. Where can I gen detailed info on VM86 by Sebastien Plante
335. How to print floating point numbers from the kernel? by pkunisetty@hotmail.com
333. PS/2 Mouse Operating in Remote Mode by Andrei Racz
331. basic module by vano0023@tc.umn.edu
329. How to check if the user is local? by jb@nicol.ml.org
328. Ldt & Privileges by Ganesh
326. skb queues by Rahul Singh
323. Page locking (for DMA) and process termination? by Espen Skoglund
322. SMP code by 97yadavm@scar.utoronto.ca
319. Porting GC: Difficulties with pthreads by Talin
314. Linux for "Besta - 88"? by Dmitry
  1. MVME147 Linux by Edward Tulupnikov
313. /proc/locks by Marco Morandini
310. syscall by ppappu@lrc.di.epfl.ch
308. How to run a bigger kernel ? by Kyung D. Ryu
300. Linux Terminal Device Driver by Nils Appeldoorn
  1. Terminal DD by Doug McNash
297. DMA to user allocated buffer ? by Chris Read
  1. allocator-example in A.Rubini's book by Thomas Sefzick
293. Patching problems by Maryam
  1. Untitled by welch@mcmail.com
290. Ethernet Collision by jerome bonnet
  1. Ethernet collisions by Juha Laine
289. Segmentation in Linux by Andrew Sampson
288. How can the kernel copy directly data from one process to another process? by Jürgen Zeller
  1. Use the /Proc file system by marty@twsu.campus.mci.net
286. Remapping Memory Buffer using vmalloc/vma_nopage by Brian W. Taylor
  1. Fixed.... strncpy to blame by Brian W. Taylor
283. Does memory area assigned by "vmalloc()" get swapped to disk? by Saurabh Desai
  1. Lock the pages in memory by balaji@ittc.ukans.edu
  -> How about assigning a fixed size array...does it get swapped too? by saurabh desai
282. Creative Lab's DVD Encore by Brandon
274. TCP sliding window by Olivier
273. Packets and default route versus direct route by Steve Resnick
269. IPv6 description - QoS Implementation - 2 IP Queues by wehrle
  2. See the kernel IPv4 implementation documentation by Juha Laine
268. writing to user file directly from kernel space, How can it be done? by Johan
267. how can i increase the number of processes running? by ElmerFudd
261. How do I change the amount of time a process is allowed before it is pre-empted? by Escher@dn101aw.cse.eng.auburn.edu
260. Network device stops after a while by Andrew Ordin
  1. Untitled by Andrew
259. Does MMAP work with Redhat 4.2? by Guy
  1. Yes, it works just fine. by Michael K. Johnson
    3. What about mprotect? by Sengan Baring-Gould
    2. It Works! Thanks! by Guy
256. multitasking by Dennis J Perkins
  1. Answer by David Welch
  -> multitasking by Dennis J Perkins
  -> answer by David Welch
247. linux on sparc by darrin hodges
241. How to call a function in user space from inside the kernel ? by Ronald Tonn
  1. How to call a user routine from kernel mode by David Welch
240. Can I map kernel (device driver) memory into user space ? by Ronald Tonn
237. driver x_open,x_release work, x_ioctl,x_write don't by Carl Schwartz
  1. Depmod Unresolved symbols? by Carl Schwartz
235. How to sleep for x jiffies? by Trent Piepho
  1. Use add_timer/del_timer (in kernel/sched.c) by Amos Shapira
234. Adding code to the Linux Kernel by Patrick
  1. /dev/random by Simon Green
231. MSG_WAITALL flag by Leonard Mosescu
230. possible bug in ipc/msg.c by Michael Adda
225. scheduler Question by Arne Spetzler
  1. Untitled by Ovsov
  -> thanks by arne spetzler
221. File Descriptor Passing? by The Llamatron
220. Linux SMP Scheduling by Angela
  2. Finding definitions in the source by Felix Rauch
  1. Re: Linux SMP Scheduling by Franky
217. Difference between ELF and kernel file by Thomas Prokosch
216. How kernel communicates with outside when it's started? by Xuan Cao
  1. Printing to the kernel log by Thomas Prokosch
213. The way from a kernel hackers' idea to an "official" kernel? by Roger Schreiter
  1. linux-kernel@vger.rutgers.edu by Michael K. Johnson
212. Curious about sleep_on_interruptible() in ancient kernels. by Colin Howell
208. Server crashes using 2.0.32 and SMP by Steve Resnick
  1. Debugging server crash by Balaji Srinivasan
  -> More Information by Steve Resnick
  -> it should not have happenned... by Balaji Srinivasan
207. Signals ID definitions by Franky
206. the segment D000 is not visible by martinv2@ctima.uma.es
205. ICMP - Supressing Messages in 2.1.82 Kernel by Brent Johnson
  1. Change /etc/syslog.conf by Balaji Srinivasan
203. Modem bits by Franky
  1. Untitled by Kostya
200. I need some way to measure the time a process spend in READY QUEUE by Leandro Gelasi
197. How to make sockets work whilst my process is in kernel mode? by Mikhail Kourinny
193. Realtime Problem by Uwe Gaethke
  1. SCHED_FIFO scheduling by Balaji Srinivasan
190. inodes by Ovsov
186. Difference between SOCK_RAW SOCK_PACKET by Chris Leung
  1. SOCK_PACKET by Eddie Leung
185. Need additional termcap entries for TERM=linux by Karl Bullock
184. Question on Umount or sys_umount by teddy
183. Passing file descriptors to the kernel by Pradeep Gore
  1. A way to "transform" a file descriptor into a struct file* in a user process by Lorenzo Cavallaro
181. Dead Man Timer by Jody Winston
179. raw sockets by lightman
178. a kernel-hacking newbie by Bradley Lawrence
  2. A place to start.
  1. Modems in general by Ian Carr-de Avelon
176. How to write CD-ROM Driver ? Any Source Code ? by Madhura Upadhya
174. Measuring the scheduler overhead by Jasleen Kaur
173. Where can I find the tcpdump or snoop in linux? by wangc@taurus
  1. man which by trajek@j00nix.org
172. Timers don't work?? by Joshua Liew
  1. Timers Work... by Balaji Srinivasan
171. problem of Linux's bridge code by wangc@taurus
170. Documention on writing kernel modules by Erik Nygren
168. How to display a clock on my console? by keco
167. Difference between SCO and Linux drivers. by M COTE
165. Changing the scheduler from round robin to shortest job first for kernel 2.0 and up by royal_and_mary_harrell@msn.com
  2. Improving the Scheduer by Lee Ingram
    1. Improving the Scheduler : use QNX-like by Leandro Gelasi
  1. Re: Changing the sched. from round robin to shortest job first for kernel 2.0 and up. by Pirasenna V.T.
164. meanings of file->private_data by ncuandre@ms14.hinet.net
162. /dev/signalprocess by flatmax
161. how to track VM page access sequence? by shawn
160. Whats the difference between dev_tint(dev) and mark_bh(NET_BH)? by Jaspreet Singh
159. PCI by mullerc@iname.com
  1. RE: PCI by Armin A. Arbinger
158. Can I make syscall from inside a kernel module? by Shawn Chang
  3. Re: Can I make syscall from inside a kernel module? by Massoud Asgharifard
    1. Make a syscall despite of wrong fs!! by Mikhail Kourinny
  2. code snip to make a sys_* call from a module by Pradeep Gore
  1. Dont use system calls within kernel...(esp sys_mlock) by Balaji Srinivasan
157. Untitled by Steve Durst
154. RAW Sockets (Art)
153. use phy mem by WYB
151. HyperNews for RH Linux ? by Eigil Krogh Sorensen
  1. Not really needed by Cameron
150. about raw ethernet frame: how to do it ? by crbild@smc.it
149. process table by Blaz Novak
148. Stream drivers by Nick Egorov
  3. Streams drivers
  1. Stream in Solaris by cai.yu@rdc.etc.ericsson.se
143. Xircom External Ethernet driver anywhere? by mike head
140. interruptible_sleep_on() too slow! by Bill Blackwell
  1. wrong functions by Michael K. Johnson
139. creating a kernel relocatable module by Simon Kittle
138. Up to date serial console patches by Simon Green
136. Kernel-Level Support for Checkpointing on Linux? by Argenis R. Fernandez
  1. Working on it. by Jan Rychter
135. Problem creating a new system call by sauru
  3. How did the file /arch/i386/kernel/entry.S do its job by Wang Ju
  2. system call returns "Bad Address". Why? by sauru
    1. Re:return values by C.H.Gopinath
      2. Re:return values by Sameer Shah
      1. possible reason for segmentation fault
  1. Creating a new sytem call: solution by C.H.Gopinath
    2. problem with system call slot 167 by Todd Medlock
    1. Kernel Debuggers for Linux by sauru
133. Resetting interface counters by Keith Dart
130. writing/accessing modules by Jones MB
  1. Use a device driver and read()/write()/ioctl() by Michael K. Johnson
  -> getting to the kernel's memory by Jones MB
  -> use buffers! by Rubens
124. Help with CPU scheduler! by Lerris
  1. Response to "Help with CPU scheduler!" by Jeremy Impson
  -> Response to "Help with CPU scheduler!" (Redux) by Jeremy Impson
117. calling interupts from linux by John J. Binder
  1. You can't by Michael K. Johnson
  -> Calling BIOS interrupts from Linux kernel by Ian Collier
  -> Possible, but takes work by Michael K. Johnson
  -> VBE video driver by Ian Collier
  -> VM86 mode at which abstraction level? by Michael K. Johnson
116. DVD-ROM and Linux? (sorry if it's off topic...) by Joel Hardy
  3. DVD-ROM and linux by Yuqing_Deng@brown.edu
  2. Response to DVD and Mpeg in Linux by Mike Corrieri
    1. DVD Encryption by Mark Treiber
    -> Untitled by Tim
    -> DVD?
115. Kernel Makefile Configuration: how? by Simon Green
  2. How to add a driver to the kernel ? by jacek Radajewski
  1. See include/linux/autoconf.h by Balaji Srinivasan
113. Multiprocessor Linux by Davis Terrell
  1. Building an SMP kernel by Michael K. Johnson
  -> SMP and module versions by linux@catlimited.com
111. Improving event timers? by bodomo@hotmail.com
109. measuring time to load a virtual mem page from disk by kandr
94. using cli/sti() and save_flags/restore_flags() by george
93. Protected Mode by ac
  2. 'Developers manual' from Intel(download)... by Mats Odman
  1. Advanced 80386 Programming Techniques by Michael K. Johnson
92. DMA buffer sizes by nomrom@hotmail.com
  2. DMA limits by Albert Cahalan <acahalan at cs.uml.edu>
  1. Not page size, page order by Michael K. Johnson
91. Problem Getting the Kernel small enough by afish@tdcdesigncorps.com
  2. Check it's the right file, zImage not vmlinux by Cameron
  1. Usually easy, but.... by Ian Carr-de Avelon
89. How to create /proc/sys variables? by Orlando Cantieni
88. Linux for NeXT black? by Dale Amon
87. vremap() in kernel modules? by Liam Wickins
86. giveing compatiblity to win95 for ext2 partitions (for programmers forced to deal with both) by pharos
  2. Well, What's the status of the Windows / Dos driver for Ext2? by Brock Lynn
  1. Working on it! by ibaird
    1. revision by ibarid
    -> Untitled by Olaf
84. setsockopt() error when triying to use ipfwadm for masquerading by omaq@encomix.es
  1. Re: masquerading by Charles Barrasso
83. reset the irq 0 timer after APM suspend by Dong Chen
  1. Re: fixed, patch for kernel 2.0.30 by Dong Chen
77. Source Code in C for make Linux partitions. by Limbert Sanabria
  1. Untitled by lolley
76. How can I "cheat" and change the IP address (src,dest) in the sent socket? by Rami
  5. Transparent Proxy by Zygo Blaxell
  4. Untitled by qwzhang@public2.bta.net.cn
  3. Untitled by navin97@hotmail.com
    2. Changing your IP address is easy, but... by Zygo Blaxell
    1. You have to know a bit of C (if u wanna learn) ;) by Lorenzo Cavallaro
  2. Untitled
  1. Do it in the kernel by Michael K. Johnson
74. Where is the source file for accept() by kaixu@hocpa.ho.lucent.com
  1. Here, in /usr/src/linux/net/socket.c by wumin@netchina.co.cn
72. How can I use RAW SOCKETS in UNIX? by Rami
  1. Re: Raw sockets by genie@risq.belcaf.minsk.by
69. the KHG in spanish? by Jorge Alvarado Revatta
  2. Si tenga preguntas, quisa yo pueda ayudarte. by KernelJock
    3. Tengo una pregunta by riderghost@rocketmail.com
    2. Espaņol by LL2
  1. No esta aqui! Pero... by Michael K. Johnson
67. How to get a Memory snapshot ? by Manuel Porras Brand
  1. Why not to get a memory snapshot? by Jukka Santala
  -> Why you would want to get a memory snapshot by Dave M.
66. resources hard limits by castejon@kbw350.chem.yale.edu
  1. Setting resource limits by Jukka Santala
65. How to invalidate a chache page by Gerhard Uttenthaler
  1. Read the rest of the KHG! by Michael K. Johnson
64. Where are the tunable parameters of the kernel? by demiguel@robot3.cps.unizar.es
  1. Kernel tunable parameters by Jukka Santala
62. How can my device driver access data structures in user space? by Stephan Theil
  1. Forced Cast data type by Wang Ju
61. Problem in doing RAW SOCKET Programming by anjali sharma
  1. Problem with ICMP echo-request/reply by Raghavendra Bhat
59. Tunable Kernel Parameters? by dennyf@bmn.net
  2. Increasing number of files in system by Simon Cooper
    1. Increasing number of open files parameter by Simon Cooper
  1. sysctl in Linux by Jukka Santala
    1. Setting and getting kernel vars by kbrown@csuhayward.edu
58. ELF matters by Carlos Munoz
  1. Information about ELF Internals by Pat Ekman
57. Droping Packets by Charles Barrasso
  1. [Selectively] Droping Packets by Jose R. cordones
56. The /proc/profile by Charles Barrasso
  1. readprofile systool by Jukka Santala
55. Can you block or ignore ICMP packets? by HackOps@nutnet.com
  4. ICMP send rate limit / ignoring by Jukka Santala
    1. Omission in earlier rate-limit... by Jukka Santala
    -> Patch worked... by Jukka Santala
  3. Using ipfwadm by Charles Barrasso
    1. ipfwadm configuration utility by Sonny Parlin
  1. Icmp.c and kernal ping replies by Don Thomas
52. encaps documentation by Kuang-chun Cheng
51. Mounting Caldrea OpenDOS formatted fs's by Trey Childs
49. finding the address that caused a SIGSEGV. by Ben Shelef
47. sti() called too late. by Erik Thiele
  1. sti() called too late. by Gadi Oxman
38. Module Development Info? by Mark S. Mathews
  1. Needed here too by ajay
  2. Help needed here too! by ajay
35. Need quicker timer than 100 ms in kernel-module by Erik Thiele
  1. 10 ms timer patch by Reinhold J. Gerharz
    2. please send me 10 ms timer patch by Tolga Ayav
    1. Please send me the patch by Jin Hwang
      1. UTIME: Microsecond Resolution Timers by BalajiSrinivasan
34. Need help with finding the linked list of unacked sk_buffs in TCP by Vijay Gupta
31. Partition Type by Suman Ball
30. New document on exception handling by Michael K. Johnson
29. How to make paralelism in to the kernel? by Delian Dlechev
27. readv/writev & other sock funcs by Dave Wreski
25. I'd like to see the scheduler chapter by Tim Bird
  1. Untitled by Vijay Gupta
  3. Go ahead! by Michael K. Johnson
21. Unable to access KHG, port 8080 giving problem. by Srihari Nelakuditi
  1. Get a proxy by Michael K. Johnson
20. proc fs docs? by David Woodruff
  1. Examples code as documentation by Jeremy Impson
18. What is SOCK_RAW and how do I use it? by arkane
  1. What raw sockets are for. by Cameron MacKinnon
15. Linux kernel debugging by yylai@hk.net
  2. GDB for Linux by David Grothe
    2. Another kernel debugging tool by David Hinds
      2. Kernel debugging with breakpoints by Keith Owens
      -> Need help for debugging by C.H.Gopinath
    1. gdb debugging of kernel now available by David Grothe
  1. Device debugging by alombardĐiiic.ethz.ch
9. Realtime mods anyone? by bill duncan
  7. Summary of Linux Real-Time Status by Markus Kuhn
  6. Hard real-time now available by Michael K. Johnson
    2. Shortcomings of RT-Linux by Balaji Srinivasan
    1. Firm Realtime available by Balaji Srinivasan
  5. found some hacks ?!? by Mayk Langer
    2. I want to know how to hack Red Hat Linux Release 5.0 by Kevin
  4. POSIX.4 scheduler by Peter Monta
    1. cli()/sti() latency, hard numbers by Ingo Molnar
  2. Realtime is already done(!) by Kai Harrekilde-Petersen
  1. 100 ms real time should be easy by jeff millar
    1. Real-Time Applications with Linux POSIX.4 Scheduling by P. Woolley
7. Why can't we incorporate new changes in linux kernel in KHG ? by Praveen Kumar Dwivedi
  1. You can! by Michael K. Johnson
3. Kernel source code by Gabor J.Toth
  1. The sounds of silence... by Gabor J.Toth
    1. Breaking the silence :) by Kyle Ferrio
      1. Scribbling in the margins by Michael K. Johnson
    2. It requires thought... by Michael K. Johnson
  2. Kernel source is already browsable online by Axel Boldt
2. Need easy way to download whole KHG
  5. KHG being mirrored nightly for download! by Michael K. Johnson
  2. postscript version of these documents? by Michael Stiller
    1. Sure! by Michael K. Johnson
    -> Not so Sure! by jeff millar
    -> Enough already! by Michael K. Johnson
  1. Mirror packages are available, but that's not really enough by Michael K. Johnson
    4. Mirror whole KHG package, off line reading and Post to this site by Kim In-Sung
      2. Untitled by Jim Van Zandt
      1. That works. (using it now). Two tips: by Richard Braakman
        2. Appears to be a bug in getwww, though... by Michael K. Johnson
        -> Sucking up to the wrong site... ;) by Jukka Santala
1. Help make the new KHG a success by Michael K. Johnson