From 67fbfe63051274850cfd20f6d9baec4b762fe579 Mon Sep 17 00:00:00 2001 From: Seth Junot Date: Thu, 17 Jan 2019 17:51:58 -0800 Subject: [PATCH] runtime/wasm: add memset() Copied from the ARM runtime and modified to return a pointer. https://pubs.opengroup.org/onlinepubs/9699919799/functions/memset.html --- src/runtime/runtime_wasm.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/runtime/runtime_wasm.go b/src/runtime/runtime_wasm.go index 8212d859..4abc1cd7 100644 --- a/src/runtime/runtime_wasm.go +++ b/src/runtime/runtime_wasm.go @@ -2,6 +2,10 @@ package runtime +import ( + "unsafe" +) + type timeUnit int64 const tickMicros = 1 @@ -48,3 +52,11 @@ func ticks() timeUnit { func abort() { trap() } + +//go:export memset +func memset(ptr unsafe.Pointer, c byte, size uintptr) unsafe.Pointer { + for i := uintptr(0); i < size; i++ { + *(*byte)(unsafe.Pointer(uintptr(ptr) + i)) = c + } + return ptr +}