diff options
author | Alexey Samsonov <samsonov@google.com> | 2012-08-27 14:51:36 +0000 |
---|---|---|
committer | Alexey Samsonov <samsonov@google.com> | 2012-08-27 14:51:36 +0000 |
commit | d883c8007ea8b5ffad10d82a66b1bb262e109705 (patch) | |
tree | 4d13495edf31c92462ee60c1d553380cfc918c8b /lib | |
parent | b10027729a3b809469f6b6ad40407ca453d6f54a (diff) | |
download | compiler-rt-d883c8007ea8b5ffad10d82a66b1bb262e109705.tar.gz |
[Sanitizer] align allocation sizes in low level allocator
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@162676 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sanitizer_common/sanitizer_allocator.cc | 3 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_common.h | 6 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_flags.cc | 3 | ||||
-rw-r--r-- | lib/sanitizer_common/tests/sanitizer_flags_test.cc | 1 |
4 files changed, 9 insertions, 4 deletions
diff --git a/lib/sanitizer_common/sanitizer_allocator.cc b/lib/sanitizer_common/sanitizer_allocator.cc index b08434ad6..45fcb230c 100644 --- a/lib/sanitizer_common/sanitizer_allocator.cc +++ b/lib/sanitizer_common/sanitizer_allocator.cc @@ -60,7 +60,8 @@ void *InternalAllocBlock(void *p) { static LowLevelAllocateCallback low_level_alloc_callback; void *LowLevelAllocator::Allocate(uptr size) { - CHECK((size & (size - 1)) == 0 && "size must be a power of two"); + // Align allocation size. + size = RoundUpTo(size, 8); if (allocated_end_ - allocated_current_ < (sptr)size) { uptr size_to_allocate = Max(size, kPageSize); allocated_current_ = diff --git a/lib/sanitizer_common/sanitizer_common.h b/lib/sanitizer_common/sanitizer_common.h index 7c3930d8e..112de59b5 100644 --- a/lib/sanitizer_common/sanitizer_common.h +++ b/lib/sanitizer_common/sanitizer_common.h @@ -78,10 +78,12 @@ class InternalScopedBuffer { void operator=(const InternalScopedBuffer&); }; -// Simple low-level (mmap-based) allocator for internal use. +// Simple low-level (mmap-based) allocator for internal use. Doesn't have +// constructor, so all instances of LowLevelAllocator should be +// linker initialized. class LowLevelAllocator { public: - // 'size' must be a power of two. Requires an external lock. + // Requires an external lock. void *Allocate(uptr size); private: char *allocated_end_; diff --git a/lib/sanitizer_common/sanitizer_flags.cc b/lib/sanitizer_common/sanitizer_flags.cc index dd28d5967..eca910c08 100644 --- a/lib/sanitizer_common/sanitizer_flags.cc +++ b/lib/sanitizer_common/sanitizer_flags.cc @@ -86,7 +86,8 @@ void ParseFlag(const char *env, const char **flag, const char *name) { int value_length; if (!GetFlagValue(env, name, &value, &value_length)) return; - // Copy the flag value. + // Copy the flag value. Don't use locks here, as flags are parsed at + // tool startup. char *value_copy = (char*)(allocator_for_flags.Allocate(value_length + 1)); internal_memcpy(value_copy, value, value_length); value_copy[value_length] = '\0'; diff --git a/lib/sanitizer_common/tests/sanitizer_flags_test.cc b/lib/sanitizer_common/tests/sanitizer_flags_test.cc index 4b273e5b9..f6b7a152d 100644 --- a/lib/sanitizer_common/tests/sanitizer_flags_test.cc +++ b/lib/sanitizer_common/tests/sanitizer_flags_test.cc @@ -66,6 +66,7 @@ TEST(SanitizerCommon, StrFlags) { TestStrFlag("zzz", "--flag_name=", ""); TestStrFlag("", "--flag_name=abc", "abc"); TestStrFlag("", "--flag_name='abc zxc'", "abc zxc"); + TestStrFlag("", "--flag_name='abc zxcc'", "abc zxcc"); TestStrFlag("", "--flag_name=\"abc qwe\" asd", "abc qwe"); } |