免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1892 | 回复: 3
打印 上一主题 下一主题

insmod 某个驱动报错问题 [复制链接]

论坛徽章:
36
CU大牛徽章
日期:2013-09-18 15:24:20NBA常规赛纪念章
日期:2015-05-04 22:32:03牛市纪念徽章
日期:2015-07-24 12:48:5515-16赛季CBA联赛之辽宁
日期:2016-03-30 09:26:4715-16赛季CBA联赛之北控
日期:2016-03-30 11:26:2315-16赛季CBA联赛之广夏
日期:2016-05-20 15:46:5715-16赛季CBA联赛之吉林
日期:2016-05-24 11:38:0615-16赛季CBA联赛之青岛
日期:2016-05-30 13:41:3215-16赛季CBA联赛之同曦
日期:2016-06-23 16:41:052015年亚洲杯之巴林
日期:2015-02-03 15:05:04CU大牛徽章
日期:2013-09-18 15:24:52CU十二周年纪念徽章
日期:2013-10-24 15:46:53
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-11-05 16:59 |只看该作者 |倒序浏览
在内核版看到一个获取物理地址的源码,有兴趣就编译了下,结果却卡在了insmod上。
2.6.19的内核 root权限下:
insmod getpgd.ko
insmod: error inserting 'getpgd.ko' : -1 Operation not permitted.

而我insmod其它驱动的时候却没问题,所以怀疑是不是源码里的一些代码不能执行造成的。
可初学,不知道如何下手,希望大家指点下。
源码如下:
  1. /*******************************************************************************
  2.   
  3.   Copyright(c) 2008-2012

  4.   This program is free software; you can redistribute it and/or modify it
  5.   under the terms and conditions of the GNU General Public License,
  6.   version 2, as published by the Free Software Foundation.

  7.   This program is distributed in the hope it will be useful, but WITHOUT
  8.   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9.   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  10.   more details.

  11.   You should have received a copy of the GNU General Public License along with
  12.   this program; if not, write to the Free Software Foundation, Inc.,
  13.   51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.

  14.   The full GNU General Public License is included in this distribution in
  15.   the file called "COPYING".

  16.   Version:  0.1

  17.   Date: 2012-04-21 10:25:55 CST

  18.   Contact Information:
  19.   Tony <tingw.liu@gmail.com>
  20.   Home, Qingdao, China.
  21. *******************************************************************************/

  22. #include <linux/module.h>
  23. #include <asm/pgtable.h>
  24. #include <linux/version.h>
  25. #include <asm/page.h>
  26. #include <linux/gfp.h>
  27. #include <linux/page-flags.h>
  28. #include <linux/sched.h>//find_task_by_vpid
  29. #include <linux/mm.h>//find_vma
  30. #include <asm/uaccess.h>
  31. #include <asm/page.h>
  32. #include <asm/e820.h>

  33. #include <asm/pgtable_types.h>

  34. MODULE_LICENSE("GPL");
  35. MODULE_AUTHOR("Tony <tingw.liu@gmail.com>");
  36. MODULE_DESCRIPTION("CONVERT USER VIRTUAL ADDRESS TO PHYADDRESS");
  37. static int pid;
  38. static unsigned long va;
  39. module_param(pid, int, 0644);
  40. module_param(va, ulong, 0644);

  41. static int find_pgd_init(void)
  42. {
  43.         unsigned long pa=0;
  44.         struct task_struct *pcb_tmp=NULL;
  45.         struct page *ppage = NULL;
  46.         unsigned long pfn = 0;
  47.         pgd_t *pgd_tmp = NULL;
  48.         pud_t *pud_tmp = NULL;
  49.         pmd_t *pmd_tmp = NULL;
  50.         pte_t *pte_tmp = NULL;
  51.         printk(KERN_ALERT "PAGE_OFFSET=0x%lx\n", PAGE_OFFSET);
  52.         printk(KERN_ALERT "PGDIR_SHIFT=%d\n", PGDIR_SHIFT);
  53.         printk(KERN_ALERT "PUD_SHIFT=%d\n", PUD_SHIFT);
  54.         printk(KERN_ALERT "PMD_SHIFT=%d\n", PMD_SHIFT);
  55.         printk(KERN_ALERT "PAGE_SHIFT=%d\n", PAGE_SHIFT);
  56.         printk(KERN_ALERT "PTRS_PRE_PGD=%d\n", PTRS_PER_PGD);
  57.         printk(KERN_ALERT "PTRS_PRE_PUD=%d\n", PTRS_PER_PUD);
  58.         printk(KERN_ALERT "PTRS_PRE_PMD=%d\n", PTRS_PER_PMD);
  59.         printk(KERN_ALERT "PTRS_PRE_PTE=%d\n", PTRS_PER_PTE);

  60.         printk(KERN_ALERT "PAGE_MASK=0x%lx\n", PAGE_MASK);
  61.         if (!(pcb_tmp = pid_task(find_vpid(pid), PIDTYPE_PID))) {
  62.                 printk(KERN_ALERT "Can't find the task %d.\n", pid);
  63.                 return -1;
  64.         }
  65.         printk(KERN_ALERT "pgd=0x%p\n", pcb_tmp->mm->pgd);
  66.         if (!find_vma(pcb_tmp->mm, va)) {
  67.                 printk(KERN_ALERT "virt_addr 0x%p not available.\n", va);
  68.                 return -1;
  69.         }
  70.         pgd_tmp = pgd_offset(pcb_tmp->mm, va);
  71.         printk(KERN_ALERT "pgd_tmp=0x%p\n", pgd_tmp);
  72.         printk(KERN_ALERT "pgd_val(*pgd_tmp)=0x%p\n", pgd_val(*pgd_tmp));
  73.         if (pgd_none(*pgd_tmp) || pgd_bad(*pgd_tmp)) {
  74.                 printk(KERN_ALERT "Not mapped in pgd.\n");
  75.                 return -1;
  76.         }
  77.         pud_tmp = pud_offset(pgd_tmp,va);
  78.         if (pud_none(*pud_tmp) || pud_bad(*pud_tmp)) {
  79.                 printk(KERN_ALERT "Not mapped in pud.\n");
  80.                 return -1;
  81.         }
  82.         pmd_tmp = pmd_offset(pud_tmp,va);
  83.         if (pmd_none(*pmd_tmp) || pmd_bad(*pmd_tmp)) {
  84.                 printk(KERN_ALERT "Not mapped in pmd.\n");
  85.                 return -1;
  86.         }
  87.         /*FIXME:
  88.           Do I need to check Large Page ? PSE bit.
  89.                 if(pmd_large(*pmd_tmp) == 1){
  90.                         pa = (pmd_val(*pmd_tmp) & PMD_MASK) | (va & ~PMD_MASK);
  91.                 }
  92.           */
  93.         pte_tmp = pte_offset_kernel(pmd_tmp, va);
  94.         if (!pte_tmp || pte_none(*pte_tmp)) {
  95.                 printk(KERN_ALERT "Not mapped in pte.\n");
  96.                 return 0;
  97.         }
  98.         if (!pte_present(*pte_tmp)) {
  99.                 printk(KERN_ALERT "pte not in RAM,maybe swaped.\n");
  100.                 return 0;
  101.         }
  102.         ppage = pte_page(*pte_tmp);
  103.         pfn = page_to_pfn(ppage);
  104.         pa = page_to_phys(ppage);
  105.         pa = pa|(va&~PAGE_MASK);
  106.         printk(KERN_ALERT "virt_addr 0x%lx in RAM is 0x%lx.\n",va,pa);
  107.         printk(KERN_ALERT "content in 0x%lx is 0x%lx.\n",pa,*(unsigned int*)(__va(pa)));
  108.         return 0;
  109. }
  110. static void find_pgd_exit(void)
  111. {
  112.         printk(KERN_ALERT "Goodbey.\n");
  113. }
  114. module_init(find_pgd_init);
  115. module_exit(find_pgd_exit);
