WSL: mmap(NULL, ...) on zero-length file fails with ENOEXEC
- Your Windows build number: (Type
verat a Windows Command Prompt)
April Update, 10.0.17134.191 Also tested on 19H1, build 18204
- What you’re doing and what’s happening: (Copy&paste specific commands and their output, or include screen shots)
The package “liblmdb” does not work on WSL. This impacts any projects that use lmdb. I’ve narrowed this down to mmap(NULL,…) on a 0-length file failing with ENOEXEC. This is likely related to #658 , yet distinct enough that the @therealkenc suggested I file a new issue, to avoid confusion.
To reproduce with lmdb:
git clone https://github.com/LMDB/lmdb.git cd lmdb/libraries/liblmdb make test
mtest.c:50: mdb_env_open(env, “./testdb”, MDB_FIXEDMAP , 0664): Exec format error Aborted (core dumped) Makefile:61: recipe for target ‘test’ failed make: *** [test] Error 134
strace shows:
mmap(NULL, 10485760, PROT_READ, MAP_SHARED, 4, 0) = -1 ENOEXEC (Exec format error)
Just before it cores.
Sample code showing just the ENOEXEC, but not going on long enough after that to core:
#include <stddef.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
int main (void) {
void *map;
int fd;
// mmap an empty file, fails with ENOEXEC
// Test case to recreate an issue with lmdb and WSL
// mmap(NULL, 10485760, PROT_READ, MAP_SHARED, 4, 0) = -1 ENOEXEC (Exec format error)
remove("./testfile");
fd = open("./testfile", O_RDWR | O_CREAT, 0664);
map = mmap(NULL, 1024, PROT_READ, MAP_SHARED, fd, 0);
if (map == MAP_FAILED)
printf("mmap(NULL,...) of empty file failed, strace shows ENOEXEC\n");
else {
printf("mmap(NULL,...) of empty file succeeded, issue fixed\n");
munmap(map, 1024);
}
close(fd);
remove("./testfile");
// By contrast, with a file that contains some data
fd = open("./testfile", O_RDWR | O_CREAT, 0664);
write(fd,"Content",7);
map = mmap(NULL, 1024, PROT_READ, MAP_SHARED, fd, 0);
if (map == MAP_FAILED)
printf("mmap(NULL,...) of non-empty file failed, that's unexpected\n");
else {
printf("mmap(NULL,...) of non-empty file succeeded, as expected\n");
munmap(map, 1024);
}
close(fd);
remove("./testfile");
return 0;
}
- Strace of the failing command, if applicable:
strace of the sample code: mmap-example.strace.txt
strace of liblmdb itself: liblmdb.strace.txt
User voice for this issue lives here: https://wpdev.uservoice.com/forums/266908-command-prompt-console-windows-subsystem-for-l/suggestions/35053207-support-oracle-berkeley-db-and-lmdb
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 16
- Comments: 19 (3 by maintainers)
The major use case for “mmap’s problems” is BerkeleyDB. Instead of deep diving
lmdb(orboltdb#2304 #3162 orfoo-db) you may consider:There is some information on running the individual tests here. If you get the BerkeleyDB tests to pass it will squash #3149 #2627 #2852 #2871 (and everything else in the BDB universe). The other
foo-dbwill almost certainly follow suit.This issue has been automatically closed since it has not had any activity for the past year. If you’re still experiencing this issue please re-file this as a new issue or feature request.
Thank you!