docs: add commets for gc mutex
docs: add commets for tinygo gc
This commit is contained in:
@@ -4,6 +4,9 @@ package tinygogc
|
|||||||
|
|
||||||
import "unsafe"
|
import "unsafe"
|
||||||
|
|
||||||
|
// LLGoPackage instructs the LLGo linker to wrap C standard library memory allocation
|
||||||
|
// functions (malloc, realloc, calloc) so they use the tinygogc allocator instead.
|
||||||
|
// This ensures all memory allocations go through the GC, including C library calls.
|
||||||
const LLGoPackage = "link: --wrap=malloc --wrap=realloc --wrap=calloc"
|
const LLGoPackage = "link: --wrap=malloc --wrap=realloc --wrap=calloc"
|
||||||
|
|
||||||
//export __wrap_malloc
|
//export __wrap_malloc
|
||||||
@@ -12,8 +15,13 @@ func __wrap_malloc(size uintptr) unsafe.Pointer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//export __wrap_calloc
|
//export __wrap_calloc
|
||||||
func __wrap_calloc(size uintptr) unsafe.Pointer {
|
func __wrap_calloc(nmemb, size uintptr) unsafe.Pointer {
|
||||||
return Alloc(size)
|
totalSize := nmemb * size
|
||||||
|
// Check for multiplication overflow
|
||||||
|
if nmemb != 0 && totalSize/nmemb != size {
|
||||||
|
return nil // Overflow
|
||||||
|
}
|
||||||
|
return Alloc(totalSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export __wrap_realloc
|
//export __wrap_realloc
|
||||||
|
|||||||
@@ -16,6 +16,20 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Package tinygogc implements a conservative mark-and-sweep garbage collector
|
||||||
|
// for baremetal environments where the standard Go runtime and bdwgc are unavailable.
|
||||||
|
//
|
||||||
|
// This implementation is based on TinyGo's GC and is designed for resource-constrained
|
||||||
|
// embedded systems. It uses a block-based allocator with conservative pointer scanning.
|
||||||
|
//
|
||||||
|
// Build tags:
|
||||||
|
// - baremetal: Enables this GC for baremetal targets
|
||||||
|
// - testGC: Enables testing mode with mock implementations
|
||||||
|
//
|
||||||
|
// Memory Layout:
|
||||||
|
// The heap is divided into fixed-size blocks (32 bytes on 64-bit). Metadata is stored
|
||||||
|
// at the end of the heap, using 2 bits per block to track state (free/head/tail/mark).
|
||||||
package tinygogc
|
package tinygogc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package tinygogc
|
package tinygogc
|
||||||
|
|
||||||
|
// TODO(MeteorsLiu): mutex lock for baremetal GC
|
||||||
type mutex struct{}
|
type mutex struct{}
|
||||||
|
|
||||||
func lock(m *mutex) {}
|
func lock(m *mutex) {}
|
||||||
|
|||||||
Reference in New Issue
Block a user