Linux Kernel exception

Source: Internet
Author: User

From: http://blog.chinaunix.net/space.php? Uid = 24219701 & Do = Blog & id = 2876128

Kernel-level programs always crash. If you are lucky, you will see some so-called "oops" Information (on the screen or in system logs)

For example:

Unable to handle kernel paging request at virtual address f899b670

Printing EIP:

C01de48c

* PVDF = 00737067

Oops: 0002 [#1]

Modules linked in: bluesmoke_e752x bluesmoke_mc MD5 IPv6 parport_pc

LP parport nls_cp936 vfat fat dm_mod button battery asus_acpi AC joydev

CPU: 0

EIP: 0060: [] not tainted vli

Eflags: 00210286 (2.6.9-11.21 axkprobes)

EIP is at kobject_add + 0x83/0 xd7

...............................

 

Oops can be viewed as a kernel-level segmentation fault. If the application has performed illegal memory access or executed illegal commands, it will get the segfault signal. The common behavior is coredump. The application can also intercept the segfault signal and process it on its own. If the kernel makes such an error, oops information is displayed.

 

Oops exception analysis: Write the kernel module to generate kernel exceptions. analyze the causes of exceptions based on oops.

Exception Code:

# Include <Linux/module. h>

# Include <Linux/kernel. h>

# Include <Linux/init. h>

 

Void D (void)

{

Int * P = NULL;

Int A = 6;

Printk ("function d \ n ");

* P = a + 5;

}

 

Void C (void)

{

Printk ("Function C \ n ");

D ();

}

 

Void B (void)

{

Printk ("function B \ n ");

C ();

}

 

Void A (void)

{

Printk ("function a \ n ");

B ();

}

 

Int oops_init (void)

{

Printk ("Oops init \ n ");

A ();

Return 0;

}

 

Void oops_exit (void)

{

Printk ("Oops exit! \ N ");

}

 

Module_init (oops_init );

Module_exit (oops_exit );

Module_license ("GPL ");

Module_author ("David xie ");

 

1. Compile and load the module

2. The oops error message is displayed when the module is loaded.

3. Cause of Error Analysis: "unable to handle kernel Null Pointer Dereference at vitual address 00000000" indicates that the error is caused by illegal access to null pointers.

4. Locate the error location: "PC is at D + 0x1c/0x28 [oops]" indicates that the error location is at 0x1c of the d function offset.

5. Find the error location through Disassembly

# Objdump-d-s oops. Ko> log

If you add the "-G" debugging option during compilation, you can see the corresponding C language code, and you can easily find the problem.

Add the debugging option: Enable "-G" in the MAKEFILE file in the kernel.

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.