diff options
Diffstat (limited to 'src/runtime/mfixalloc.go')
| -rw-r--r-- | src/runtime/mfixalloc.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/runtime/mfixalloc.go b/src/runtime/mfixalloc.go index 0e56efb923..0d3d895113 100644 --- a/src/runtime/mfixalloc.go +++ b/src/runtime/mfixalloc.go @@ -14,7 +14,11 @@ import "unsafe" // Malloc uses a FixAlloc wrapped around sysAlloc to manages its // MCache and MSpan objects. // -// Memory returned by FixAlloc_Alloc is not zeroed. +// Memory returned by fixalloc.alloc is zeroed by default, but the +// caller may take responsibility for zeroing allocations by setting +// the zero flag to false. This is only safe if the memory never +// contains heap pointers. +// // The caller is responsible for locking around FixAlloc calls. // Callers can keep state in the object but the first word is // smashed by freeing and reallocating. @@ -29,6 +33,7 @@ type fixalloc struct { nchunk uint32 inuse uintptr // in-use bytes now stat *uint64 + zero bool // zero allocations } // A generic linked list of blocks. (Typically the block is bigger than sizeof(MLink).) @@ -53,6 +58,7 @@ func (f *fixalloc) init(size uintptr, first func(arg, p unsafe.Pointer), arg uns f.nchunk = 0 f.inuse = 0 f.stat = stat + f.zero = true } func (f *fixalloc) alloc() unsafe.Pointer { @@ -65,6 +71,9 @@ func (f *fixalloc) alloc() unsafe.Pointer { v := unsafe.Pointer(f.list) f.list = f.list.next f.inuse += f.size + if f.zero { + memclr(v, f.size) + } return v } if uintptr(f.nchunk) < f.size { |
