[scudo][standalone] Introduce the C & C++ wrappers [fixed]
Summary:
This is a redo of D63612.
Two problems came up on some bots:
- `__builtin_umull_overflow` was not declared. This is likely due to an
older clang or gcc, so add a guard with `__has_builtin` and fallback
to a division in the event the builtin doesn't exist;
- contradicting definition for `malloc`, etc. This is AFAIU due to the
fact that we ended up transitively including `stdlib.h` in the `.inc`
due to it being the flags parser header: so move the include to the
cc instead.
This should fix the issues, but since those didn't come up in my local
tests it's mostly guesswork.
Rest is the same!
Reviewers: morehouse, hctim, eugenis, vitalybuka, dyung, hans
Reviewed By: morehouse, dyung, hans
Subscribers: srhines, mgorny, delcypher, jfb, #sanitizers, llvm-commits
Tags: #llvm, #sanitizers
Differential Revision: https://reviews.llvm.org/D63831
llvm-svn: 364547
2019-06-27 22:23:26 +08:00
|
|
|
//===-- wrappers_c.inc ------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef SCUDO_PREFIX
|
|
|
|
#error "Define SCUDO_PREFIX prior to including this file!"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// malloc-type functions have to be aligned to std::max_align_t. This is
|
|
|
|
// distinct from (1U << SCUDO_MIN_ALIGNMENT_LOG), since C++ new-type functions
|
|
|
|
// do not have to abide by the same requirement.
|
|
|
|
#ifndef SCUDO_MALLOC_ALIGNMENT
|
|
|
|
#define SCUDO_MALLOC_ALIGNMENT FIRST_32_SECOND_64(8U, 16U)
|
|
|
|
#endif
|
|
|
|
|
2020-01-10 03:43:16 +08:00
|
|
|
extern "C" {
|
|
|
|
|
[scudo][standalone] Introduce the C & C++ wrappers [fixed]
Summary:
This is a redo of D63612.
Two problems came up on some bots:
- `__builtin_umull_overflow` was not declared. This is likely due to an
older clang or gcc, so add a guard with `__has_builtin` and fallback
to a division in the event the builtin doesn't exist;
- contradicting definition for `malloc`, etc. This is AFAIU due to the
fact that we ended up transitively including `stdlib.h` in the `.inc`
due to it being the flags parser header: so move the include to the
cc instead.
This should fix the issues, but since those didn't come up in my local
tests it's mostly guesswork.
Rest is the same!
Reviewers: morehouse, hctim, eugenis, vitalybuka, dyung, hans
Reviewed By: morehouse, dyung, hans
Subscribers: srhines, mgorny, delcypher, jfb, #sanitizers, llvm-commits
Tags: #llvm, #sanitizers
Differential Revision: https://reviews.llvm.org/D63831
llvm-svn: 364547
2019-06-27 22:23:26 +08:00
|
|
|
INTERFACE WEAK void *SCUDO_PREFIX(calloc)(size_t nmemb, size_t size) {
|
|
|
|
scudo::uptr Product;
|
|
|
|
if (UNLIKELY(scudo::checkForCallocOverflow(size, nmemb, &Product))) {
|
|
|
|
if (SCUDO_ALLOCATOR.canReturnNull()) {
|
|
|
|
errno = ENOMEM;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
scudo::reportCallocOverflow(nmemb, size);
|
|
|
|
}
|
|
|
|
return scudo::setErrnoOnNull(SCUDO_ALLOCATOR.allocate(
|
|
|
|
Product, scudo::Chunk::Origin::Malloc, SCUDO_MALLOC_ALIGNMENT, true));
|
|
|
|
}
|
|
|
|
|
|
|
|
INTERFACE WEAK void SCUDO_PREFIX(free)(void *ptr) {
|
|
|
|
SCUDO_ALLOCATOR.deallocate(ptr, scudo::Chunk::Origin::Malloc);
|
|
|
|
}
|
|
|
|
|
|
|
|
INTERFACE WEAK struct SCUDO_MALLINFO SCUDO_PREFIX(mallinfo)(void) {
|
|
|
|
struct SCUDO_MALLINFO Info = {};
|
|
|
|
scudo::StatCounters Stats;
|
|
|
|
SCUDO_ALLOCATOR.getStats(Stats);
|
[scudo][standalone] Add more stats to mallinfo
Summary:
Android requires additional stats in mallinfo. While we can provide
right away the number of bytes mapped (Primary+Secondary), there was
no way to get the number of free bytes (only makes sense for the
Primary since the Secondary unmaps everything on deallocation).
An approximation could be `StatMapped - StatAllocated`, but since we
are mapping in `1<<17` increments for the 64-bit Primary, it's fairly
inaccurate.
So we introduce `StatFree` (note it's `Free`, not `Freed`!), which
keeps track of the amount of Primary blocks currently unallocated.
Reviewers: cferris, eugenis, vitalybuka, hctim, morehouse
Reviewed By: morehouse
Subscribers: delcypher, #sanitizers, llvm-commits
Tags: #llvm, #sanitizers
Differential Revision: https://reviews.llvm.org/D66112
llvm-svn: 368866
2019-08-15 00:04:01 +08:00
|
|
|
// Space allocated in mmapped regions (bytes)
|
|
|
|
Info.hblkhd = static_cast<__scudo_mallinfo_data_t>(Stats[scudo::StatMapped]);
|
|
|
|
// Maximum total allocated space (bytes)
|
|
|
|
Info.usmblks = Info.hblkhd;
|
|
|
|
// Space in freed fastbin blocks (bytes)
|
|
|
|
Info.fsmblks = static_cast<__scudo_mallinfo_data_t>(Stats[scudo::StatFree]);
|
|
|
|
// Total allocated space (bytes)
|
[scudo][standalone] Introduce the C & C++ wrappers [fixed]
Summary:
This is a redo of D63612.
Two problems came up on some bots:
- `__builtin_umull_overflow` was not declared. This is likely due to an
older clang or gcc, so add a guard with `__has_builtin` and fallback
to a division in the event the builtin doesn't exist;
- contradicting definition for `malloc`, etc. This is AFAIU due to the
fact that we ended up transitively including `stdlib.h` in the `.inc`
due to it being the flags parser header: so move the include to the
cc instead.
This should fix the issues, but since those didn't come up in my local
tests it's mostly guesswork.
Rest is the same!
Reviewers: morehouse, hctim, eugenis, vitalybuka, dyung, hans
Reviewed By: morehouse, dyung, hans
Subscribers: srhines, mgorny, delcypher, jfb, #sanitizers, llvm-commits
Tags: #llvm, #sanitizers
Differential Revision: https://reviews.llvm.org/D63831
llvm-svn: 364547
2019-06-27 22:23:26 +08:00
|
|
|
Info.uordblks =
|
|
|
|
static_cast<__scudo_mallinfo_data_t>(Stats[scudo::StatAllocated]);
|
[scudo][standalone] Add more stats to mallinfo
Summary:
Android requires additional stats in mallinfo. While we can provide
right away the number of bytes mapped (Primary+Secondary), there was
no way to get the number of free bytes (only makes sense for the
Primary since the Secondary unmaps everything on deallocation).
An approximation could be `StatMapped - StatAllocated`, but since we
are mapping in `1<<17` increments for the 64-bit Primary, it's fairly
inaccurate.
So we introduce `StatFree` (note it's `Free`, not `Freed`!), which
keeps track of the amount of Primary blocks currently unallocated.
Reviewers: cferris, eugenis, vitalybuka, hctim, morehouse
Reviewed By: morehouse
Subscribers: delcypher, #sanitizers, llvm-commits
Tags: #llvm, #sanitizers
Differential Revision: https://reviews.llvm.org/D66112
llvm-svn: 368866
2019-08-15 00:04:01 +08:00
|
|
|
// Total free space (bytes)
|
|
|
|
Info.fordblks = Info.fsmblks;
|
[scudo][standalone] Introduce the C & C++ wrappers [fixed]
Summary:
This is a redo of D63612.
Two problems came up on some bots:
- `__builtin_umull_overflow` was not declared. This is likely due to an
older clang or gcc, so add a guard with `__has_builtin` and fallback
to a division in the event the builtin doesn't exist;
- contradicting definition for `malloc`, etc. This is AFAIU due to the
fact that we ended up transitively including `stdlib.h` in the `.inc`
due to it being the flags parser header: so move the include to the
cc instead.
This should fix the issues, but since those didn't come up in my local
tests it's mostly guesswork.
Rest is the same!
Reviewers: morehouse, hctim, eugenis, vitalybuka, dyung, hans
Reviewed By: morehouse, dyung, hans
Subscribers: srhines, mgorny, delcypher, jfb, #sanitizers, llvm-commits
Tags: #llvm, #sanitizers
Differential Revision: https://reviews.llvm.org/D63831
llvm-svn: 364547
2019-06-27 22:23:26 +08:00
|
|
|
return Info;
|
|
|
|
}
|
|
|
|
|
|
|
|
INTERFACE WEAK void *SCUDO_PREFIX(malloc)(size_t size) {
|
|
|
|
return scudo::setErrnoOnNull(SCUDO_ALLOCATOR.allocate(
|
|
|
|
size, scudo::Chunk::Origin::Malloc, SCUDO_MALLOC_ALIGNMENT));
|
|
|
|
}
|
|
|
|
|
|
|
|
#if SCUDO_ANDROID
|
|
|
|
INTERFACE WEAK size_t SCUDO_PREFIX(malloc_usable_size)(const void *ptr) {
|
|
|
|
#else
|
|
|
|
INTERFACE WEAK size_t SCUDO_PREFIX(malloc_usable_size)(void *ptr) {
|
|
|
|
#endif
|
|
|
|
return SCUDO_ALLOCATOR.getUsableSize(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
INTERFACE WEAK void *SCUDO_PREFIX(memalign)(size_t alignment, size_t size) {
|
|
|
|
// Android rounds up the alignment to a power of two if it isn't one.
|
|
|
|
if (SCUDO_ANDROID) {
|
|
|
|
if (UNLIKELY(!alignment)) {
|
|
|
|
alignment = 1U;
|
|
|
|
} else {
|
|
|
|
if (UNLIKELY(!scudo::isPowerOfTwo(alignment)))
|
|
|
|
alignment = scudo::roundUpToPowerOfTwo(alignment);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (UNLIKELY(!scudo::isPowerOfTwo(alignment))) {
|
|
|
|
if (SCUDO_ALLOCATOR.canReturnNull()) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
scudo::reportAlignmentNotPowerOfTwo(alignment);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return SCUDO_ALLOCATOR.allocate(size, scudo::Chunk::Origin::Memalign,
|
|
|
|
alignment);
|
|
|
|
}
|
|
|
|
|
|
|
|
INTERFACE WEAK int SCUDO_PREFIX(posix_memalign)(void **memptr, size_t alignment,
|
|
|
|
size_t size) {
|
|
|
|
if (UNLIKELY(scudo::checkPosixMemalignAlignment(alignment))) {
|
|
|
|
if (!SCUDO_ALLOCATOR.canReturnNull())
|
|
|
|
scudo::reportInvalidPosixMemalignAlignment(alignment);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
void *Ptr =
|
|
|
|
SCUDO_ALLOCATOR.allocate(size, scudo::Chunk::Origin::Memalign, alignment);
|
|
|
|
if (UNLIKELY(!Ptr))
|
|
|
|
return ENOMEM;
|
|
|
|
*memptr = Ptr;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
INTERFACE WEAK void *SCUDO_PREFIX(pvalloc)(size_t size) {
|
|
|
|
const scudo::uptr PageSize = scudo::getPageSizeCached();
|
|
|
|
if (UNLIKELY(scudo::checkForPvallocOverflow(size, PageSize))) {
|
|
|
|
if (SCUDO_ALLOCATOR.canReturnNull()) {
|
|
|
|
errno = ENOMEM;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
scudo::reportPvallocOverflow(size);
|
|
|
|
}
|
|
|
|
// pvalloc(0) should allocate one page.
|
|
|
|
return scudo::setErrnoOnNull(SCUDO_ALLOCATOR.allocate(
|
|
|
|
size ? scudo::roundUpTo(size, PageSize) : PageSize,
|
|
|
|
scudo::Chunk::Origin::Memalign, PageSize));
|
|
|
|
}
|
|
|
|
|
|
|
|
INTERFACE WEAK void *SCUDO_PREFIX(realloc)(void *ptr, size_t size) {
|
|
|
|
if (!ptr)
|
|
|
|
return scudo::setErrnoOnNull(SCUDO_ALLOCATOR.allocate(
|
|
|
|
size, scudo::Chunk::Origin::Malloc, SCUDO_MALLOC_ALIGNMENT));
|
|
|
|
if (size == 0) {
|
|
|
|
SCUDO_ALLOCATOR.deallocate(ptr, scudo::Chunk::Origin::Malloc);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return scudo::setErrnoOnNull(
|
|
|
|
SCUDO_ALLOCATOR.reallocate(ptr, size, SCUDO_MALLOC_ALIGNMENT));
|
|
|
|
}
|
|
|
|
|
|
|
|
INTERFACE WEAK void *SCUDO_PREFIX(valloc)(size_t size) {
|
|
|
|
return scudo::setErrnoOnNull(SCUDO_ALLOCATOR.allocate(
|
|
|
|
size, scudo::Chunk::Origin::Memalign, scudo::getPageSizeCached()));
|
|
|
|
}
|
|
|
|
|
2019-11-12 01:30:17 +08:00
|
|
|
INTERFACE WEAK int SCUDO_PREFIX(malloc_iterate)(
|
[scudo][standalone] Introduce the C & C++ wrappers [fixed]
Summary:
This is a redo of D63612.
Two problems came up on some bots:
- `__builtin_umull_overflow` was not declared. This is likely due to an
older clang or gcc, so add a guard with `__has_builtin` and fallback
to a division in the event the builtin doesn't exist;
- contradicting definition for `malloc`, etc. This is AFAIU due to the
fact that we ended up transitively including `stdlib.h` in the `.inc`
due to it being the flags parser header: so move the include to the
cc instead.
This should fix the issues, but since those didn't come up in my local
tests it's mostly guesswork.
Rest is the same!
Reviewers: morehouse, hctim, eugenis, vitalybuka, dyung, hans
Reviewed By: morehouse, dyung, hans
Subscribers: srhines, mgorny, delcypher, jfb, #sanitizers, llvm-commits
Tags: #llvm, #sanitizers
Differential Revision: https://reviews.llvm.org/D63831
llvm-svn: 364547
2019-06-27 22:23:26 +08:00
|
|
|
uintptr_t base, size_t size,
|
|
|
|
void (*callback)(uintptr_t base, size_t size, void *arg), void *arg) {
|
|
|
|
SCUDO_ALLOCATOR.iterateOverChunks(base, size, callback, arg);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-10 03:43:16 +08:00
|
|
|
INTERFACE WEAK void SCUDO_PREFIX(malloc_enable)() { SCUDO_ALLOCATOR.enable(); }
|
|
|
|
|
[scudo][standalone] Introduce the C & C++ wrappers [fixed]
Summary:
This is a redo of D63612.
Two problems came up on some bots:
- `__builtin_umull_overflow` was not declared. This is likely due to an
older clang or gcc, so add a guard with `__has_builtin` and fallback
to a division in the event the builtin doesn't exist;
- contradicting definition for `malloc`, etc. This is AFAIU due to the
fact that we ended up transitively including `stdlib.h` in the `.inc`
due to it being the flags parser header: so move the include to the
cc instead.
This should fix the issues, but since those didn't come up in my local
tests it's mostly guesswork.
Rest is the same!
Reviewers: morehouse, hctim, eugenis, vitalybuka, dyung, hans
Reviewed By: morehouse, dyung, hans
Subscribers: srhines, mgorny, delcypher, jfb, #sanitizers, llvm-commits
Tags: #llvm, #sanitizers
Differential Revision: https://reviews.llvm.org/D63831
llvm-svn: 364547
2019-06-27 22:23:26 +08:00
|
|
|
INTERFACE WEAK void SCUDO_PREFIX(malloc_disable)() {
|
|
|
|
SCUDO_ALLOCATOR.disable();
|
|
|
|
}
|
|
|
|
|
2020-01-10 03:43:16 +08:00
|
|
|
void SCUDO_PREFIX(malloc_postinit)() {
|
2020-01-11 08:01:01 +08:00
|
|
|
SCUDO_ALLOCATOR.initGwpAsan();
|
2020-01-10 03:43:16 +08:00
|
|
|
pthread_atfork(SCUDO_PREFIX(malloc_disable), SCUDO_PREFIX(malloc_enable),
|
|
|
|
SCUDO_PREFIX(malloc_enable));
|
|
|
|
}
|
[scudo][standalone] Introduce the C & C++ wrappers [fixed]
Summary:
This is a redo of D63612.
Two problems came up on some bots:
- `__builtin_umull_overflow` was not declared. This is likely due to an
older clang or gcc, so add a guard with `__has_builtin` and fallback
to a division in the event the builtin doesn't exist;
- contradicting definition for `malloc`, etc. This is AFAIU due to the
fact that we ended up transitively including `stdlib.h` in the `.inc`
due to it being the flags parser header: so move the include to the
cc instead.
This should fix the issues, but since those didn't come up in my local
tests it's mostly guesswork.
Rest is the same!
Reviewers: morehouse, hctim, eugenis, vitalybuka, dyung, hans
Reviewed By: morehouse, dyung, hans
Subscribers: srhines, mgorny, delcypher, jfb, #sanitizers, llvm-commits
Tags: #llvm, #sanitizers
Differential Revision: https://reviews.llvm.org/D63831
llvm-svn: 364547
2019-06-27 22:23:26 +08:00
|
|
|
|
2020-07-29 07:25:49 +08:00
|
|
|
INTERFACE WEAK int SCUDO_PREFIX(mallopt)(int param, int value) {
|
[scudo][standalone] Introduce the C & C++ wrappers [fixed]
Summary:
This is a redo of D63612.
Two problems came up on some bots:
- `__builtin_umull_overflow` was not declared. This is likely due to an
older clang or gcc, so add a guard with `__has_builtin` and fallback
to a division in the event the builtin doesn't exist;
- contradicting definition for `malloc`, etc. This is AFAIU due to the
fact that we ended up transitively including `stdlib.h` in the `.inc`
due to it being the flags parser header: so move the include to the
cc instead.
This should fix the issues, but since those didn't come up in my local
tests it's mostly guesswork.
Rest is the same!
Reviewers: morehouse, hctim, eugenis, vitalybuka, dyung, hans
Reviewed By: morehouse, dyung, hans
Subscribers: srhines, mgorny, delcypher, jfb, #sanitizers, llvm-commits
Tags: #llvm, #sanitizers
Differential Revision: https://reviews.llvm.org/D63831
llvm-svn: 364547
2019-06-27 22:23:26 +08:00
|
|
|
if (param == M_DECAY_TIME) {
|
2020-02-15 04:24:03 +08:00
|
|
|
if (SCUDO_ANDROID) {
|
|
|
|
if (value == 0) {
|
|
|
|
// Will set the release values to their minimum values.
|
|
|
|
value = INT32_MIN;
|
|
|
|
} else {
|
|
|
|
// Will set the release values to their maximum values.
|
|
|
|
value = INT32_MAX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SCUDO_ALLOCATOR.setOption(scudo::Option::ReleaseInterval,
|
|
|
|
static_cast<scudo::sptr>(value));
|
[scudo][standalone] Introduce the C & C++ wrappers [fixed]
Summary:
This is a redo of D63612.
Two problems came up on some bots:
- `__builtin_umull_overflow` was not declared. This is likely due to an
older clang or gcc, so add a guard with `__has_builtin` and fallback
to a division in the event the builtin doesn't exist;
- contradicting definition for `malloc`, etc. This is AFAIU due to the
fact that we ended up transitively including `stdlib.h` in the `.inc`
due to it being the flags parser header: so move the include to the
cc instead.
This should fix the issues, but since those didn't come up in my local
tests it's mostly guesswork.
Rest is the same!
Reviewers: morehouse, hctim, eugenis, vitalybuka, dyung, hans
Reviewed By: morehouse, dyung, hans
Subscribers: srhines, mgorny, delcypher, jfb, #sanitizers, llvm-commits
Tags: #llvm, #sanitizers
Differential Revision: https://reviews.llvm.org/D63831
llvm-svn: 364547
2019-06-27 22:23:26 +08:00
|
|
|
return 1;
|
|
|
|
} else if (param == M_PURGE) {
|
|
|
|
SCUDO_ALLOCATOR.releaseToOS();
|
|
|
|
return 1;
|
2020-07-29 07:25:49 +08:00
|
|
|
} else {
|
|
|
|
scudo::Option option;
|
|
|
|
switch (param) {
|
|
|
|
case M_MEMTAG_TUNING:
|
|
|
|
option = scudo::Option::MemtagTuning;
|
|
|
|
break;
|
2020-09-10 10:15:26 +08:00
|
|
|
case M_THREAD_DISABLE_MEM_INIT:
|
|
|
|
option = scudo::Option::ThreadDisableMemInit;
|
|
|
|
break;
|
2020-07-29 07:25:49 +08:00
|
|
|
case M_CACHE_COUNT_MAX:
|
|
|
|
option = scudo::Option::MaxCacheEntriesCount;
|
|
|
|
break;
|
|
|
|
case M_CACHE_SIZE_MAX:
|
|
|
|
option = scudo::Option::MaxCacheEntrySize;
|
|
|
|
break;
|
|
|
|
case M_TSDS_COUNT_MAX:
|
|
|
|
option = scudo::Option::MaxTSDsCount;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return SCUDO_ALLOCATOR.setOption(option, static_cast<scudo::sptr>(value));
|
[scudo][standalone] Introduce the C & C++ wrappers [fixed]
Summary:
This is a redo of D63612.
Two problems came up on some bots:
- `__builtin_umull_overflow` was not declared. This is likely due to an
older clang or gcc, so add a guard with `__has_builtin` and fallback
to a division in the event the builtin doesn't exist;
- contradicting definition for `malloc`, etc. This is AFAIU due to the
fact that we ended up transitively including `stdlib.h` in the `.inc`
due to it being the flags parser header: so move the include to the
cc instead.
This should fix the issues, but since those didn't come up in my local
tests it's mostly guesswork.
Rest is the same!
Reviewers: morehouse, hctim, eugenis, vitalybuka, dyung, hans
Reviewed By: morehouse, dyung, hans
Subscribers: srhines, mgorny, delcypher, jfb, #sanitizers, llvm-commits
Tags: #llvm, #sanitizers
Differential Revision: https://reviews.llvm.org/D63831
llvm-svn: 364547
2019-06-27 22:23:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
INTERFACE WEAK void *SCUDO_PREFIX(aligned_alloc)(size_t alignment,
|
|
|
|
size_t size) {
|
|
|
|
if (UNLIKELY(scudo::checkAlignedAllocAlignmentAndSize(alignment, size))) {
|
|
|
|
if (SCUDO_ALLOCATOR.canReturnNull()) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
scudo::reportInvalidAlignedAllocAlignment(alignment, size);
|
|
|
|
}
|
|
|
|
return scudo::setErrnoOnNull(
|
|
|
|
SCUDO_ALLOCATOR.allocate(size, scudo::Chunk::Origin::Malloc, alignment));
|
|
|
|
}
|
|
|
|
|
[scudo][standalone] Make malloc_info return a minimal XML
Summary:
Initially, our malloc_info was returning ENOTSUP, but Android would
rather have it return successfully and write a barebone XML to the
stream, so we will oblige.
Add an associated test.
Reviewers: cferris, morehouse, hctim, eugenis, vitalybuka
Reviewed By: morehouse
Subscribers: delcypher, #sanitizers, llvm-commits
Tags: #llvm, #sanitizers
Differential Revision: https://reviews.llvm.org/D68427
llvm-svn: 373754
2019-10-04 23:46:34 +08:00
|
|
|
INTERFACE WEAK int SCUDO_PREFIX(malloc_info)(UNUSED int options, FILE *stream) {
|
2020-02-06 06:49:19 +08:00
|
|
|
const scudo::uptr max_size =
|
|
|
|
decltype(SCUDO_ALLOCATOR)::PrimaryT::SizeClassMap::MaxSize;
|
2020-02-11 07:53:07 +08:00
|
|
|
auto *sizes = static_cast<scudo::uptr *>(
|
|
|
|
SCUDO_PREFIX(calloc)(max_size, sizeof(scudo::uptr)));
|
[scudo][standalone] Shift some data from dynamic to static
Summary:
Most of our larger data is dynamically allocated (via `map`) but it
became an hindrance with regard to init time, for a cost to benefit
ratio that is not great. So change the `TSD`s, `RegionInfo`, `ByteMap`
to be static.
Additionally, for reclaiming, we used mapped & unmapped a buffer each
time, which is costly. It turns out that we can have a static buffer,
and that there isn't much contention on it.
One of the other things changed here, is that we hard set the number
of TSDs on Android to the maximum number, as there could be a
situation where cores are put to sleep and we could miss some.
Subscribers: mgorny, #sanitizers, llvm-commits
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D74696
2020-02-17 07:29:46 +08:00
|
|
|
auto callback = [](uintptr_t, size_t size, void *arg) {
|
2020-02-06 06:49:19 +08:00
|
|
|
auto *sizes = reinterpret_cast<scudo::uptr *>(arg);
|
|
|
|
if (size < max_size)
|
|
|
|
sizes[size]++;
|
|
|
|
};
|
|
|
|
SCUDO_ALLOCATOR.iterateOverChunks(0, -1ul, callback, sizes);
|
|
|
|
|
|
|
|
fputs("<malloc version=\"scudo-1\">\n", stream);
|
|
|
|
for (scudo::uptr i = 0; i != max_size; ++i)
|
|
|
|
if (sizes[i])
|
|
|
|
fprintf(stream, "<alloc size=\"%lu\" count=\"%lu\"/>\n", i, sizes[i]);
|
|
|
|
fputs("</malloc>\n", stream);
|
2020-02-11 07:53:07 +08:00
|
|
|
SCUDO_PREFIX(free)(sizes);
|
[scudo][standalone] Make malloc_info return a minimal XML
Summary:
Initially, our malloc_info was returning ENOTSUP, but Android would
rather have it return successfully and write a barebone XML to the
stream, so we will oblige.
Add an associated test.
Reviewers: cferris, morehouse, hctim, eugenis, vitalybuka
Reviewed By: morehouse
Subscribers: delcypher, #sanitizers, llvm-commits
Tags: #llvm, #sanitizers
Differential Revision: https://reviews.llvm.org/D68427
llvm-svn: 373754
2019-10-04 23:46:34 +08:00
|
|
|
return 0;
|
[scudo][standalone] Introduce the C & C++ wrappers [fixed]
Summary:
This is a redo of D63612.
Two problems came up on some bots:
- `__builtin_umull_overflow` was not declared. This is likely due to an
older clang or gcc, so add a guard with `__has_builtin` and fallback
to a division in the event the builtin doesn't exist;
- contradicting definition for `malloc`, etc. This is AFAIU due to the
fact that we ended up transitively including `stdlib.h` in the `.inc`
due to it being the flags parser header: so move the include to the
cc instead.
This should fix the issues, but since those didn't come up in my local
tests it's mostly guesswork.
Rest is the same!
Reviewers: morehouse, hctim, eugenis, vitalybuka, dyung, hans
Reviewed By: morehouse, dyung, hans
Subscribers: srhines, mgorny, delcypher, jfb, #sanitizers, llvm-commits
Tags: #llvm, #sanitizers
Differential Revision: https://reviews.llvm.org/D63831
llvm-svn: 364547
2019-06-27 22:23:26 +08:00
|
|
|
}
|
2020-01-10 03:43:16 +08:00
|
|
|
|
2019-12-05 09:46:15 +08:00
|
|
|
// Disable memory tagging for the heap. The caller must disable memory tag
|
|
|
|
// checks globally (e.g. by clearing TCF0 on aarch64) before calling this
|
2020-09-25 08:01:24 +08:00
|
|
|
// function, and may not re-enable them after calling the function.
|
2019-12-05 09:46:15 +08:00
|
|
|
INTERFACE WEAK void SCUDO_PREFIX(malloc_disable_memory_tagging)() {
|
|
|
|
SCUDO_ALLOCATOR.disableMemoryTagging();
|
|
|
|
}
|
|
|
|
|
2020-01-28 10:43:46 +08:00
|
|
|
// Sets whether scudo records stack traces and other metadata for allocations
|
|
|
|
// and deallocations. This function only has an effect if the allocator and
|
2020-09-25 08:01:24 +08:00
|
|
|
// hardware support memory tagging.
|
2020-01-28 10:43:46 +08:00
|
|
|
INTERFACE WEAK void
|
|
|
|
SCUDO_PREFIX(malloc_set_track_allocation_stacks)(int track) {
|
|
|
|
SCUDO_ALLOCATOR.setTrackAllocationStacks(track);
|
|
|
|
}
|
|
|
|
|
2020-09-25 08:01:24 +08:00
|
|
|
// Sets whether scudo zero-initializes all allocated memory.
|
2020-04-30 05:39:23 +08:00
|
|
|
INTERFACE WEAK void SCUDO_PREFIX(malloc_set_zero_contents)(int zero_contents) {
|
|
|
|
SCUDO_ALLOCATOR.setFillContents(zero_contents ? scudo::ZeroFill
|
|
|
|
: scudo::NoFill);
|
|
|
|
}
|
|
|
|
|
2020-09-25 08:01:24 +08:00
|
|
|
// Sets whether scudo pattern-initializes all allocated memory.
|
2020-04-30 05:39:23 +08:00
|
|
|
INTERFACE WEAK void
|
|
|
|
SCUDO_PREFIX(malloc_set_pattern_fill_contents)(int pattern_fill_contents) {
|
|
|
|
SCUDO_ALLOCATOR.setFillContents(
|
|
|
|
pattern_fill_contents ? scudo::PatternOrZeroFill : scudo::NoFill);
|
|
|
|
}
|
|
|
|
|
2020-12-22 10:39:03 +08:00
|
|
|
// Sets whether scudo adds a small amount of slack at the end of large
|
|
|
|
// allocations, before the guard page. This can be enabled to work around buggy
|
|
|
|
// applications that read a few bytes past the end of their allocation.
|
|
|
|
INTERFACE WEAK void
|
|
|
|
SCUDO_PREFIX(malloc_set_add_large_allocation_slack)(int add_slack) {
|
|
|
|
SCUDO_ALLOCATOR.setAddLargeAllocationSlack(add_slack);
|
|
|
|
}
|
|
|
|
|
2020-01-10 03:43:16 +08:00
|
|
|
} // extern "C"
|