Skip to content

POSIX on Windows with BSD sockets, pthreads, mqueue, mmap

Latest
Compare
Choose a tag to compare
@robinrowe robinrowe released this 29 Oct 06:19
· 160 commits to master since this release

The best version of this library is always master. If you need to lock to a version for QA purposes, you are better off choosing as library freeze point the latest commit tag, not libunistd's last version tag. Version tags are created as milestones, not as latest best releases. I use this library regularly to develop code on Windows that will be released on Linux (or FreeBSD or MacOS or Solaris). I make little, and not so little, improvements as needed to support my projects.

Version 1.2 has many POSIX API additions, pthread support, message queues, shared memory support and bug fixes.

IMPORTANT NOTE regarding mmap:

This is one case where I couldn't make the Windows API perfectly emulate the Linux calls. I had to make minor extensions to mmap API. An issue is Windows file handles are wider than int, so I use a std::map to store the actual Windows handle. This means my Windows mmap fd is not really a file descriptor and can't be used on system calls expecting an fd. In other words, you must call shm_close(fd) and not close(fd).

You also must call shm_flush(fd) because Windows won't immediately flush memory to a file using the shared memory file API. The shared memory pagefile API would do that, but Windows security restrictions block opening global shared memory from a normal user account. That Windows API works best from within a Windows service. Of course, for single codebase Linux, creating a Windows service would make no sense.

There is a tricky workaround to the global pagefile security issue, as noted in mmap.h. I might try it someday. However, it doesn't solve the fd behavior issue. Another approach might be to share memory from a dll, but that seems ugly too.

The best mmap solution would be for the C++ standards committee to define shared memory in the C++ language so we won't need a library call.