int the last blog ,if i modify the code as
start=mmap((void*)0xbcde6600,buf.st_size, PROT_READ|PROT_WRITE,MAP_PRIVATE,fd,1);
the last argument now is changed into 1 from 0----------indicates that i want mapping the file from the second byts,----but it's not impossible
run it
[root@localhost mmap]# ./3 text1
mmap success p=ffffffff
start= ffffffff
Segmentation fault
segment fault occurs again!
it seems to be more serious than the last example as the address is fffffff
so i modify again as
start=mmap((void*)0xbcde6600,buf.st_size, PROT_READ|PROT_WRITE,MAP_PRIVATE,fd,4096);
run it
[root@localhost mmap]# ./3 text1
mmap success p=bcde6000
start= bcde6000
start=
now it is ok ,but the text1 is 4097KB in size----no string to disply
so type some characters at the end of text1 file as "this is the end of text1"
-rw-r--r-- 1 root root 4122 2011-07-07 04:53 text1
you know,4122>4096
run it again
[root@localhost mmap]# ./4 text3
open file error /n[root@localhost mmap]# ./4 text1
mmap ok.p=b7f67000
buf=
this is the end of text1
it's ok
we can come to a conclusion from the text above
the file is divided into sevral parts(likes pages in vertue memory ) by os and every part is also 4KB.
the memory page shoud be aligned with the file part
so we must map the file from one part ,such as 0,4096....,not 1 or 2
ok,now let's make another error just modify the code
start=mmap((void*)0xbcde6600,buf.st_size, PROT_READ|PROT_WRITE,MAP_PRIVATE,fd,8192);
the last argument now is changed into 8192 from 4096,it's following the alinged rule,but the erro comes after runing
[root@localhost mmap]# ./3 text1
mmap success p=bcde6000
start= bcde6000
Bus error
[root@localhost mmap]#
bus error,
see the size of file text1
-rw-r--r-- 1 root root 4122 2011-07-07 04:53 text1
4122Bytes totally,
the part starts from 8192 beyond 4122