|
| 1 | +//go:build gc.custom |
| 2 | +// +build gc.custom |
| 3 | + |
| 4 | +package runtime |
| 5 | + |
| 6 | +// This GC strategy allows an external GC to be plugged in instead of the builtin |
| 7 | +// implementations. |
| 8 | +// |
| 9 | +// The interface defined in this file is not stable and can be broken at anytime, even |
| 10 | +// across minor versions. |
| 11 | +// |
| 12 | +// runtime.markStack() must be called at the beginning of any GC cycle. //go:linkname |
| 13 | +// on a function without a body can be used to access this internal function. |
| 14 | +// |
| 15 | +// The custom implementation must provide the following functions in the runtime package |
| 16 | +// using the go:linkname directive: |
| 17 | +// |
| 18 | +// - func initHeap() |
| 19 | +// - func alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer |
| 20 | +// - func free(ptr unsafe.Pointer) |
| 21 | +// - func markRoots(start, end uintptr) |
| 22 | +// - func GC() |
| 23 | +// |
| 24 | +// |
| 25 | +// In addition, if targeting wasi, the following functions should be exported for interoperability |
| 26 | +// with wasi libraries that use them. Note, this requires the export directive, not go:linkname. |
| 27 | +// |
| 28 | +// - func malloc(size uintptr) unsafe.Pointer |
| 29 | +// - func free(ptr unsafe.Pointer) |
| 30 | +// - func calloc(nmemb, size uintptr) unsafe.Pointer |
| 31 | +// - func realloc(oldPtr unsafe.Pointer, size uintptr) unsafe.Pointer |
| 32 | + |
| 33 | +import ( |
| 34 | + "unsafe" |
| 35 | +) |
| 36 | + |
| 37 | +// initHeap is called when the heap is first initialized at program start. |
| 38 | +func initHeap() |
| 39 | + |
| 40 | +// alloc is called to allocate memory. layout is currently not used. |
| 41 | +func alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer |
| 42 | + |
| 43 | +// free is called to explicitly free a previously allocated pointer. |
| 44 | +func free(ptr unsafe.Pointer) |
| 45 | + |
| 46 | +// markRoots is called with the start and end addresses to scan for references. |
| 47 | +// It is currently only called with the top and bottom of the stack. |
| 48 | +func markRoots(start, end uintptr) |
| 49 | + |
| 50 | +// GC is called to explicitly run garbage collection. |
| 51 | +func GC() |
| 52 | + |
| 53 | +func setHeapEnd(newHeapEnd uintptr) { |
| 54 | + // Heap is in custom GC so ignore for when called from wasm initialization. |
| 55 | +} |
0 commit comments