File 0389-erts-Fix-ASSERT_IN_ENV-for-dirty-NIFs.patch of Package erlang

From abacfe437343ae27ac7c3ab6f837ed7b9aae94d4 Mon Sep 17 00:00:00 2001
From: Sverker Eriksson <sverker@erlang.org>
Date: Thu, 25 Mar 2021 20:47:54 +0100
Subject: [PATCH] erts: Fix ASSERT_IN_ENV for dirty NIFs

---
 erts/emulator/beam/erl_nif.c | 27 +++++++++++++++++++--------
 1 file 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;
-- 
2.26.2

openSUSE Build Service is sponsored by