阅读:1028回复:0
怎么读写低端内存呢?
我想写段地址为0偏移地址为300的这快内存。用了以下这个代码。
可是发现读出来的是0。请问读写低端内存是用这种办法吗? void main(int argc,char * argv[]) { int fd; int len; int i = 0; unsigned char buf[1]; buf[0] =0x01; printf("buf[0]= %x\r\n",buf[0]); fd = open("/dev/mem",O_RDWR,0x666); if (fd < 0) { printf("open /dev/mem failed\r\n"); return; } lseek(fd,(off_t)0xD000000L,SEEK_SET); len = write(fd,buf,sizeof(buf)); if(len <= 0) { printf("write failed = %s\r\n",strerror(errno)); close(fd); return; } printf("write len =%x\r\n",len); memset(buf,0,1); lseek(fd,(off_t)0x300,SEEK_SET); len = read(fd,buf,sizeof(buf)); if(len <= 0) { printf("read failed = %s\r\n",strerror(errno)); close(fd); } printf("read len =%d\r\n",len); for( i = 0; i < len; i++) { printf("buf[%d] = %x\r\n",i,buf); } close(fd); return; } |
|