Checks whether the RTC log state is consistent: rtcLogMagic must equal LOG_RTC_MAGIC and logHead must be in 0..MAX_LOG_LINES-1. Returns true if corruption is detected, in which case rtcLogMagic is still invalid and logMessages may contain garbage. Callers (e.g. HalSystem::begin on the panic-reboot path) must call clearLastLogs() after a true result to fully reinitialize the ring buffer and stamp t
| 87 | // panic-reboot path) must call clearLastLogs() after a true result to fully |
| 88 | // reinitialize the ring buffer and stamp the magic before getLastLogs() is used. |
| 89 | bool sanitizeLogHead() { |
| 90 | if (rtcLogMagic != LOG_RTC_MAGIC || logHead >= MAX_LOG_LINES) { |
| 91 | logHead = 0; |
| 92 | return true; |
| 93 | } |
| 94 | return false; |
| 95 | } |
| 96 | |
| 97 | void clearLastLogs() { |
| 98 | for (size_t i = 0; i < MAX_LOG_LINES; i++) { |