Kernel learning FAQ highlights

Source: Internet
Author: User
Kernel learning FAQ highlights-general Linux technology-Linux programming and kernel information. For more information, see the following. 1. Please recommend some good Linux kernel reference books?
A. Linux Device Drivers, Second Edition, with Chinese Translations
B. Understanding the Linux Kernel, 2nd Edition
C. Linux kernel source code scenario analysis, which is divided into two volumes:
D. Learn while doing-Linux kernel Guide


2. kernel source code Problems
2.1 How to obtain the Linux kernel source code of a certain version?
A. http://www.kernel.org or ftp://ftp.kernel.org, This is the release of the Linux kernel version
Website.
B. Many images or local websites also provide download of some Linux kernel versions and use ftp search engines.
C. General Linux distributions such as Redhat will provide the corresponding kernel source code along with the disk, but this source generation
The code is often changed, and may be different from the standard Linux kernel of the same version.

2.2 are some source code viewing tools recommended?
A. You can use Source Insight in Windows and Source Navigator in Linux.
B. vim or emacs editor, used with cross-index tools such as cssag, ctags, and etags.
C. vim or emacs editor, combined with grep, egrep and other text search tools, but it is best to view the source code
Familiar with the recording Structure
D. LXR, which can be viewed on a web page through a browser. The installation is complex and can be found at http://lxr.linux.no /.
You can also directly access http://lxr.linux.no/source/onlinelinux
Code.

Which kernel source file is the definition of the 2.3 xx structure?
A. Use the source code check tool. For details, see question 2.2.
B. If grep and other text search tools are used, they are mainly in the include/linux and include/asm directories.
Search.

2.4 What does volatile and _ volatile _ mean?
A. volatile is a keyword defined in C language. For the sake of its needs, gcc defines _ volatile __, which corresponds
Volatile indicates the same meaning.
B. volatile is intended to be "changeable". Since the access register speed is faster than the access memory, the compiler generally
All are optimized to reduce memory access. If the variable is modified with volatile, the compiler does not
Read/write operations are optimized, that is, directly accessing the memory without using the register buffer.
C. _ asm _ volatile _ indicates that the compiler should not modify the Assembly statements after optimization.

2.5 do {...} while (0) What does it mean?
A. It is mainly used to avoid some errors that may occur when macros are expanded in different situations.
B. Detailed descriptions are provided at http://www.kernelnewbies.org/faq.

2.6 What is the definition of list_entry?
A. list_entry is defined in the kernel source File include/linux/list. h:
# Define list_entry (ptr, type, member )\
(Type *) (char *) (ptr)-(unsigned long) (& (type *) 0)-> member )))
B. Its function is to convert the pointer ptr of list_head to the starting address of its host structure. The host structure is
Type, and ptr is defined as a member in its host structure. For example:

Req> | start address of type object
|
| ......
Ptr> | member address indicated by the ptr pointer
|
| ......

Ptr points to the position shown in the figure. The ptr is obtained through (unsigned long) (& (type *) 0)-> member ).
Difference between the value and req, ptr minus this difference to get the type host structure pointer req, return
Type: (type *).


3. module programming problems
3.1 What should I pay attention to when programming modules?
A. Add-c to the gcc compilation Option
B. Define two Macros in the gcc compilation options:-DMODULE-d1_kerenl __
Or define these two macros directly in the source file:
# Define MODULE
# Define _ KERNEL __
C. Include the module. h file in the source file:
# Include
D. If you want to use the inline function, add-O2 to the gcc compilation option.

3.2 why does the version of the insmod module not match?
Assume that the absolute path of the source code directory of the kernel you are running is MyKernelSrcPath.
Added options:
-I $ MyKernelSrcPath/include

3.3 why does Unresolved Symbol appear?
A. first check the file/proc/ksyms to see if the kernel has output this symbol. Different kernel versions are shown in figure
The symbols output by 2.2 and 2.4 may change.
B. If the symbol output by the kernel carries version control information such as printk_R12345678, it is of the same nature
Issue 3.2.

3.4 why is the no license error?
Add the following line to the source file:
MODULE_LICENSE ("GPL ");

3.5 why can't I see the information printed with printk?
A. The message printing level is restricted. You can set the message level through printk, for example:
Printk (" Something ");/* where 0 <= n <= 7 */
Assume that the Message Level in the console is m, when n In this way, you can increase the level of the message to be printed (the smaller the number, the higher the level ),
On the other hand, you can change the message level of the console (from 1 to 8). For example, you can change the message level to 8 by using the following command:
# Echo "8">/proc/sys/kernel/printk
B. Run the dmesg command.
C. When the system runs klogd and syslogd, kernel messages are distributed to syslogd by klogd,
Syslogd will be processed according to the configuration file/etc/syslog. conf. For details, see syslogd
And syslog. conf man pages.


4. kernel development problems
4.1 how to create and use patch files?
The patch file is generated by the diff command. You can use the patch command to view the diff and
The man page and info of the patch.

4.2 can the system call be used in the kernel?
A. Yes. There are examples of using system calls in the kernel source code, such as open () and execve.
B. To use system calls in the kernel, the following two lines must be included in the source file:
# Define _ kernel_syscils __
# Include
C. Check the include/asm/unistd. h file by using the definition of system call in the kernel.
If you want to use a system call that is not defined in this file, you can add it as needed.

4.3 how to open and operate a file in the kernel?
A. directly use open (), read (), and other systems for calling. See question 4.2.
B. Use the filp_open () function to open the file and obtain the pointer fp of struct file.
Use the pointer fp for corresponding operations. For example, you can use fp-> f_ops-> read to read a file.
Finally, use the filp_close () function to close the file.
The filp_open () and filp_close () functions are defined in fs/open. c and in include/linux/fs. h.
Statement.
C. Write the packaging function by yourself. You can refer to the open_exec () and kernel_read () functions in file fs/exec. c.
In http://www.linuxforum.net/forum/showflat.php? Cat = & Board = linuxK
& Number = 363455 & page = & view = & sb = & o = & vc = 1 some code can be referenced.

4.4 why does the EFAULT error occur when reading and writing files in the kernel?
A. functions such as read () and write () provided by the Kernel File System are expected to serve user-state programs,
Therefore, it verifies that the read/write buffer does not exceed the user space limit, that is, 0xC000 0000. But in the kernel
To read and write files, the buffer address in the kernel will exceed 0xC000 0000.
B. Obtain the current fs: mm_segment_t old_fs = get_fs ();
Set the current fs as the kernel fs: set_fs (KERNEL_DS );
After reading and writing the file, restore the original fs: set_fs (old_fs );
Set_fs (), get_fs () and other related macros are defined in the File include/asm/uaccess. h.


5. Others

5.1 which file is the source code of the xx command and library?
A. In addition to the kernel, a system also needs a series of tools and commands, such as shell and gcc, and a C library.
The source code of these applications is not in the kernel, and the corresponding source code needs to be downloaded separately.
B. For the Redhat system, you can use the rqm-qf command to find the software package where a command is located, and then find
Install the corresponding source code package.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.