-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
//go:build tinygo.wasm | ||
|
||
package wasilibs | ||
|
||
/* | ||
#cgo LDFLAGS: -Linternal/wasm -lcre2 -lre2 -lc++ -lc++abi -lclang_rt.builtins-wasm32 | ||
*/ | ||
import "C" |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//go:build tinygo.wasm && !gc.custom && !custommalloc | ||
|
||
package wasilibs | ||
|
||
import ( | ||
"unsafe" | ||
) | ||
|
||
/* | ||
#include <stdint.h> | ||
void* malloc(size_t size); | ||
void free(void* ptr); | ||
*/ | ||
import "C" | ||
|
||
// TinyGo currently only includes a subset of malloc functions by default, so we | ||
// reimplement the remaining here. | ||
|
||
//export posix_memalign | ||
func posix_memalign(memptr *uint32, align uint32, size uint32) int32 { | ||
if align < 4 { | ||
return 22 /* EINVAL */ | ||
} | ||
|
||
// Ignore alignment and hope for best, TinyGo by default does not | ||
// provide a way to allocate aligned memory. | ||
mem := uint32(uintptr(C.malloc(C.size_t(size)))) | ||
if mem == 0 { | ||
// TODO(anuraaga): Needs to read errno to be precise | ||
return 1 | ||
} | ||
|
||
*memptr = mem | ||
|
||
return 0 | ||
} | ||
|
||
//export calloc | ||
func calloc(num uint32, size uint32) uint32 | ||
|
||
//export __libc_calloc | ||
func __libc_calloc(num uint32, size uint32) uint32 { | ||
return calloc(num, size) | ||
} | ||
|
||
//export __libc_malloc | ||
func __libc_malloc(size uint32) uint32 { | ||
return uint32(uintptr(C.malloc(C.size_t(size)))) | ||
} | ||
|
||
//export __libc_free | ||
func __libc_free(ptr uint32) { | ||
C.free(unsafe.Pointer(uintptr(ptr))) | ||
} |