From f4e837a6f78d7409383ed3af2c0600599cf48252 Mon Sep 17 00:00:00 2001 From: Mark Stevens Date: Wed, 14 Oct 2026 18:36:11 +0100 Subject: [PATCH 1/3] Drop the SDRAM cache hook from mono_file_map_open The NuttX 7 firmware tracked open assembly files so its mmap replacement could cache them in SDRAM. Meadow.OS on NuttX 12 serves file mmap with CONFIG_FS_RAMMAP and no longer provides sdram_cache_track_fd. Co-Authored-By: Claude Opus 5.5 --- src/mono/mono/utils/mono-filemap.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/mono/mono/utils/mono-filemap.c b/src/mono/mono/utils/mono-filemap.c index 4d7cd5f96b896a..0c4ac46a5b4970 100644 --- a/src/mono/mono/utils/mono-filemap.c +++ b/src/mono/mono/utils/mono-filemap.c @@ -40,11 +40,6 @@ mono_file_map_open (const char* name) int fd = open (name, O_RDONLY); if (fd < 0) return NULL; -#ifdef HOST_NUTTX - /* Track fd→path mapping for SDRAM cache in mmap stub */ - extern void sdram_cache_track_fd(int fd, const char *path); - sdram_cache_track_fd (fd, name); -#endif return (MonoFileMap *)(size_t)fd; #endif } From 6b2b6b97cf9e8a624d27b7f1ddf2297412f79769 Mon Sep 17 00:00:00 2001 From: Mark Stevens Date: Wed, 14 Oct 2026 18:36:11 +0100 Subject: [PATCH 2/3] Notify the socket layer when System.Native closes a descriptor on NuttX Call nxsock_close_notify before close() in SystemNative_Close. This replaces the firmware's --wrap close, which applied to the whole user image. Co-Authored-By: Claude Opus 5.5 --- src/native/libs/System.Native/pal_io.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/native/libs/System.Native/pal_io.c b/src/native/libs/System.Native/pal_io.c index 7c1d8af3b417c4..1af3c4b080d256 100644 --- a/src/native/libs/System.Native/pal_io.c +++ b/src/native/libs/System.Native/pal_io.c @@ -14,6 +14,7 @@ #include #ifdef __NuttX__ #include "pal_io_nuttx.h" +#include "pal_networking.h" // nxsock_close_notify #else #include #endif @@ -394,6 +395,10 @@ int32_t SystemNative_Close(intptr_t fd) // do it here. Harmless for non-socket fds (ENOTSOCK) and already-shutdown // sockets (ENOTCONN). shutdown(rawFd, SHUT_RDWR); + + // Remove the fd from the SocketAsyncEngine poll() emulation before it is + // closed (see nxsock_close_notify in pal_networking.c). Safe for any fd. + nxsock_close_notify(rawFd); #endif int result = close(rawFd); From 4e67a4b2ebe0ebe6600875f8cf2cbe2656c7809b Mon Sep 17 00:00:00 2001 From: Mark Stevens Date: Wed, 14 Oct 2026 18:36:11 +0100 Subject: [PATCH 3/3] Do not cache the thread ID in thread-local storage on NuttX NuttX user space has no TLS support: __aeabi_read_tp is only provided in the kernel, so the _Thread_local cache in minipal_get_current_thread_id fails to link in a protected build. Co-Authored-By: Claude Opus 5.5 --- src/native/minipal/thread.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/native/minipal/thread.h b/src/native/minipal/thread.h index b626f9ddea6bf3..0c10ff84c298be 100644 --- a/src/native/minipal/thread.h +++ b/src/native/minipal/thread.h @@ -88,6 +88,11 @@ static inline size_t minipal_get_current_thread_id(void) #if defined(__wasm) && !defined(_REENTRANT) return minipal_get_current_thread_id_no_cache(); +#elif defined(__NuttX__) + // NuttX user space has no thread-local storage support (__aeabi_read_tp is + // only provided in the kernel), so do not cache the ID. + return minipal_get_current_thread_id_no_cache(); + #else // !__wasm || _REENTRANT #if defined(__GNUC__) && !defined(__clang__) && defined(__cplusplus) // gcc doesn't like _Thread_local when __cplusplus is defined.