From 4c9d70f03f6c90aa28799f0f5b5467e3280498c6 Mon Sep 17 00:00:00 2001 From: Jamie Smith Date: Wed, 20 Sep 2023 18:56:51 -0700 Subject: [PATCH 1/2] Fix warnings from kill and getpid not being implemented --- platform/source/mbed_retarget.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/platform/source/mbed_retarget.cpp b/platform/source/mbed_retarget.cpp index 6e10dcd4d77..fdf519844ac 100644 --- a/platform/source/mbed_retarget.cpp +++ b/platform/source/mbed_retarget.cpp @@ -1464,6 +1464,10 @@ extern "C" WEAK void __cxa_pure_virtual(void) // SP. This make it compatible with RTX RTOS thread stacks. #if defined(TOOLCHAIN_GCC_ARM) +// Turn off the errno macro and use actual global variable instead. +#undef errno +extern "C" int errno; + #if defined(MBED_SPLIT_HEAP) // Default RAM memory used for heap @@ -1506,10 +1510,6 @@ extern "C" WEAK caddr_t _sbrk(int incr) extern "C" uint32_t __end__; extern "C" uint32_t __HeapLimit; -// Turn off the errno macro and use actual global variable instead. -#undef errno -extern "C" int errno; - // Weak attribute allows user to override, e.g. to use external RAM for dynamic memory. extern "C" WEAK caddr_t _sbrk(int incr) { @@ -1529,6 +1529,25 @@ extern "C" WEAK caddr_t _sbrk(int incr) #endif #endif +#if defined(TOOLCHAIN_GCC_ARM) + +// Implementation of getpid for Newlib, following signature here: +// https://github.com/bminor/newlib/blob/55485616ba2afedca05da40f5cde59ee336b9f28/newlib/libc/sys/arm/syscalls.c#L32 +extern "C" pid_t _getpid() +{ + // Since PIDs aren't a thing on embedded, just return 0 + return 0; +} + +extern "C" int _kill(int pid, int signal) +{ + // Always return error + errno = ENOSYS; + return -1; +} + +#endif + #if defined(TOOLCHAIN_GCC_ARM) extern "C" void _exit(int return_code) { From 54dd89fb3b4b4701d04ce198162df1c31192e2ea Mon Sep 17 00:00:00 2001 From: Jamie Smith Date: Wed, 20 Sep 2023 21:38:53 -0700 Subject: [PATCH 2/2] Fix comments --- platform/source/mbed_retarget.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platform/source/mbed_retarget.cpp b/platform/source/mbed_retarget.cpp index fdf519844ac..f052eec9302 100644 --- a/platform/source/mbed_retarget.cpp +++ b/platform/source/mbed_retarget.cpp @@ -1531,7 +1531,7 @@ extern "C" WEAK caddr_t _sbrk(int incr) #if defined(TOOLCHAIN_GCC_ARM) -// Implementation of getpid for Newlib, following signature here: +// Implementation of getpid for Newlib, following signature here: // https://github.com/bminor/newlib/blob/55485616ba2afedca05da40f5cde59ee336b9f28/newlib/libc/sys/arm/syscalls.c#L32 extern "C" pid_t _getpid() { @@ -1539,6 +1539,8 @@ extern "C" pid_t _getpid() return 0; } +// Implementation of kill for Newlib, following signature here: +// https://github.com/bminor/newlib/blob/55485616ba2afedca05da40f5cde59ee336b9f28/newlib/libc/sys/arm/syscalls.c#L33 extern "C" int _kill(int pid, int signal) { // Always return error