[PATCH] D35275: [Sanitizers] ASan/MSan/LSan allocators set errno on failure.

Aleksey Shlyapnikov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 14 11:40:48 PDT 2017


alekseyshl marked an inline comment as done.
alekseyshl added a comment.

In https://reviews.llvm.org/D35275#808959, @morehouse wrote:

> Test cases for EINVAL in the various *memalign and *aligned_alloc functions might be a good idea.


Yes, I have them on my TODO list, but, with the exception of Scudo, not all platforms implement them and I did not want to revert the entire patch because of those failing tests. Will add them later.



================
Comment at: lib/msan/msan_allocator.cc:269
+void *msan_aligned_alloc(uptr alignment, uptr size, StackTrace *stack) {
+  if (UNLIKELY(!IsPowerOfTwo(alignment) || (size & (alignment - 1)) != 0)) {
+    errno = errno_EINVAL;
----------------
vitalybuka wrote:
> morehouse wrote:
> > vitalybuka wrote:
> > > why not just (size % alignmet == 0) and ignore "power of two" check?
> > From memalign and aligned_alloc man page:
> > > The  obsolete  function  memalign()  allocates size bytes and returns a
> > > pointer to the allocated memory.  The memory address will be a multiple
> > > of alignment, which must be a power of two.
> > 
> > > The  function aligned_alloc() is the same as memalign(), except for the
> > > added restriction that size should be a multiple of alignment.
> power of two is posix specific requirement
> http://en.cppreference.com/w/c/memory/aligned_alloc
> 
> Anyway  (size & (alignment - 1)) != 0) can be replaced with simple (size % alignmet)
My man memalign says exactly as quoted earlier, the power of two requirement affects both memalign and aligned_alloc.




https://reviews.llvm.org/D35275





More information about the llvm-commits mailing list