Skip to content

apps/system/init: Add C++ terminate handler support#7143

Merged
sunghan-chang merged 3 commits intoSamsung:masterfrom
pcs1265:260203_cxx_terminate_handler
Feb 10, 2026
Merged

apps/system/init: Add C++ terminate handler support#7143
sunghan-chang merged 3 commits intoSamsung:masterfrom
pcs1265:260203_cxx_terminate_handler

Conversation

@pcs1265
Copy link
Copy Markdown
Member

@pcs1265 pcs1265 commented Feb 3, 2026

This patch adds global terminate handler for unhandled C++ exceptions. The handler will print exception information and call PANIC() when an unhandled exception occurs.

and Corrected a typo in init.c

This PR includes defconfig modification to fix CI build error.

Comment thread apps/system/init/terminate_handler.cxx Outdated
static void __global_terminate_handler(void)
{
if (!IS_SECURE_STATE()) {
sched_lock();
Copy link
Copy Markdown
Member Author

@pcs1265 pcs1265 Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please share your opinion that sched_lock is needed here or not

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, sched_lock isn’t necessary.
However, if we’re going to handle it with PANIC() anyway, it seems worthwhile to ensure that this thread can operate without being preempted by other threads.
On the other hand, depending on the config, the system might not reset after a PANIC(), so it should be paired with sched_unlock.

@pcs1265 pcs1265 force-pushed the 260203_cxx_terminate_handler branch 2 times, most recently from 21ca162 to f48776f Compare February 3, 2026 03:24
@sunghan-chang
Copy link
Copy Markdown
Contributor

@aashish-l @amandeep-samsung Could you review this?

@pcs1265 pcs1265 force-pushed the 260203_cxx_terminate_handler branch 2 times, most recently from 7bffa95 to 2c72f82 Compare February 3, 2026 08:48
if (!IS_SECURE_STATE()) {
sched_lock();

#ifdef CONFIG_LIBCXX_EXCEPTION
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using #if defined(CONFIG_LIBCXX_EXCEPTION) && defined(__EXCEPTIONS).
__EXCEPTIONS is defined when -fexceptions is enabled.

Comment thread apps/system/init/terminate_handler.cxx Outdated
{
printf("C++ terminate handler called! PID: %d\n", getpid());
if (!IS_SECURE_STATE()) {
sched_lock();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have an one simple question, All log in try-catch must be printed out totally. can we guarantee it by sched_lock ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In SMP configuration, We can't.
If assert or panic occur on other core while terminate_handler printing logs, the log will be lost.

@pcs1265 pcs1265 force-pushed the 260203_cxx_terminate_handler branch 7 times, most recently from 5df8dce to b525ea4 Compare February 9, 2026 09:51
This patch adds global terminate handler for unhandled C++ exceptions.
The handler will print exception information and call PANIC() when
an unhandled exception occurs.

and Corrected a typo in `init.c`
artik055s/audio enables LIBCXX_EXCEPTION. but Make.defs does not accept that so fix the mismatching Make.defs

and Exception handling requires newer toolchain version. so update defconfig to use 2.0.0 docker image.
…defconfig

  This PR does fetch for DOCKER version defined in corresponding defconfig file.
  and apply fetched DOCKER version for CI build configuration.
@pcs1265 pcs1265 force-pushed the 260203_cxx_terminate_handler branch from b525ea4 to f40f488 Compare February 10, 2026 02:33
Comment thread apps/system/init/terminate_handler.cxx
@sunghan-chang sunghan-chang merged commit 3a68fdf into Samsung:master Feb 10, 2026
17 checks passed
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

Successfully merging this pull request may close these issues.

5 participants