mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
891eb3b020
Since in b0491307
, which has introduced the optimized window spill
procedure, _xt_context_save did not work correctly when called from
_xt_syscall_exc. This was because unlike _xt_lowint1, _xt_syscall_exc
does not save PS and EPC1. The new version of _xt_context_save
modified PS (on purpose) and EPC1 (accidentally, due to window
overflow exceptions), which resulted in a crash upon 'rfi' from the
syscall.
This commit adds restoring of PS and EPC1 in _xt_context_save. It also
slightly reduces the number of instructions used to prepare PS for
window spill.
Unit test for setjmp/longjmp (which were broken by this regression)
is added.
Closes https://github.com/espressif/esp-idf/issues/4541
36 lines
812 B
C
36 lines
812 B
C
#include <setjmp.h>
|
|
#include <stdio.h>
|
|
#include "unity.h"
|
|
#include "esp_system.h"
|
|
|
|
|
|
typedef struct {
|
|
jmp_buf jmp_env;
|
|
uint32_t retval;
|
|
volatile bool inner_called;
|
|
} setjmp_test_ctx_t;
|
|
|
|
static __attribute__((noreturn)) void inner(setjmp_test_ctx_t *ctx)
|
|
{
|
|
printf("inner, retval=0x%x\n", ctx->retval);
|
|
ctx->inner_called = true;
|
|
longjmp(ctx->jmp_env, ctx->retval);
|
|
TEST_FAIL_MESSAGE("Should not reach here");
|
|
}
|
|
|
|
TEST_CASE("setjmp and longjmp", "[newlib]")
|
|
{
|
|
const uint32_t expected = 0x12345678;
|
|
setjmp_test_ctx_t ctx = {
|
|
.retval = expected
|
|
};
|
|
uint32_t ret = setjmp(ctx.jmp_env);
|
|
if (!ctx.inner_called) {
|
|
TEST_ASSERT_EQUAL(0, ret);
|
|
inner(&ctx);
|
|
} else {
|
|
TEST_ASSERT_EQUAL(expected, ret);
|
|
}
|
|
TEST_ASSERT(ctx.inner_called);
|
|
}
|