diff options
author | Andreas Kling <awesomekling@gmail.com> | 2020-01-08 12:33:36 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2020-01-08 12:47:37 +0100 |
commit | 50056d1d84f654043b8f4401135ec3ec08a3478c (patch) | |
tree | 84c13402b68b0e1b0117ba77fe17af7e4fa1b7ea /Userland | |
parent | 3f35cd2f7d9ca60188b3b057cdb2ba23f050d745 (diff) | |
download | serenity-50056d1d84f654043b8f4401135ec3ec08a3478c.zip |
Kernel: mmap() should fail with ENODEV for directories
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/test_io.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Userland/test_io.cpp b/Userland/test_io.cpp index dc8f1e7961..17fbb5e1f6 100644 --- a/Userland/test_io.cpp +++ b/Userland/test_io.cpp @@ -105,6 +105,22 @@ void test_ftruncate_negative() close(fd); } +void test_mmap_directory() +{ + int fd = open("/tmp", O_RDONLY | O_DIRECTORY); + ASSERT(fd >= 0); + auto* ptr = mmap(nullptr, 4096, PROT_READ, MAP_FILE | MAP_SHARED, fd, 0); + if (ptr != MAP_FAILED) { + fprintf(stderr, "Boo! mmap() of a directory succeeded!\n"); + return; + } + if (errno != ENODEV) { + fprintf(stderr, "Boo! mmap() of a directory gave errno=%d instead of ENODEV!\n", errno); + return; + } + close(fd); +} + int main(int, char**) { int rc; @@ -123,6 +139,7 @@ int main(int, char**) test_read_past_eof(); test_ftruncate_readonly(); test_ftruncate_negative(); + test_mmap_directory(); return 0; } |