I am getting a segfault when accessing shared memory (memory mapped file, using a fixed address of 0x60000000 ) from within a share object (.so).
当从共享对象(.so)中访问共享内存(内存映射文件,使用固定地址0x60000000)时,我得到一个段错误。
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.
我们有很多应用程序毫无困难地访问此共享内存。我的应用程序不同之处在于我用它创建一个小的.so而.so是调用mmap并访问共享内存的.so。
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.
mmap()返回正常。我要求的地址已正确退回。但是一旦我尝试从这个.so中访问内存,就会出现故障。
I can't figure out what is unique about a .so that would prevent it from accessing shared memory this way.
我无法弄清楚.so的独特之处在于它会阻止它以这种方式访问共享内存。
Anyone have thoughts?
有人有想法吗?
1 个解决方案
#1
2
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:
通常,从共享库访问mmaped内存与从主可执行文件访问mmaped内存完全不同,并且你可能正在咆哮错误的树。那说,这个:
memory mapped file, using a fixed address of
0x60000000
内存映射文件,使用固定地址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.
通常是一个非常糟糕的主意,因为你无法控制以前曾在那里做过什么(如果有的话)。 MAP_FIXED映射将简单地删除任何先前存在的映射。如果您的库本身恰好映射到那里,那么您将替换库.text或.data,结果几乎肯定是一个神秘的崩溃。
#1
2
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:
通常,从共享库访问mmaped内存与从主可执行文件访问mmaped内存完全不同,并且你可能正在咆哮错误的树。那说,这个:
memory mapped file, using a fixed address of
0x60000000
内存映射文件,使用固定地址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.
通常是一个非常糟糕的主意,因为你无法控制以前曾在那里做过什么(如果有的话)。 MAP_FIXED映射将简单地删除任何先前存在的映射。如果您的库本身恰好映射到那里,那么您将替换库.text或.data,结果几乎肯定是一个神秘的崩溃。