主题 : kmalloc crash 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 21782
精华: 0
发帖: 6
金钱: 30 两
威望: 6 点
综合积分: 12 分
注册时间: 2010-05-21
最后登录: 2015-09-28
楼主  发表于: 2010-06-19 13:10

 kmalloc crash

目标板硬件平台:xscale ixp43x
目标板软件平台:linux2.6.23.1

我写的很简单的内核模块:
#include <linux/module.h>       /* Needed by all modules */
#include <linux/kernel.h>       /* Needed for KERN_INFO */
#include <linux/init.h>         /* Needed for the macros */

void* mem;

static int __init hello_start(void)
{
    size_t size = 64;
    printk(KERN_EMERG"Loading hello module...\n");

    mem = kmalloc(size, GFP_ATOMIC);

    printk(KERN_EMERG"Hello world\n");
    return 0;
}

static void __exit hello_end(void)
{
    printk(KERN_EMERG"Goodbye Mr.\n");
    kfree(mem);
}

module_init(hello_start);
module_exit(hello_end);
MODULE_LICENSE("GPL");

将这个交叉编译好的hello.ko放到目标板上,然后insmod hello.ko,输出以下Oops:
Loading hello module...
Unable to handle kernel paging request at virtual address 00001000
pgd = cee9c000
[00001000] *pgd=0ee93031, *pte=00000000, *ppte=00000000
Internal error: Oops: 17 [#1]
Modules linked in: hello sg sd_mod usb_storage scsi_mod uhci_hcd ehci_hcd usbcore moxa_dio moxa_software_id mxser_uc8400(P) nfs nfs_acl lockd sunrpc 8139too ixp400_eth ixp400
CPU: 0    Tainted: P         (2.6.23.1 #986)
pc : [<c0079168>]    lr : [<c0079674>]    psr: a0000093
sp : cf7a9ea4  ip : 00001000  fp : cf7a9ed0
r10: ffffffff  r9 : 00000020  r8 : 00000013
r7 : c026e378  r6 : 00000020  r5 : 00000fe8  r4 : 60000013
r3 : c41ef5c0  r2 : ffffffff  r1 : 00000020  r0 : c026e378
Flags: NzCv  IRQs off  FIQs on  Mode SVC_32  ISA ARM  Segment user
Control: 000039ff  Table: 0ee9c000  DAC: 00000015
Process insmod (pid: 912, stack limit = 0xcf7a8258)
Stack: (0xcf7a9ea4 to 0xcf7aa000)
9ea0:          cf7a9ec0 60000013 bf1c51d0 00000020 c026e378 00000013 bf1c51dc
9ec0: bf1c51d0 cf7a9ef4 cf7a9ed4 c0079674 c00790e0 00000000 bf1c51d0 bf1c51d0
9ee0: cccccccd d08624d8 cf7a9f04 cf7a9ef8 bf1c7020 c00795f4 cf7a9fa4 cf7a9f08
9f00: c005a778 bf1c700c 00000000 cf7a8000 00000000 00000000 00000000 00000000
9f20: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
9f40: 00000000 00000012 d0862a78 cf714040 00000000 d0862690 d0862000 00000008
9f60: 00000000 00000024 00000024 d08627a8 00000011 00000000 00000000 00000028
9f80: beda7e81 beda7dac 00000080 c001dfc4 cf7a8000 401a3048 00000000 cf7a9fa8
9fa0: c001de20 c005a65c beda7e81 beda7dac 00900080 00097018 00000b41 00097008
9fc0: 00000028 beda7e81 beda7dac 4000b10c 00000002 0000c814 401a3048 beda7d24
9fe0: beda7cf0 beda7ce4 0000fa34 40153f00 60000010 00900080 ffffffff feffffff
Backtrace:
Function entered at [<c00790d4>] from [<c0079674>]
Function entered at [<c00795e8>] from [<bf1c7020>]
r7:d08624d8 r6:cccccccd r5:bf1c51d0 r4:bf1c51d0
Function entered at [<bf1c7000>] from [<c005a778>]
Function entered at [<c005a650>] from [<c001de20>]
Code: e3530000 0a000017 e597c01c e24c5018 (e5950018)

只打印了“Loading hello module...”,没有“Hello world”,应该是kmalloc出问题了,但网上找了很多资料,也不清楚为什么会出错,要是哪位高人知道,还请指点一下,多谢了!
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
1楼  发表于: 2010-06-20 16:43
Function entered at [<c00790d4>] from [<c0079674>]
Function entered at [<c00795e8>] from [<bf1c7020>]

对照System.map查一下这几个地址是什么函数
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."