diff options
author | Sverker Eriksson <sverker@erlang.org> | 2021-03-25 20:47:54 +0100 |
---|---|---|
committer | Sverker Eriksson <sverker@erlang.org> | 2021-03-25 20:49:37 +0100 |
commit | abacfe437343ae27ac7c3ab6f837ed7b9aae94d4 (patch) | |
tree | 58b5ede210af585fde48ce925369664784b8cb7b | |
parent | 21a34505ea53378e770acd584eab1f02d8ee8cee (diff) | |
download | erlang-abacfe437343ae27ac7c3ab6f837ed7b9aae94d4.tar.gz |
erts: Fix ASSERT_IN_ENV for dirty NIFs
-rw-r--r-- | erts/emulator/beam/erl_nif.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/erts/emulator/beam/erl_nif.c b/erts/emulator/beam/erl_nif.c index 40ba7f1128..3181958498 100644 --- a/erts/emulator/beam/erl_nif.c +++ b/erts/emulator/beam/erl_nif.c @@ -5092,16 +5092,27 @@ static void dbg_assert_in_env(ErlNifEnv* env, Eterm term, real_htop = env->hp; } if (!erts_dbg_within_proc(ptr_val(term), env->proc, real_htop)) { - fprintf(stderr, "\r\nFAILED ASSERTION in %s:\r\n", func); - if (nr) { - fprintf(stderr, "Term #%d of the %s is not from same ErlNifEnv.", - nr, type); + int ok = 0; + if (env->proc->static_flags & ERTS_STC_FLG_SHADOW_PROC) { + Process* real_proc = env->proc->next; + ASSERT(real_proc); + erts_proc_lock(real_proc, ERTS_PROC_LOCK_MAIN); + ok = (ERTS_PROC_IS_EXITING(real_proc) + || erts_dbg_within_proc(ptr_val(term), real_proc, NULL)); + erts_proc_unlock(real_proc, ERTS_PROC_LOCK_MAIN); } - else { - fprintf(stderr, "The %s is not from the same ErlNifEnv.", type); + if (!ok) { + fprintf(stderr, "\r\nFAILED ASSERTION in %s:\r\n", func); + if (nr) { + fprintf(stderr, "Term #%d of the %s is not from same ErlNifEnv.", + nr, type); + } + else { + fprintf(stderr, "The %s is not from the same ErlNifEnv.", type); + } + fprintf(stderr, "\r\nABORTING\r\n"); + abort(); } - fprintf(stderr, "\r\nABORTING\r\n"); - abort(); } if (env->heap_frag) { env->heap_frag->used_size = saved_used_size; |