Chinaunix首页 | 论坛 | 博客
  • 博客访问: 187873
  • 博文数量: 45
  • 博客积分: 1456
  • 博客等级: 上尉
  • 技术积分: 535
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-21 17:47
文章分类
文章存档

2012年(1)

2009年(43)

2008年(1)

我的朋友

分类: LINUX

2009-05-14 21:41:32

用户空间(userspace)引用jiffies

写在前面,该方法并非原创,乃是根据csdn中一网友回帖改编而来。此方法可以推广,用以引用任何内核中的资源。




#include <stdio.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>


int main ()
{
    unsigned long offset = 0xc06e1740; /* 0xc06e1740 is from

                                        * /boot/System.map-2.6.xx
                                        * c06e1740 D jiffies
                                        */


    offset -= 0xc0000000;

    int fd;
    fd = open("/dev/mem", O_RDONLY);

    void *p;
    p = mmap(0, 0x10000, PROT_READ, MAP_SHARED, fd, (off_t)(offset - offset%0x10000));

    volatile unsigned long *pJiffies;
    pJiffies = (volatile unsigned long *)((char *)p + offset%0x10000);
    
    int i;
    for (i = 0; i < 1000; i++)
    {
     printf ("jiffies = %ul\n",(unsigned long)(*pJiffies));
    }
}

阅读(2253) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~