I have a very simple class that opens a file and creates a memory mapped file.
The region is mapped to the member variable called data_ which is defined as unsigned char* data_;
The memory map part looks like this:
// Create memory mapped file
unsigned char* data_ = (unsigned char*)mmap(NULL, 1024,
PROT_READ | PROT_WRITE, MAP_SHARED, fd_, 0);
if (block_data_ == MAP_FAILED) {
throw Exception(std::string("mmap: ") + strerror(errno));
}
Now I can read and write to the file by simply writing to the data_ variable (up to the size 1024.
But, the intention is not to do it this way. I have a function that returns me a pointer to data_.
When I simply create the block it works fine all the way up until I try to write to the data OUTSIDE of the class. That's when I get a SIGSEGV.
How do I get around that?