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
Этот коммит содержится в:
родитель
385d1d0a5d
коммит
d49a363d0d
2 изменённых файлов: 6 добавлений и 0 удалений
|
@ -336,6 +336,9 @@ func (c *Compiler) markAsyncFunctions() (needsScheduler bool, err error) {
|
||||||
size = c.builder.CreateZExt(size, c.uintptrType, "task.size.uintptr")
|
size = c.builder.CreateZExt(size, c.uintptrType, "task.size.uintptr")
|
||||||
}
|
}
|
||||||
data := c.createRuntimeCall("alloc", []llvm.Value{size}, "task.data")
|
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")
|
frame.taskHandle = c.builder.CreateCall(coroBeginFunc, []llvm.Value{id, data}, "task.handle")
|
||||||
|
|
||||||
// Modify async calls so this function suspends right after the child
|
// Modify async calls so this function suspends right after the child
|
||||||
|
|
|
@ -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.
|
// Packed data is bigger than a pointer, so allocate it on the heap.
|
||||||
sizeValue := llvm.ConstInt(c.uintptrType, size, false)
|
sizeValue := llvm.ConstInt(c.uintptrType, size, false)
|
||||||
packedHeapAlloc = c.createRuntimeCall("alloc", []llvm.Value{sizeValue}, "")
|
packedHeapAlloc = c.createRuntimeCall("alloc", []llvm.Value{sizeValue}, "")
|
||||||
|
if c.needsStackObjects() {
|
||||||
|
c.trackPointer(packedHeapAlloc)
|
||||||
|
}
|
||||||
packedAlloc = c.builder.CreateBitCast(packedHeapAlloc, llvm.PointerType(packedType, 0), "")
|
packedAlloc = c.builder.CreateBitCast(packedHeapAlloc, llvm.PointerType(packedType, 0), "")
|
||||||
}
|
}
|
||||||
// Store all values in the alloca or heap pointer.
|
// Store all values in the alloca or heap pointer.
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче