From ccee1552b789cc0451ee86171af45d31a3d87785 Mon Sep 17 00:00:00 2001 From: BCG Date: Thu, 26 Mar 2020 22:26:03 -0400 Subject: [PATCH 1/2] Added malloc and free implementations for calling from C --- src/runtime/runtime_libc.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/runtime/runtime_libc.go diff --git a/src/runtime/runtime_libc.go b/src/runtime/runtime_libc.go new file mode 100644 index 0000000000..af40cb61d7 --- /dev/null +++ b/src/runtime/runtime_libc.go @@ -0,0 +1,15 @@ +// +build baremetal + +package runtime + +import "unsafe" + +//go:export malloc +func libc_malloc(size uintptr) unsafe.Pointer { + return alloc(size) +} + +//go:export free +func libc_free(ptr unsafe.Pointer) { + free(ptr) +} From 88741f5a237df09cd31541b595e7664489925d0b Mon Sep 17 00:00:00 2001 From: BCG Date: Mon, 30 Mar 2020 07:41:46 -0400 Subject: [PATCH 2/2] moved malloc and free functions to src/runtime/baremetal.go --- src/runtime/baremetal.go | 10 ++++++++++ src/runtime/runtime_libc.go | 15 --------------- 2 files changed, 10 insertions(+), 15 deletions(-) delete mode 100644 src/runtime/runtime_libc.go diff --git a/src/runtime/baremetal.go b/src/runtime/baremetal.go index 892aff9236..8256720198 100644 --- a/src/runtime/baremetal.go +++ b/src/runtime/baremetal.go @@ -28,3 +28,13 @@ var ( globalsEnd = uintptr(unsafe.Pointer(&globalsEndSymbol)) stackTop = uintptr(unsafe.Pointer(&stackTopSymbol)) ) + +//export malloc +func libc_malloc(size uintptr) unsafe.Pointer { + return alloc(size) +} + +//export free +func libc_free(ptr unsafe.Pointer) { + free(ptr) +} diff --git a/src/runtime/runtime_libc.go b/src/runtime/runtime_libc.go deleted file mode 100644 index af40cb61d7..0000000000 --- a/src/runtime/runtime_libc.go +++ /dev/null @@ -1,15 +0,0 @@ -// +build baremetal - -package runtime - -import "unsafe" - -//go:export malloc -func libc_malloc(size uintptr) unsafe.Pointer { - return alloc(size) -} - -//go:export free -func libc_free(ptr unsafe.Pointer) { - free(ptr) -}