summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPatrick Williams <iawillia@us.ibm.com>2013-04-28 18:39:46 -0500
committerA. Patrick Williams III <iawillia@us.ibm.com>2013-05-01 14:22:37 -0500
commit12bb660f69bc7d7bd4cab92621ee2d5b3963ab62 (patch)
treea5422e50ee94c990caf67afd3ee7654a98ec56f4 /src
parente319acb36befe9fbbdd71565ec570d5977be532b (diff)
downloadtalos-hostboot-12bb660f69bc7d7bd4cab92621ee2d5b3963ab62.tar.gz
talos-hostboot-12bb660f69bc7d7bd4cab92621ee2d5b3963ab62.zip
Enhance heap corruption detection.
Change-Id: I25ec156fe3c9088d2de2254017407dbadd2fac31 Reviewed-on: http://gfw160.austin.ibm.com:8080/gerrit/4255 Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com> Tested-by: Jenkins Server Reviewed-by: A. Patrick Williams III <iawillia@us.ibm.com>
Diffstat (limited to 'src')
-rw-r--r--src/include/util/lockfree/stack.H56
-rw-r--r--src/kernel/heapmgr.C8
-rw-r--r--src/lib/assert.C8
3 files changed, 43 insertions, 29 deletions
diff --git a/src/include/util/lockfree/stack.H b/src/include/util/lockfree/stack.H
index 61120364b..e6b4daf09 100644
--- a/src/include/util/lockfree/stack.H
+++ b/src/include/util/lockfree/stack.H
@@ -1,29 +1,30 @@
-// IBM_PROLOG_BEGIN_TAG
-// This is an automatically generated prolog.
-//
-// $Source: src/include/util/lockfree/stack.H $
-//
-// IBM CONFIDENTIAL
-//
-// COPYRIGHT International Business Machines Corp. 2010 - 2011
-//
-// p1
-//
-// Object Code Only (OCO) source materials
-// Licensed Internal Code Source Materials
-// IBM HostBoot Licensed Internal Code
-//
-// The source code for this program is not published or other-
-// wise divested of its trade secrets, irrespective of what has
-// been deposited with the U.S. Copyright Office.
-//
-// Origin: 30
-//
-// IBM_PROLOG_END
+/* IBM_PROLOG_BEGIN_TAG */
+/* This is an automatically generated prolog. */
+/* */
+/* $Source: src/include/util/lockfree/stack.H $ */
+/* */
+/* IBM CONFIDENTIAL */
+/* */
+/* COPYRIGHT International Business Machines Corp. 2010,2013 */
+/* */
+/* p1 */
+/* */
+/* Object Code Only (OCO) source materials */
+/* Licensed Internal Code Source Materials */
+/* IBM HostBoot Licensed Internal Code */
+/* */
+/* The source code for this program is not published or otherwise */
+/* divested of its trade secrets, irrespective of what has been */
+/* deposited with the U.S. Copyright Office. */
+/* */
+/* Origin: 30 */
+/* */
+/* IBM_PROLOG_END_TAG */
#ifndef __UTIL_LOCKFREE_STACK_H
#define __UTIL_LOCKFREE_STACK_H
#include <stddef.h>
+#include <assert.h>
namespace Util
{
@@ -61,14 +62,18 @@ namespace Util
{
_T * _head = head;
_T * h = (_T*) (((uint64_t)_head) & 0x00000000FFFFFFFF);
- if (NULL == h) return h;
+ if (NULL == h) return h;
uint64_t token = ((uint64_t)_head) >> 32;
token++;
- _T * h_next = (_T*) (((uint64_t)(h->next)) | (token << 32));
+ uint64_t h_next_v = (uint64_t)(h->next);
+ _T * h_next = (_T*) ((h_next_v & 0x00000000FFFFFFFF) |
+ (token << 32));
if (!__sync_bool_compare_and_swap(&head,
_head,
h_next))
return pop();
+
+ crit_assert((h_next_v >> 32) == 0x5354414B);
return h;
}
@@ -76,7 +81,8 @@ namespace Util
void Stack<_T>::push(_T* p)
{
_T* _head = head;
- p->next = (_T*) (((uint64_t)_head) & 0x00000000FFFFFFFF);
+ p->next = (_T*) ((((uint64_t)_head) & 0x00000000FFFFFFFF) |
+ 0x5354414B00000000);
uint64_t token = ((uint64_t)_head) >> 32;
token++;
diff --git a/src/kernel/heapmgr.C b/src/kernel/heapmgr.C
index f790b9e46..5518a96f8 100644
--- a/src/kernel/heapmgr.C
+++ b/src/kernel/heapmgr.C
@@ -119,6 +119,7 @@ void* HeapManager::_allocate(size_t i_sz)
g_smallheap_alloc_hw = g_smallheap_allocated;
// test_pages();
#endif
+ crit_assert(chunk->free);
chunk->free = false;
return &chunk->next;
}
@@ -180,7 +181,7 @@ void* HeapManager::_reallocBig(void* i_ptr, size_t i_sz)
break;
}
- bc = bc->next;
+ bc = (big_chunk_t*) (((uint64_t)bc->next) & 0x00000000FFFFFFFF);
}
return new_ptr;
}
@@ -196,6 +197,7 @@ void HeapManager::_free(void * i_ptr)
__sync_sub_and_fetch(&g_smallheap_count,1);
__sync_sub_and_fetch(&g_smallheap_allocated,bucketByteSize(chunk->bucket));
#endif
+ crit_assert(!chunk->free);
push_bucket(chunk, chunk->bucket);
}
}
@@ -531,7 +533,7 @@ void* HeapManager::_allocateBig(size_t i_sz)
break;
}
}
- bc = bc->next;
+ bc = (big_chunk_t*) (((uint64_t)bc->next) & 0x00000000FFFFFFFF);
}
if(!bc)
{
@@ -570,7 +572,7 @@ bool HeapManager::_freeBig(void* i_ptr)
result = true;
break;
}
- bc = bc->next;
+ bc = (big_chunk_t*) (((uint64_t)bc->next) & 0x00000000FFFFFFFF);
}
return result;
}
diff --git a/src/lib/assert.C b/src/lib/assert.C
index ebf59fb3f..28348bbc1 100644
--- a/src/lib/assert.C
+++ b/src/lib/assert.C
@@ -5,7 +5,7 @@
/* */
/* IBM CONFIDENTIAL */
/* */
-/* COPYRIGHT International Business Machines Corp. 2011,2012 */
+/* COPYRIGHT International Business Machines Corp. 2011,2013 */
/* */
/* p1 */
/* */
@@ -29,6 +29,7 @@
#include <assert.h>
#include <sys/task.h>
#include <arch/ppc.H>
+#include <kernel/misc.H>
#include <kernel/hbterminatetypes.H>
#include <kernel/terminate.H>
@@ -40,6 +41,11 @@ namespace TRACE { void (*traceCallback)(void*, size_t) = NULL; };
extern "C" void __assert(AssertBehavior i_assertb, int i_line)
{
+ if ((i_assertb == ASSERT_CRITICAL) && (KernelMisc::in_kernel_mode()))
+ {
+ i_assertb = ASSERT_KERNEL;
+ }
+
switch (i_assertb)
{
case ASSERT_TRACE_DONE: // Custom trace was provided.
OpenPOWER on IntegriCloud