Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 521ae60

Browse filesBrowse files
authored
Fix for dangerous relocation: j: cannot encode (esp8266#8925)
Fixes to recent changes to Postmortem to cover large jump offsets, use relaxed jump (J.L) in __wrap_system_restart_local. Also add check that epc1 is a valid code address before reading.
1 parent 8b33e2e commit 521ae60
Copy full SHA for 521ae60

File tree

Expand file treeCollapse file tree

1 file changed

+6
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+6
-2
lines changed

‎cores/esp8266/core_esp8266_postmortem.cpp

Copy file name to clipboardExpand all lines: cores/esp8266/core_esp8266_postmortem.cpp
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ static void cut_here() {
110110
ets_putc('\n');
111111
}
112112

113+
static inline bool is_pc_valid(uint32_t pc) {
114+
return pc >= XCHAL_INSTRAM0_VADDR && pc < (XCHAL_INSTROM0_VADDR + XCHAL_INSTROM0_SIZE);
115+
}
116+
113117
/*
114118
Add some assembly to grab the stack pointer and pass it as an argument before
115119
it grows for the target function. Should stabilize the stack offsets, used to
@@ -125,7 +129,7 @@ asm(
125129
"\n"
126130
"__wrap_system_restart_local:\n\t"
127131
"mov a2, a1\n\t"
128-
"j postmortem_report\n\t"
132+
"j.l postmortem_report, a3\n\t"
129133
".size __wrap_system_restart_local, .-__wrap_system_restart_local\n\t"
130134
);
131135

@@ -183,7 +187,7 @@ static void postmortem_report(uint32_t sp_dump) {
183187
else if (rst_info.reason == REASON_SOFT_WDT_RST) {
184188
ets_printf_P(PSTR("\nSoft WDT reset"));
185189
const char infinite_loop[] = { 0x06, 0xff, 0xff }; // loop: j loop
186-
if (0 == memcmp_P(infinite_loop, (PGM_VOID_P)rst_info.epc1, 3u)) {
190+
if (is_pc_valid(rst_info.epc1) && 0 == memcmp_P(infinite_loop, (PGM_VOID_P)rst_info.epc1, 3u)) {
187191
// The SDK is riddled with these. They are usually preceded by an ets_printf.
188192
ets_printf_P(PSTR(" - deliberate infinite loop detected"));
189193
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.