I found out that the cause for the error was that I was using Ubuntu Linux in a VM (Parallels) when running the code on my native system everything worked fine. Seems that Parallels doesn't implement this kind of memory modifications in it's filesystem drivers...
This question helped me a lot: Invalid argument for read-write mmap?