Fix fallout from the merge.
- CI merge issues:
- The malloc shim libraries are renamed.
- CMake gets very unhappy if you don't enable the C language and
tries to link with the C compiler instead of the C++ compiler if
you do enable it.
- The Ubuntu packages for QEMU install a `binfmt_misc` activator for
PowerPC64 little-endian, but set the page size to 4 KiB. We then
tried to run the tests (which expect 64 KiB pages) and became very
confused when `mmap` returned 4 KiB-aligned memory.
- Test failures:
- Fix all of the issues UBsan found.
- Underflow in `pointer_offset` when used to add negative offsets.
- `CoreAlloc`'s `LocalState` accessed on a null `CoreAlloc` pointer.
- Out of bounds access in the sizeclass list on attempts to access
more memory than fits in the VA space.
-
- There was an integer overflow in `AddressSpace` that could cause it
to try to allocate a zero-sized object, get a null pointer, and
then try to do something with 0 - {size of the real allocation}.
- The malloc tests weren't setting `errno` to 0 before doing
calling `malloc`, which should set `errno` on failure, and then
checking that `errno` was 0.
- Don't call `PAL::error` on PAL allocation failure, return `nullptr`.
The PALs were inconsistent about that and the new code expects to be
able to report address-space exhaustion.
- The malloc checks can behave differently with 0-sized allocations
on different platforms but were very fragile about their
expectations.
- The malloc test didn't report failure for all of the ways that it
could fail and so was spuriously passing on some platforms.
- The perf test for external pointer is currently very slow on
Windows. The number of loops have been reduced and a timeout added
for the Windows CI runs.
- The logic to capture `errno` across calls was using
`decltype(errno)`, which on some platforms where `errno` is a macro
evaluated to `int&` and so they captured a reference rather than
the value and failed to reset `errno`.
- The Apple PAL can set `errno` on `notify_using` if it's called with
memory that was not previously passed to `notify_not_using` but was
not adequately protected against this and so would sometimes cause
`malloc` to set `errno` to `EINVAL`.
This commit is contained in:
@@ -160,6 +160,7 @@ namespace snmalloc
|
||||
template<ZeroMem zero_mem>
|
||||
static void notify_using(void* p, size_t size) noexcept
|
||||
{
|
||||
KeepErrno e;
|
||||
SNMALLOC_ASSERT(
|
||||
is_aligned_block<page_size>(p, size) || (zero_mem == NoZero));
|
||||
|
||||
@@ -239,7 +240,7 @@ namespace snmalloc
|
||||
|
||||
if (unlikely(kr != KERN_SUCCESS))
|
||||
{
|
||||
error("Failed to allocate memory\n");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return reinterpret_cast<void*>(addr);
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace snmalloc
|
||||
0);
|
||||
|
||||
if (p == MAP_FAILED)
|
||||
PALBSD<OS>::error("Out of memory");
|
||||
return nullptr;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -99,12 +99,13 @@ namespace snmalloc
|
||||
static const int fd = T::anonymous_memory_fd;
|
||||
};
|
||||
|
||||
protected:
|
||||
/**
|
||||
* A RAII class to capture and restore errno
|
||||
*/
|
||||
class KeepErrno
|
||||
{
|
||||
decltype(errno) cached_errno;
|
||||
int cached_errno;
|
||||
|
||||
public:
|
||||
KeepErrno() : cached_errno(errno) {}
|
||||
|
||||
@@ -177,10 +177,6 @@ namespace snmalloc
|
||||
|
||||
void* ret = VirtualAlloc2FromApp(
|
||||
nullptr, nullptr, size, flags, PAGE_READWRITE, ¶m, 1);
|
||||
if (ret == nullptr)
|
||||
{
|
||||
error("Failed to allocate memory\n");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
# endif
|
||||
|
||||
Reference in New Issue
Block a user