Skip to content

FreeBSD compatibility...  #110

@oschonrock

Description

@oschonrock

Is FreeBSD supported?

The following code snippet leads to a segfault on FreeBSD 14, but works fine on Linux (Ubuntu 24.04 or on Windows/mingw) :

#include "mio/mmap.hpp"                                                                                                                                                                                                                                       
#include <iostream>                                                                                                                                                                                                                                           
#include <system_error>                                                                                                                                                                                                                                       
                                                                                                                                                                                                                                                              
int main() {                                                                                                                                                                                                                                                  
  std::error_code err;                                                                                                                                                                                                                                        
  mio::mmap_sink mmap;                                                                                                                                                                                                                                        
  mmap.map("test/tmp/sharded_filter8.bin", err);                                                                                                                                                                                                              
  if (err) std::cerr << err.message() << "\n";                                                                                                                                                                                                                
  std::string tag(15, '\0');                                                                                                                                                                                                                                  
  memcpy(tag.data(), mmap.data(), 15);                                                                                                                                                                                                                        
  std::cout << "'" << tag << "'\n";                                                                                                                                                                                                                                                                                                                                                                                                                                              
}  
precise error (obtained with valgrind): 
==3608== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==3608==  Bad permissions for mapped region at address 0x4841000
==3608==    at 0x203092: main (app/test_mio.cpp:11)     // line 11 is the memcpy

I am using mio::access_mode::write because in the original code it is writing and and then reading. If I change it to mmap_source it works fine.

I definitely have read and write permissions to the file, and an earlier instance of mmap_sink could write to the file.
I single stepped through the code, and is correctly opening the file with O_RDWR and passing PROT_WRITE to the ::mmap call.

If I change mmap.ipp:L208 to always pass PROT_READ, it works fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions