]> Cypherpunks repositories - gostls13.git/commit
runtime: change tinyalloc, persistentalloc not to point past allocated data
authorRuss Cox <rsc@golang.org>
Wed, 14 Jan 2015 19:13:55 +0000 (14:13 -0500)
committerRuss Cox <rsc@golang.org>
Wed, 14 Jan 2015 20:46:57 +0000 (20:46 +0000)
commit0e84088715a2242fbc99b813ac25ac60b21d997a
tree9b28c559b88235864b5ecd596094ddbe8a624b8a
parentbfeda9188a054efdb950c9c9727d6bce7ad04961
runtime: change tinyalloc, persistentalloc not to point past allocated data

During all.bash I got a crash in the GOMAXPROCS=2 runtime test reporting
that the write barrier in the assignment 'c.tiny = add(x, size)' had been
given a pointer pointing into an unexpected span. The problem is that
the tiny allocation was at the end of a span and c.tiny was now pointing
to the end of the allocation and therefore to the end of the span aka
the beginning of the next span.

Rewrite tinyalloc not to do that.

More generally, it's not okay to call add(p, size) unless you know that p
points at > (not just >=) size bytes. Similarly, pretty much any call to
roundup doesn't know how much space p points at, so those are all
broken.

Rewrite persistentalloc not to use add(p, totalsize) and not to use roundup.

There is only one use of roundup left, in vprintf, which is dead code.
I will remove that code and roundup itself in a followup CL.

Change-Id: I211e307d1a656d29087b8fd40b2b71010722fb4a
Reviewed-on: https://go-review.googlesource.com/2814
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
src/runtime/malloc.go
src/runtime/malloc2.go
src/runtime/mgc0.go