[asan] asan_allocator2: do less work under the quarantine lock; make the strcasecmp test more resistant to the contents of unaddressable memory

llvm-svn: 172048
This commit is contained in:
Kostya Serebryany 2013-01-10 09:25:16 +00:00
parent 9fb566c076
commit 8cc7b627b4
2 changed files with 15 additions and 14 deletions

View File

@ -251,9 +251,16 @@ class Quarantine: public AsanChunkFifoList {
void SwallowThreadLocalQuarantine(AsanThreadLocalMallocStorage *ms) {
AsanChunkFifoList *q = &ms->quarantine_;
if (!q->size()) return;
SpinMutexLock l(&mutex_);
PushList(q);
PopAndDeallocateLoop(ms);
AsanChunkFifoList tmp;
uptr max_size = flags()->quarantine_size;
{
SpinMutexLock l(&mutex_);
PushList(q);
while (size() > max_size)
tmp.Push(Pop());
}
while (!tmp.empty())
Deallocate(tmp.Pop(), ms);
}
void BypassThreadLocalQuarantine(AsanChunk *m) {
@ -262,14 +269,7 @@ class Quarantine: public AsanChunkFifoList {
}
private:
void PopAndDeallocateLoop(AsanThreadLocalMallocStorage *ms) {
while (size() > (uptr)flags()->quarantine_size) {
PopAndDeallocate(ms);
}
}
void PopAndDeallocate(AsanThreadLocalMallocStorage *ms) {
CHECK_GT(size(), 0);
AsanChunk *m = Pop();
static void Deallocate(AsanChunk *m, AsanThreadLocalMallocStorage *ms) {
CHECK(m);
CHECK(m->chunk_state == CHUNK_QUARANTINE);
m->chunk_state = CHUNK_AVAILABLE;

View File

@ -1313,8 +1313,9 @@ TEST(AddressSanitizer, StrCmpAndFriendsLogicTest) {
typedef int(*PointerToStrCmp)(const char*, const char*);
void RunStrCmpTest(PointerToStrCmp StrCmp) {
size_t size = Ident(100);
char *s1 = MallocAndMemsetString(size);
char *s2 = MallocAndMemsetString(size);
int fill = 'o';
char *s1 = MallocAndMemsetString(size, fill);
char *s2 = MallocAndMemsetString(size, fill);
s1[size - 1] = '\0';
s2[size - 1] = '\0';
// Normal StrCmp calls
@ -1330,7 +1331,7 @@ void RunStrCmpTest(PointerToStrCmp StrCmp) {
EXPECT_DEATH(Ident(StrCmp)(s1 + size, s2), RightOOBReadMessage(0));
EXPECT_DEATH(Ident(StrCmp)(s1, s2 + size), RightOOBReadMessage(0));
// Hit unallocated memory and die.
s2[size - 1] = 'z';
s1[size - 1] = fill;
EXPECT_DEATH(Ident(StrCmp)(s1, s1), RightOOBReadMessage(0));
EXPECT_DEATH(Ident(StrCmp)(s1 + size - 1, s2), RightOOBReadMessage(0));
free(s1);