aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2019-07-03 19:44:36 +0200
committerRon Evans <[email protected]>2019-07-03 21:22:12 +0200
commitd49a363d0d3834887415f32d74868f6876fdae08 (patch)
tree1522ceb74254eec84b274995a1c5ac85e7b3f87d
parent385d1d0a5d5c8713ca5eaf35fd6dffd1f3b0ed55 (diff)
downloadtinygo-d49a363d0d3834887415f32d74868f6876fdae08.tar.gz
tinygo-d49a363d0d3834887415f32d74868f6876fdae08.zip
compiler: track all pointers returned by runtime.alloc
In particular, track the pointers to the memory allocated for coroutine frames. Before this change, the following code would show memory corruption: https://github.com/johanbrandhorst/wasm-experiments/blob/master/canvas/main.go
-rw-r--r--compiler/goroutine-lowering.go3
-rw-r--r--compiler/wordpack.go3
2 files changed, 6 insertions, 0 deletions
diff --git a/compiler/goroutine-lowering.go b/compiler/goroutine-lowering.go
index 3aa72e938..a336a3dd9 100644
--- a/compiler/goroutine-lowering.go
+++ b/compiler/goroutine-lowering.go
@@ -336,6 +336,9 @@ func (c *Compiler) markAsyncFunctions() (needsScheduler bool, err error) {
size = c.builder.CreateZExt(size, c.uintptrType, "task.size.uintptr")
}
data := c.createRuntimeCall("alloc", []llvm.Value{size}, "task.data")
+ if c.needsStackObjects() {
+ c.trackPointer(data)
+ }
frame.taskHandle = c.builder.CreateCall(coroBeginFunc, []llvm.Value{id, data}, "task.handle")
// Modify async calls so this function suspends right after the child
diff --git a/compiler/wordpack.go b/compiler/wordpack.go
index b76bf6a35..e553cb9c4 100644
--- a/compiler/wordpack.go
+++ b/compiler/wordpack.go
@@ -39,6 +39,9 @@ func (c *Compiler) emitPointerPack(values []llvm.Value) llvm.Value {
// Packed data is bigger than a pointer, so allocate it on the heap.
sizeValue := llvm.ConstInt(c.uintptrType, size, false)
packedHeapAlloc = c.createRuntimeCall("alloc", []llvm.Value{sizeValue}, "")
+ if c.needsStackObjects() {
+ c.trackPointer(packedHeapAlloc)
+ }
packedAlloc = c.builder.CreateBitCast(packedHeapAlloc, llvm.PointerType(packedType, 0), "")
}
// Store all values in the alloca or heap pointer.