summaryrefslogtreecommitdiff
path: root/src/pkg/runtime/mcache.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/runtime/mcache.c')
-rw-r--r--src/pkg/runtime/mcache.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/pkg/runtime/mcache.c b/src/pkg/runtime/mcache.c
index ae2594023..429b42541 100644
--- a/src/pkg/runtime/mcache.c
+++ b/src/pkg/runtime/mcache.c
@@ -10,7 +10,7 @@
#include "malloc.h"
void*
-MCache_Alloc(MCache *c, int32 sizeclass, uintptr size)
+MCache_Alloc(MCache *c, int32 sizeclass, uintptr size, int32 zeroed)
{
MCacheList *l;
MLink *first, *v;
@@ -36,6 +36,16 @@ MCache_Alloc(MCache *c, int32 sizeclass, uintptr size)
// v is zeroed except for the link pointer
// that we used above; zero that.
v->next = nil;
+ if(zeroed) {
+ // block is zeroed iff second word is zero ...
+ if(size > sizeof(uintptr) && ((uintptr*)v)[1] != 0)
+ runtime_memclr((byte*)v, size);
+ else {
+ // ... except for the link pointer
+ // that we used above; zero that.
+ v->next = nil;
+ }
+ }
return v;
}