2015-09-30 02:23:36 +08:00
|
|
|
//===-- sanitizer_allocator_internal.h --------------------------*- C++ -*-===//
|
2013-05-29 17:15:39 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
2013-05-29 17:15:39 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This allocator is used inside run-times.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef SANITIZER_ALLOCATOR_INTERNAL_H
|
|
|
|
#define SANITIZER_ALLOCATOR_INTERNAL_H
|
|
|
|
|
|
|
|
#include "sanitizer_allocator.h"
|
|
|
|
#include "sanitizer_internal_defs.h"
|
|
|
|
|
|
|
|
namespace __sanitizer {
|
|
|
|
|
2013-05-29 17:40:07 +08:00
|
|
|
// FIXME: Check if we may use even more compact size class map for internal
|
2013-05-29 17:15:39 +08:00
|
|
|
// purposes.
|
|
|
|
typedef CompactSizeClassMap InternalSizeClassMap;
|
|
|
|
|
2017-05-15 22:47:19 +08:00
|
|
|
struct AP32 {
|
|
|
|
static const uptr kSpaceBeg = 0;
|
|
|
|
static const u64 kSpaceSize = SANITIZER_MMAP_RANGE_SIZE;
|
|
|
|
static const uptr kMetadataSize = 0;
|
|
|
|
typedef InternalSizeClassMap SizeClassMap;
|
2019-04-27 14:30:52 +08:00
|
|
|
static const uptr kRegionSizeLog = 20;
|
Introduce `AddressSpaceView` template parameter to `SizeClassAllocator32`, `FlatByteMap`, and `TwoLevelByteMap`.
Summary:
This is a follow up patch to r346956 for the `SizeClassAllocator32`
allocator.
This patch makes `AddressSpaceView` a template parameter both to the
`ByteMap` implementations (but makes `LocalAddressSpaceView` the
default), some `AP32` implementations and is used in `SizeClassAllocator32`.
The actual changes to `ByteMap` implementations and
`SizeClassAllocator32` are very simple. However the patch is large
because it requires changing all the `AP32` definitions, and users of
those definitions.
For ASan and LSan we make `AP32` and `ByteMap` templateds type that take
a single `AddressSpaceView` argument. This has been done because we will
instantiate the allocator with a type that isn't `LocalAddressSpaceView`
in the future patches. For the allocators used in the other sanitizers
(i.e. HWAsan, MSan, Scudo, and TSan) use of `LocalAddressSpaceView` is
hard coded because we do not intend to instantiate the allocators with
any other type.
In the cases where untemplated types have become templated on a single
`AddressSpaceView` parameter (e.g. `PrimaryAllocator`) their name has
been changed to have a `ASVT` suffix (Address Space View Type) to
indicate they are templated. The only exception to this are the `AP32`
types due to the desire to keep the type name as short as possible.
In order to check that template is instantiated in the correct a way a
`static_assert(...)` has been added that checks that the
`AddressSpaceView` type used by `Params::ByteMap::AddressSpaceView` matches
the `Params::AddressSpaceView`. This uses the new `sanitizer_type_traits.h`
header.
rdar://problem/45284065
Reviewers: kcc, dvyukov, vitalybuka, cryptoad, eugenis, kubamracek, george.karpenkov
Subscribers: mgorny, llvm-commits, #sanitizers
Differential Revision: https://reviews.llvm.org/D54904
llvm-svn: 349138
2018-12-14 17:03:18 +08:00
|
|
|
using AddressSpaceView = LocalAddressSpaceView;
|
2017-05-15 22:47:19 +08:00
|
|
|
typedef NoOpMapUnmapCallback MapUnmapCallback;
|
|
|
|
static const uptr kFlags = 0;
|
|
|
|
};
|
|
|
|
typedef SizeClassAllocator32<AP32> PrimaryInternalAllocator;
|
2013-05-29 17:15:39 +08:00
|
|
|
|
2019-05-02 03:41:54 +08:00
|
|
|
typedef CombinedAllocator<PrimaryInternalAllocator,
|
|
|
|
LargeMmapAllocatorPtrArrayStatic>
|
2019-05-02 03:30:49 +08:00
|
|
|
InternalAllocator;
|
|
|
|
typedef InternalAllocator::AllocatorCache InternalAllocatorCache;
|
2013-05-29 17:15:39 +08:00
|
|
|
|
2016-06-07 02:18:47 +08:00
|
|
|
void *InternalAlloc(uptr size, InternalAllocatorCache *cache = nullptr,
|
|
|
|
uptr alignment = 0);
|
|
|
|
void *InternalRealloc(void *p, uptr size,
|
|
|
|
InternalAllocatorCache *cache = nullptr);
|
2019-05-02 01:33:01 +08:00
|
|
|
void *InternalReallocArray(void *p, uptr count, uptr size,
|
|
|
|
InternalAllocatorCache *cache = nullptr);
|
|
|
|
void *InternalCalloc(uptr count, uptr size,
|
2016-06-07 02:18:47 +08:00
|
|
|
InternalAllocatorCache *cache = nullptr);
|
2015-09-30 02:23:36 +08:00
|
|
|
void InternalFree(void *p, InternalAllocatorCache *cache = nullptr);
|
2013-05-29 17:15:39 +08:00
|
|
|
InternalAllocator *internal_allocator();
|
|
|
|
|
2015-09-30 02:23:36 +08:00
|
|
|
} // namespace __sanitizer
|
2013-05-29 17:15:39 +08:00
|
|
|
|
2015-09-30 02:23:36 +08:00
|
|
|
#endif // SANITIZER_ALLOCATOR_INTERNAL_H
|