mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-03 18:47:47 +00:00
54169c714f
This simplifies adding more baremetal targets, like a GameBoy Advance, or baremetal x86 for unikernels.
36 lines
967 B
Go
36 lines
967 B
Go
// +build gc.conservative
|
|
// +build !baremetal
|
|
|
|
package runtime
|
|
|
|
import (
|
|
"unsafe"
|
|
)
|
|
|
|
//go:extern runtime.trackedGlobalsStart
|
|
var trackedGlobalsStart uintptr
|
|
|
|
//go:extern runtime.trackedGlobalsLength
|
|
var trackedGlobalsLength uintptr
|
|
|
|
//go:extern runtime.trackedGlobalsBitmap
|
|
var trackedGlobalsBitmap [0]uint8
|
|
|
|
// markGlobals marks all globals, which are reachable by definition.
|
|
//
|
|
// This implementation relies on a compiler pass that stores all globals in a
|
|
// single global (adjusting all uses of them accordingly) and creates a bit
|
|
// vector with the locations of each pointer. This implementation then walks the
|
|
// bit vector and for each pointer it indicates, it marks the root.
|
|
//
|
|
//go:nobounds
|
|
func markGlobals() {
|
|
for i := uintptr(0); i < trackedGlobalsLength; i++ {
|
|
if trackedGlobalsBitmap[i/8]&(1<<(i%8)) != 0 {
|
|
addr := trackedGlobalsStart + i*unsafe.Alignof(uintptr(0))
|
|
root := *(*uintptr)(unsafe.Pointer(addr))
|
|
markRoot(addr, root)
|
|
}
|
|
}
|
|
}
|