March 5, 2015

memdump function in kernel

void memdump(unsigned char *rdesc, int *rsize){
    int i,pos=0;
    unsigned char outbuf[256];
    printk(KERN_WARNING "rsize=%d\n",*rsize);
    for (i=0;i<*rsize;i++){
        pos+=sprintf(outbuf+pos,"%02x ",rdesc[i]);
        if (i>0 && ((i+1)%16)==0){
            printk(KERN_WARNING "%04x dump %s\n",(i/16)*16,outbuf);
            pos=0;
        }
    }
    if (pos>0){
        printk(KERN_WARNING "%04x dump %s\n",(i/16)*16,outbuf);
    }
}

No comments:

Post a Comment