linux - /proc/self/maps write memory to file using fwrite bad address error -


i try write memory file, using fwrite, "bad address". don't know reason.

the code showed below

static struct mmapheader* mmap_headers[header_max];  struct mmapheader {     bool iscontext; // used mark end of maps     size_t start; //process memory start address     size_t len; // process memory size     int prot; // permission     size_t offset; //offset     char file_name[file_name_max]; //file name };  for(i=0;mmap_headers[i]!=null;i++) {     if(mmap_headers[i]->prot & prot_read)     {         printf("save map information start:%zx,len:%zx\n",mmap_headers[i]->start,mmap_headers[i]->len);         if(fwrite(mmap_headers[i],sizeof(struct mmapheader),1,save_file)<1)             perror("following error occur:");         fflush(save_file);         //******         //error in fwrite below, mmap_headers[i]->start address of         //memory, address read file /proc/self/maps value         //7ffea6de4000(hex), mmap_headers[i]->len 2000(hex).          if(fwrite((void*)mmap_headers[i]->start,mmap_headers[i]->len,1,save_file)<1)             perror("following error occur:");//here "bad address error address 7ffea6de4000(hex)"         fflush(save_file);     } } 

output is:

save map information start:400000,len:c1000 save map information start:6c0000,len:3000 save map information start:6c3000,len:3000 save map information start:1921000,len:23000 save map information start:2b7d46805000,len:2000 save map information start:7ffea6dc3000,len:21000 save map information start:7ffea6de4000,len:2000 following error occur:: bad address save map information start:7ffea6de6000,len:200 

mmap_headers store process information read file /proc/self/maps, size of mmap_headers 8, other 7 address write except address 7ffea6de4000(hex), has idea?

"bad address" corresponds error code efault. if read manual page underlying system call, man 2 write, find description of error:

efault buf outside accessible address space. 

this means address have passed fwrite (and write) not valid.

if run cat /proc/self/maps, can see in program cat, there unreadable pages:

00400000-0040c000 r-xp 00000000 00:11 6447384                            /usr/bin/cat 0060b000-0060c000 r--p 0000b000 00:11 6447384                            /usr/bin/cat 0060c000-0060d000 rw-p 0000c000 00:11 6447384                            /usr/bin/cat 0060d000-0062e000 rw-p 00000000 00:00 0                                  [heap] 34ddd837000-34dddba0000 r--p 00000000 00:11 6755848                      /usr/lib/locale/locale-archive 34dddba0000-34dddd3b000 r-xp 00000000 00:11 6904408                      /usr/lib/libc-2.22.so 34dddd3b000-34dddf3a000 ---p 0019b000 00:11 6904408                      /usr/lib/libc-2.22.so 34dddf3a000-34dddf3e000 r--p 0019a000 00:11 6904408                      /usr/lib/libc-2.22.so 34dddf3e000-34dddf40000 rw-p 0019e000 00:11 6904408                      /usr/lib/libc-2.22.so 34dddf40000-34dddf44000 rw-p 00000000 00:00 0  34dddf44000-34dddf66000 r-xp 00000000 00:11 6904407                      /usr/lib/ld-2.22.so 34dde119000-34dde11c000 rw-p 00000000 00:00 0  34dde13f000-34dde161000 rw-p 00000000 00:00 0  34dde161000-34dde163000 r--p 00000000 00:00 0                            [vvar] 34dde163000-34dde165000 r-xp 00000000 00:00 0                            [vdso] 34dde165000-34dde166000 r--p 00021000 00:11 6904407                      /usr/lib/ld-2.22.so 34dde166000-34dde167000 rw-p 00022000 00:11 6904407                      /usr/lib/ld-2.22.so 34dde167000-34dde168000 rw-p 00000000 00:00 0  3fd669db000-3fd669fd000 rw-p 00000000 00:00 0                            [stack] ffffffffff600000-ffffffffff601000 r--p 00000000 00:00 0                  [vsyscall] 

here second page belonging libc not readable program. if program tried pass argument write system call, not succeed , suspect what's happening in code.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -