Skip to content

Commit d49a363

Browse files
aykevldeadprogram
authored andcommitted
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
1 parent 385d1d0 commit d49a363

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

compiler/goroutine-lowering.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,9 @@ func (c *Compiler) markAsyncFunctions() (needsScheduler bool, err error) {
336336
size = c.builder.CreateZExt(size, c.uintptrType, "task.size.uintptr")
337337
}
338338
data := c.createRuntimeCall("alloc", []llvm.Value{size}, "task.data")
339+
if c.needsStackObjects() {
340+
c.trackPointer(data)
341+
}
339342
frame.taskHandle = c.builder.CreateCall(coroBeginFunc, []llvm.Value{id, data}, "task.handle")
340343

341344
// Modify async calls so this function suspends right after the child

compiler/wordpack.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ func (c *Compiler) emitPointerPack(values []llvm.Value) llvm.Value {
3939
// Packed data is bigger than a pointer, so allocate it on the heap.
4040
sizeValue := llvm.ConstInt(c.uintptrType, size, false)
4141
packedHeapAlloc = c.createRuntimeCall("alloc", []llvm.Value{sizeValue}, "")
42+
if c.needsStackObjects() {
43+
c.trackPointer(packedHeapAlloc)
44+
}
4245
packedAlloc = c.builder.CreateBitCast(packedHeapAlloc, llvm.PointerType(packedType, 0), "")
4346
}
4447
// Store all values in the alloca or heap pointer.

0 commit comments

Comments
 (0)