用户空间(userspace)引用jiffies

本文来自 http://blog.chinaunix.net/space.php?uid=11426705&do=blog&id=2875456


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

http://topic.csdn.net/u/20080905/12/a3355510-636e-4519-8205-dc482e07e8c8.html


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


int main (int argc, char* argv[])
{
    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));
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值