|
| 1 | +/**************************************************************************** |
| 2 | + * |
| 3 | + * Copyright 2026 Samsung Electronics All Rights Reserved. |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, |
| 12 | + * software distributed under the License is distributed on an |
| 13 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
| 14 | + * either express or implied. See the License for the specific |
| 15 | + * language governing permissions and limitations under the License. |
| 16 | + * |
| 17 | + ****************************************************************************/ |
| 18 | +/**************************************************************************** |
| 19 | + * Included Files |
| 20 | + ****************************************************************************/ |
| 21 | + |
| 22 | +#include <tinyara/config.h> |
| 23 | +#include <tinyara/security_level.h> |
| 24 | + |
| 25 | +#include <cstdio> |
| 26 | +#include <debug.h> |
| 27 | +#include <exception> |
| 28 | +#include <stdlib.h> |
| 29 | +#include <typeinfo> |
| 30 | +#include <sched.h> |
| 31 | + |
| 32 | + |
| 33 | +/**************************************************************************** |
| 34 | + * Private Functions |
| 35 | + ****************************************************************************/ |
| 36 | + |
| 37 | +static void __global_terminate_handler(void) |
| 38 | +{ |
| 39 | + if (!IS_SECURE_STATE()) { |
| 40 | + sched_lock(); |
| 41 | + printf("C++ terminate handler called! PID: %d\n", getpid()); |
| 42 | + |
| 43 | +#ifdef CONFIG_LIBCXX_EXCEPTION |
| 44 | + // Check if there's an active exception |
| 45 | + std::exception_ptr exptr = std::current_exception(); |
| 46 | + if (exptr) { |
| 47 | + try { |
| 48 | + std::rethrow_exception(exptr); |
| 49 | + } catch (const std::exception& e) { |
| 50 | + try { |
| 51 | + printf("Exception Type: %s\n", typeid(e).name()); |
| 52 | + printf("Exception Message: %s\n", e.what()); |
| 53 | + } catch (...) { |
| 54 | + printf("Exception info extraction failed\n"); |
| 55 | + } |
| 56 | + } catch (...) { |
| 57 | + printf("Unknown exception type\n"); |
| 58 | + } |
| 59 | + } else { |
| 60 | + printf("No active exception\n"); |
| 61 | + } |
| 62 | +#endif |
| 63 | + } |
| 64 | + |
| 65 | + PANIC(); |
| 66 | +} |
| 67 | + |
| 68 | +//*************************************************************************** |
| 69 | +// Public Functions |
| 70 | +//*************************************************************************** |
| 71 | + |
| 72 | +extern "C" void register_cxx_terminate_handler(void) |
| 73 | +{ |
| 74 | + std::set_terminate(__global_terminate_handler); |
| 75 | +} |
0 commit comments