{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/WSL/issues/902","repository_url":"https://api.github.com/repos/Microsoft/WSL","labels_url":"https://api.github.com/repos/Microsoft/WSL/issues/902/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/WSL/issues/902/comments","events_url":"https://api.github.com/repos/Microsoft/WSL/issues/902/events","html_url":"https://github.com/Microsoft/WSL/issues/902","id":171253500,"node_id":"MDU6SXNzdWUxNzEyNTM1MDA=","number":902,"title":"WSL: ftruncate does not truncate mmap'd files","user":{"login":"freeone3000","id":1736876,"node_id":"MDQ6VXNlcjE3MzY4NzY=","avatar_url":"https://avatars3.githubusercontent.com/u/1736876?v=4","gravatar_id":"","url":"https://api.github.com/users/freeone3000","html_url":"https://github.com/freeone3000","followers_url":"https://api.github.com/users/freeone3000/followers","following_url":"https://api.github.com/users/freeone3000/following{/other_user}","gists_url":"https://api.github.com/users/freeone3000/gists{/gist_id}","starred_url":"https://api.github.com/users/freeone3000/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/freeone3000/subscriptions","organizations_url":"https://api.github.com/users/freeone3000/orgs","repos_url":"https://api.github.com/users/freeone3000/repos","events_url":"https://api.github.com/users/freeone3000/events{/privacy}","received_events_url":"https://api.github.com/users/freeone3000/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2016-08-15T20:24:33Z","updated_at":"2018-08-08T20:30:03Z","closed_at":null,"author_association":"NONE","body":"Please use the following bug reporting template to help produce actionable and reproducible issues:\r\n- A brief description\r\n  ftruncate does not truncate mmap'd files while they are mmap'd.\r\n- Expected results\r\n  file gets truncated to desired size in bytes, even when mmap'd; SIGBUS occurs if memory outside new file bounds is accessed. (This is the behavior on Ubuntu.)\r\n- Actual results (with terminal output if applicable)\r\n  file does not get truncated\r\n- Your Windows build number\r\n  14393\r\n- Steps / commands required to reproduce the error\r\n```\r\n#include <sys/mman.h>\r\n#include <fcntl.h>\r\n#include <unistd.h>\r\n#include <stdlib.h>\r\n#include <stdio.h>\r\n#include <string.h>\r\n#include <errno.h>\r\n#define FAIL exit(errno);\r\n\r\nint main() {\r\n    /* prepare test data */\r\n    int buf_size = 8102;\r\n    char* buf = malloc(buf_size);\r\n    if(NULL == buf) {\r\n            FAIL\r\n    }\r\n    memset(buf, '?', buf_size);\r\n    int fd = open(\"test_buffer\", O_RDWR | O_CREAT);\r\n    if(fd < 0) {\r\n            FAIL\r\n    }\r\n\r\n    /* run test */\r\n    write(fd, buf, buf_size);\r\n    char* mm = mmap(NULL, buf_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);\r\n    if(MAP_FAILED == mm) {\r\n            FAIL\r\n    }\r\n    memset(mm, '!', buf_size);\r\n    int tres = ftruncate(fd, 16);\r\n    if(0 != tres) { /* okay, trying again later */\r\n            write(STDOUT_FILENO, \"NOFIRST\\n\", 9);\r\n            errno = 0;\r\n    }\r\n    int mures = munmap(mm, buf_size);\r\n    if(0 != mures) {\r\n            FAIL\r\n    }\r\n    tres = ftruncate(fd, 16);\r\n    if(0 != tres) {\r\n            write(STDOUT_FILENO, \"FAIL BOTH\\n\", 11);\r\n            exit(1);\r\n    }\r\n\r\n    write(STDOUT_FILENO, \"SUCCESS\\n\", 9);\r\n    close(fd);\r\n}\r\n```\r\n- Strace of the failing command\r\n\r\n```\r\n  `execve(\"./min_test.bin\", [\"./min_test.bin\"], [/* 23 vars */]) = 0\r\n  brk(0)                                  = 0x12ab000\r\n  access(\"/etc/ld.so.nohwcap\", F_OK)      = -1 ENOENT (No such file or directory)\r\n  mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f7c97540000\r\n  access(\"/etc/ld.so.preload\", R_OK)      = -1 ENOENT (No such file or directory)\r\n  open(\"/etc/ld.so.cache\", O_RDONLY|O_CLOEXEC) = 3\r\n  fstat(3, {st_mode=S_IFREG|0644, st_size=64852, ...}) = 0\r\n  mmap(NULL, 64852, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f7c97530000\r\n  close(3)                                = 0\r\n  access(\"/etc/ld.so.nohwcap\", F_OK)      = -1 ENOENT (No such file or directory)\r\n  open(\"/lib/x86_64-linux-gnu/libc.so.6\", O_RDONLY|O_CLOEXEC) = 3\r\n  read(3, \"\\177ELF\\2\\1\\1\\0\\0\\0\\0\\0\\0\\0\\0\\0\\3\\0>\\0\\1\\0\\0\\0P \\2\\0\\0\\0\\0\\0\"..., 832) = 832\r\n  fstat(3, {st_mode=S_IFREG|0755, st_size=1840928, ...}) = 0\r\n  mmap(NULL, 3949248, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f7c96e30000\r\n  mprotect(0x7f7c96fea000, 2097152, PROT_NONE) = 0\r\n  mmap(0x7f7c971ea000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1ba000) = 0x7f7c971ea000\r\n  mmap(0x7f7c971f0000, 17088, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f7c971f0000\r\n  close(3)                                = 0\r\n  mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f7c97520000\r\n  mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f7c97510000\r\n  arch_prctl(ARCH_SET_FS, 0x7f7c97510740) = 0\r\n  mprotect(0x7f7c971ea000, 16384, PROT_READ) = 0\r\n  mprotect(0x600000, 4096, PROT_READ)     = 0\r\n  mprotect(0x7f7c97422000, 4096, PROT_READ) = 0\r\n  munmap(0x7f7c97530000, 64852)           = 0\r\n  brk(0)                                  = 0x12ab000\r\n  brk(0x12cd000)                          = 0x12cd000\r\n  open(\"test_buffer\", O_RDWR|O_CREAT, 0112547600) = 3\r\n  write(3, \"????????????????????????????????\"..., 8102) = 8102\r\n  mmap(NULL, 8102, PROT_READ|PROT_WRITE, MAP_SHARED, 3, 0) = 0x7f7c9754b000\r\n  ftruncate(3, 16)                        = -1 EINVAL (Invalid argument)\r\n  write(1, \"NOFIRST\\n\\0\", 9)              = 9\r\n  munmap(0x7f7c9754b000, 8102)            = 0\r\n  ftruncate(3, 16)                        = 0\r\n  write(1, \"SUCCESS\\n\\0\", 9)              = 9\r\n  close(3)                                = 0\r\n  exit_group(0)                           = ?\r\n  +++ exited with 0 +++\r\n```\r\n- Required packages and commands to install\r\n  `apt-get -y install build-essential`\r\n\r\nSee [our contributing instructions](/CONTRIBUTING.md) for assistance.\r\n"},"comment":{"url":"https://api.github.com/repos/Microsoft/WSL/issues/comments/411541756","html_url":"https://github.com/Microsoft/WSL/issues/902#issuecomment-411541756","issue_url":"https://api.github.com/repos/Microsoft/WSL/issues/902","id":411541756,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMTU0MTc1Ng==","user":{"login":"yorickdowne","id":540651,"node_id":"MDQ6VXNlcjU0MDY1MQ==","avatar_url":"https://avatars2.githubusercontent.com/u/540651?v=4","gravatar_id":"","url":"https://api.github.com/users/yorickdowne","html_url":"https://github.com/yorickdowne","followers_url":"https://api.github.com/users/yorickdowne/followers","following_url":"https://api.github.com/users/yorickdowne/following{/other_user}","gists_url":"https://api.github.com/users/yorickdowne/gists{/gist_id}","starred_url":"https://api.github.com/users/yorickdowne/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yorickdowne/subscriptions","organizations_url":"https://api.github.com/users/yorickdowne/orgs","repos_url":"https://api.github.com/users/yorickdowne/repos","events_url":"https://api.github.com/users/yorickdowne/events{/privacy}","received_events_url":"https://api.github.com/users/yorickdowne/received_events","type":"User","site_admin":false},"created_at":"2018-08-08T20:30:03Z","updated_at":"2018-08-08T20:30:03Z","author_association":"NONE","body":"@therealkenc I'm unsure whether the lmdb issue belongs here or in #658. As the latter is closed, I copied the comment over here. lmdb is running into an mmap issue, either one of those two. Tested on 18204 and on the April Update."}}
{"actor":{"display_login":"yorickdowne"}}