Skip to content
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

exception handler intercepts c++ exceptions in the host on windows #3416

Open
malytomas opened this issue May 12, 2024 · 2 comments
Open

exception handler intercepts c++ exceptions in the host on windows #3416

malytomas opened this issue May 12, 2024 · 2 comments

Comments

@malytomas
Copy link

embedding wamr into c++ application, after initializing, the wamr spams into console with every c++ exception thrown (in the host), even if completely unrelated to wasm.

the logging happens on

LOG_ERROR("Unhandled exception thrown: exception code: 0x%lx, "

my understanding is that this handler is used for HW bounds checks, in which case it should ignore all other types of exceptions, and only log when actual issue has happened.

@TianlongLiang
Copy link
Contributor

So how about LOG_ERROR for the actual wasm exception and LOG_WARNING/LOG_VERBOSE to replace the log you are pointing out? And maybe add extra info like "unrecognized exception for wasm, pass to user's host exception handler" to explain the intention of return EXCEPTION_CONTINUE_SEARCH is to search for the next handler(transfer to the user's own handler). What do you think?

@malytomas
Copy link
Author

Hi, I have looked into the code in more detail now.

I would prefer to log a warning when inside wasm, and unknown exception code only. There is no point in logging anything if the exception is not related to the wasm, as such cases should be handled in other handlers. And no logging is necessary when the exception code is handled with wasm_set_exception.

diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c
index c6e9f0b9..3dbcc76d 100644
--- a/core/iwasm/common/wasm_runtime_common.c
+++ b/core/iwasm/common/wasm_runtime_common.c
@@ -384,12 +384,16 @@ runtime_exception_handler(EXCEPTION_POINTERS *exce_info)
                 return ret;
         }
 #endif
+        else {
+            LOG_WARNING("Unhandled exception thrown: "
+                        "exception code: 0x%lx, "
+                        "exception address: %p, "
+                        "exception information: %p\n",
+                        ExceptionRecord->ExceptionCode,
+                        ExceptionRecord->ExceptionAddress, sig_addr);
+        }
     }

-    LOG_ERROR("Unhandled exception thrown:  exception code: 0x%lx, "
-              "exception address: %p, exception information: %p\n",
-              ExceptionRecord->ExceptionCode, ExceptionRecord->ExceptionAddress,
-              sig_addr);
     return EXCEPTION_CONTINUE_SEARCH;
 }
 #endif /* end of BH_PLATFORM_WINDOWS */

Furthermore, It would be nice to have similar logging on linux, which currently does not log anything. However, I dont know if it is allowed to do so inside signal handler?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants