10000 Ets intr lock nest by ChocolateFrogsNuts · Pull Request #6484 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content

Ets intr lock nest #6484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Replace the SDK's use of ets_intr_lock/unlock with nestable versions
Testing has shown that there are several paths in the SDK that result in nested
calls to ets_intr_lock() / ets_intr_unlock() which may be a problem.

These functions also do not preserve the enabled interrupt level and may
result in code running with interrupts enabled when that is not intended.
This issue has recently been fixed in the Arduino code by using
xt_rsil() / xt_wsr_ps() but still exists in the Espressif SDK code.

This commit is intended to fix that and should be used in addition to the above.

The maximum nesting I have seen is 2 and lock/unlock calls appear to be balanced.
A max of 7 levels of nesting leaves plenty of room for that to change.
  • Loading branch information
ChocolateFrogsNuts committed Sep 1, 2019
commit 5f9281f71592d51e85a5386c06367d9f353de933
18 changes: 18 additions & 0 deletions cores/esp8266/core_esp8266_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ static os_event_t s_loop_queue[LOOP_QUEUE_SIZE];
/* Used to implement optimistic_yield */
static uint32_t s_micros_at_task_start;

/* For ets_intr_lock_nest / ets_intr_unlock_nest
* Max nesting seen by SDK so far is 2.
*/
#define ETS_INTR_LOCK_NEST_MAX 7
byte ets_intr_lock_stack[ETS_INTR_LOCK_NEST_MAX];
byte ets_intr_lock_stack_ptr=0;


extern "C" {
extern const uint32_t __attribute__((section(".ver_number"))) core_version = ARDUINO_ESP8266_GIT_VER;
Expand Down Expand Up @@ -121,6 +128,17 @@ extern "C" void optimistic_yield(uint32_t interval_us) {
}
}

extern "C" void ets_intr_lock_nest() {
if (ets_intr_lock_stack_ptr < ETS_INTR_LOCK_NEST_MAX)
ets_intr_lock_stack[ets_intr_lock_stack_ptr++] = xt_rsil(3);
}

extern "C" void ets_intr_unlock_nest() {
if (ets_intr_lock_stack_ptr > 0)
xt_wsr_ps(ets_intr_lock_stack[--ets_intr_lock_stack_ptr]);
}


extern "C" void __loop_end (void)
{
run_scheduled_functions();
Expand Down
7 changes: 7 additions & 0 deletions tools/sdk/lib/fix_sdk_libs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ xtensa-lx106-elf-objcopy --redefine-sym default_hostname=wifi_station_default_ho
xtensa-lx106-elf-objcopy --redefine-sym default_hostname=wifi_station_default_hostname eagle_lwip_if.o
xtensa-lx106-elf-ar r libmain.a eagle_lwip_if.o user_interface.o
rm -f eagle_lwip_if.o user_interface.o

# Replace use of ROM ets_intr_(un)lock with nestable ets_intr_(un)lock_nest
for f in libmain.a libpp.a libnet80211.a; do
xtensa-lx106-elf-objcopy --redefine-sym ets_intr_lock=ets_intr_lock_nest $f;
xtensa-lx106-elf-objcopy --redefine-sym ets_intr_unlock=ets_intr_unlock_nest $f;
done

0