fix(admin): stop the admin dispatcher from overflowing the ESP32 loopTask stack (#11239)
AdminModule::handleReceivedProtobuf carried a 3008-byte stack frame - 37% of the 8 KB Arduino loopTask stack. GCC inlines the eight handleGet* helpers into it, each of which builds a whole meshtastic_AdminMessage (480 B), so the dispatcher reserved a slot for every one of them at once even though only one case ever runs. Two more full AdminMessages lived directly in the function. That left any admin write short of stack for what runs beneath it: NodeDB::saveToDisk -> saveProto -> pb_encode -> SafeFile -> LittleFS -> flash. On heltec-v4 the canary fired at 7824 of 8192 bytes while writing /prefs/config.proto, so no setting ever persisted and the device rebooted. Mark the response builders NOINLINE and move the module-API and observer responses into their own functions. Pure refactor; measured on heltec-v4 the dispatcher frame drops 3008 -> 384 bytes, taking the crashing path from 368 bytes of headroom to 2992. Fixes #11237
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <esp_ota_ops.h>
|
||||
#endif
|
||||
#include "ProtobufModule.h"
|
||||
#include "meshUtils.h"
|
||||
#include <sys/types.h>
|
||||
#if HAS_WIFI
|
||||
#include "mesh/wifi/WiFiAPClient.h"
|
||||
@@ -48,16 +49,24 @@ class AdminModule : public ProtobufModule<meshtastic_AdminMessage>, public Obser
|
||||
|
||||
/**
|
||||
* Getters
|
||||
*
|
||||
* Each of the NOINLINE ones below builds a whole meshtastic_AdminMessage (480 bytes) on the
|
||||
* stack. They are only ever reached from one case of handleReceivedProtobuf()'s switch, but
|
||||
* when the compiler inlines them the dispatcher's frame has to reserve a slot for every one of
|
||||
* them at once - measured at 3008 bytes on ESP32-S3, 37% of the 8 KB Arduino loopTask stack
|
||||
* that also has to carry PhoneAPI, the router, nanopb and LittleFS below it. Keeping them out
|
||||
* of line means only the request actually being served pays for its response buffer.
|
||||
* See issue #11237.
|
||||
*/
|
||||
void handleGetModuleConfigResponse(const meshtastic_MeshPacket &req, meshtastic_AdminMessage *p);
|
||||
void handleGetOwner(const meshtastic_MeshPacket &req);
|
||||
void handleGetConfig(const meshtastic_MeshPacket &req, uint32_t configType);
|
||||
void handleGetModuleConfig(const meshtastic_MeshPacket &req, uint32_t configType);
|
||||
void handleGetChannel(const meshtastic_MeshPacket &req, uint32_t channelIndex);
|
||||
void handleGetDeviceMetadata(const meshtastic_MeshPacket &req);
|
||||
void handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &req);
|
||||
void handleGetNodeRemoteHardwarePins(const meshtastic_MeshPacket &req);
|
||||
void handleGetDeviceUIConfig(const meshtastic_MeshPacket &req);
|
||||
NOINLINE void handleGetOwner(const meshtastic_MeshPacket &req);
|
||||
NOINLINE void handleGetConfig(const meshtastic_MeshPacket &req, uint32_t configType);
|
||||
NOINLINE void handleGetModuleConfig(const meshtastic_MeshPacket &req, uint32_t configType);
|
||||
NOINLINE void handleGetChannel(const meshtastic_MeshPacket &req, uint32_t channelIndex);
|
||||
NOINLINE void handleGetDeviceMetadata(const meshtastic_MeshPacket &req);
|
||||
NOINLINE void handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &req);
|
||||
NOINLINE void handleGetNodeRemoteHardwarePins(const meshtastic_MeshPacket &req);
|
||||
NOINLINE void handleGetDeviceUIConfig(const meshtastic_MeshPacket &req);
|
||||
/**
|
||||
* Setters
|
||||
*/
|
||||
@@ -102,6 +111,13 @@ class AdminModule : public ProtobufModule<meshtastic_AdminMessage>, public Obser
|
||||
/// Whether a response (variant responseVariant, module-config subtype moduleConfigTag or 0)
|
||||
/// from mp.from answers a request we sent; consumes the matched request so it can't be replayed.
|
||||
bool responseIsSolicited(const meshtastic_MeshPacket &mp, pb_size_t responseVariant, pb_size_t moduleConfigTag);
|
||||
|
||||
/// Offer an admin message we have no case for to the module API, and let observers (e.g. the UI)
|
||||
/// see every admin message. Both build a response on the stack, so like the getters above they
|
||||
/// stay out of line to keep handleReceivedProtobuf()'s frame small.
|
||||
NOINLINE void handleViaModuleApi(const meshtastic_MeshPacket &mp, meshtastic_AdminMessage *r);
|
||||
NOINLINE void handleViaObservers(const meshtastic_AdminMessage *r);
|
||||
|
||||
void handleStoreDeviceUIConfig(const meshtastic_DeviceUIConfig &uicfg);
|
||||
void handleSendInputEvent(const meshtastic_AdminMessage_InputEvent &inputEvent);
|
||||
void reboot(int32_t seconds);
|
||||
|
||||
Reference in New Issue
Block a user