SIGBUS while doing memcpy from mmap ed buffer which is in RAM as identified by mincore

寵の児 提交于 2020-02-02 09:59:16

问题


I am mmapping a block as:

mapAddr = mmap((void*) 0, curMapSize, PROT_NONE, MAP_LOCKED|MAP_SHARED, fd, curMapOffset);

if this does not fail (mapAddr != MAP_FAILED) I query mincore as:

err = mincore((char*) mapAddr, pageSize, &mincoreRet);

to find out whether it is in RAM. In case it is in RAM (err == 0 && mincoreRet & 0x01) I mmap it again for reading as:

copyAddr = mmap((void*) 0, curMapSize, PROT_READ, MAP_LOCKED|MAP_SHARED, fd, curMapOffset);

and then I try to copy it out to my buffer as:

memcpy(data, copyAddr, pageSize);

everything works fine except in the last memcpy once in a while I get SIGBUS. When I check /proc/ /smaps at the time of the failure I notice that it has Rss as well as Locked fields as 0 as listed below:

7f4a4c118000-7f4a4c119000 r--s 00326000 00:17 6                          <file name>

Size:                  4 kB

Rss:                   0 kB

Pss:                   0 kB

Shared_Clean:          0 kB

Shared_Dirty:          0 kB

Private_Clean:         0 kB

Private_Dirty:         0 kB

Referenced:            0 kB

Anonymous:             0 kB

AnonHugePages:         0 kB

Swap:                  0 kB

KernelPageSize:        4 kB

MMUPageSize:           4 kB

Locked:                0 kB

Any thoughts? This is happening on ubuntu 12.0.4 with kernel version 3.5.0-36.

来源:https://stackoverflow.com/questions/21230720/sigbus-while-doing-memcpy-from-mmap-ed-buffer-which-is-in-ram-as-identified-by-m

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!