[PATCH] D68455: [builtins][test] Avoid unportable mmap call in clear_cache_test.c

Rainer Orth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 4 03:53:43 PDT 2019


ro created this revision.
ro added reviewers: delcypher, howard.hinnant, samsonov.
Herald added subscribers: Sanitizers, fedor.sergeev, jyknight.
Herald added projects: LLVM, Sanitizers.

Within the last two weeks, the `Builtins-*-sunos :: clear_cache_test.c` started to FAIL
on Solaris.  Running it under truss shows

  mmap(0x00000000, 128, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANON, 0, 0) Err#22 EINVAL
  _exit(1)

While there are several possible reasons mmap can return EINVAL on Solaris, it turns
out it's this one (from mmap(2)):

  MAP_ANON  was  specified,  but the file descriptor was not
   -1.

And indeed even the Linux mmap(2) documents this as unportable:

  MAP_ANONYMOUS
          The mapping is not backed by any file; its contents are initial‐
          ized to zero.  The fd argument is ignored; however, some  imple‐
          mentations require fd to be -1 if MAP_ANONYMOUS (or MAP_ANON) is
          specified, and portable applications should  ensure  this.   The

This patch follows this advise.  Tested on `x86_64-pc-linux-gnu`, `amd64-pc-solaris2.11`
and `sparcv9-sun-solaris2.11`.  Ok for trunk?


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D68455

Files:
  test/builtins/Unit/clear_cache_test.c


Index: test/builtins/Unit/clear_cache_test.c
===================================================================
--- test/builtins/Unit/clear_cache_test.c
+++ test/builtins/Unit/clear_cache_test.c
@@ -48,7 +48,7 @@
 #if !defined(_WIN32)
     uint8_t *execution_buffer = mmap(0, kSize,
                                      PROT_READ | PROT_WRITE | PROT_EXEC,
-                                     MAP_ANON | MAP_PRIVATE, 0, 0);
+                                     MAP_ANON | MAP_PRIVATE, -1, 0);
     if (execution_buffer == MAP_FAILED)
       return 1;
 #else


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68455.223183.patch
Type: text/x-patch
Size: 563 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191004/4bcea545/attachment.bin>


More information about the llvm-commits mailing list