简体   繁体   中英

Using memory-mapped files from within a .so (shared object)

I am getting a segfault when accessing shared memory (memory mapped file, using a fixed address of 0x60000000 ) from within a share object (.so).

We have many applications accessing this shared memory without difficulty. My app is different in that I create a small .so with it and the .so is the one calling mmap and accessing the shared memory.

The mmap() returns just fine. My requested address is returned back properly. But as soon as I try to access the memory from within this .so, it seg faults.

I can't figure out what is unique about a .so that would prevent it from accessing shared memory this way.

Anyone have thoughts?

In general, accessing mmap ed memory from a shared library is in no way different from accessing it from a main executable, and you are likely barking up the wrong tree. That said, this:

memory mapped file, using a fixed address of 0x60000000

is generally a very bad idea , because you have no control over what (if anything) was mmap ed there before. A MAP_FIXED mapping will simply remove any previous mapping that existed. If your library itself happens to be mapped there, then you'll replace the library .text , or .data , and the result is almost certain to be a mysterious crash.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM