Skip to content

Commit 213cdf6

Browse files
committed
baremetal: implement calloc libc function
This simply calls runtime.alloc, because the memory will be zero-initialized anyway.
1 parent 21a2d5a commit 213cdf6

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/runtime/baremetal.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ func libc_free(ptr unsafe.Pointer) {
4646
free(ptr)
4747
}
4848

49+
//export calloc
50+
func libc_calloc(nmemb, size uintptr) unsafe.Pointer {
51+
// Note: we could be even more correct here and check that nmemb * size
52+
// doesn't overflow. However the current implementation should normally work
53+
// fine.
54+
return alloc(nmemb * size)
55+
}
56+
4957
//export abort
5058
func libc_abort() {
5159
abort()

0 commit comments

Comments
 (0)