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 // - func SetFinalizer(obj interface{}, finalizer interface{})
24 // - func ReadMemStats(ms *runtime.MemStats)
25 //
26 //
27 // In addition, if targeting wasi, the following functions should be exported for interoperability
28 // with wasi libraries that use them. Note, this requires the export directive, not go:linkname.
29 //
30 // - func malloc(size uintptr) unsafe.Pointer
31 // - func free(ptr unsafe.Pointer)
32 // - func calloc(nmemb, size uintptr) unsafe.Pointer
33 // - func realloc(oldPtr unsafe.Pointer, size uintptr) unsafe.Pointer
34 35 import (
36 "unsafe"
37 )
38 39 const needsStaticHeap = false
40 41 // initHeap is called when the heap is first initialized at program start.
42 func initHeap()
43 44 // alloc is called to allocate memory. layout is currently not used.
45 func alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer
46 47 // free is called to explicitly free a previously allocated pointer.
48 func free(ptr unsafe.Pointer)
49 50 // markRoots is called with the start and end addresses to scan for references.
51 // It is currently only called with the top and bottom of the stack.
52 func markRoots(start, end uintptr)
53 54 // GC is called to explicitly run garbage collection.
55 func GC()
56 57 // SetFinalizer registers a finalizer.
58 func SetFinalizer(obj interface{}, finalizer interface{})
59 60 // ReadMemStats populates m with memory statistics.
61 func ReadMemStats(ms *MemStats)
62 63 func setHeapEnd(newHeapEnd uintptr) {
64 // Heap is in custom GC so ignore for when called from wasm initialization.
65 }
66