复制代码

论坛徽章:
1
射手座
日期:2013-11-07 09:19:48
2 [报告]
发表于 2013-11-05 18:08 |只看该作者
dmesg有什么线索吗?

论坛徽章:
36
CU大牛徽章
日期:2013-09-18 15:24:20NBA常规赛纪念章
日期:2015-05-04 22:32:03牛市纪念徽章
日期:2015-07-24 12:48:5515-16赛季CBA联赛之辽宁
日期:2016-03-30 09:26:4715-16赛季CBA联赛之北控
日期:2016-03-30 11:26:2315-16赛季CBA联赛之广夏
日期:2016-05-20 15:46:5715-16赛季CBA联赛之吉林
日期:2016-05-24 11:38:0615-16赛季CBA联赛之青岛
日期:2016-05-30 13:41:3215-16赛季CBA联赛之同曦
日期:2016-06-23 16:41:052015年亚洲杯之巴林
日期:2015-02-03 15:05:04CU大牛徽章
日期:2013-09-18 15:24:52CU十二周年纪念徽章
日期:2013-10-24 15:46:53
3 [报告]
发表于 2013-11-05 22:29 |只看该作者
回复 2# guocslock
    dmesg 就是找不到pid。
    重启了就好了,奇怪了, pid和via不知道怎么传不进去.初学很多不懂,以后学习深入了再回过来看看

论坛徽章:
0
4 [报告]
发表于 2013-11-06 16:02 |只看该作者
初学弄这么多代码,换个简单先玩玩,把框架整明白了,在逐渐加入新的东西。我感觉static int xx()这个地方就有问题。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP