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

loadable exception support #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/examples/hello/hello_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ int main(int argc, FAR char *argv[])
int hello_main(int argc, char *argv[])
#endif
{
printf("Hello, World!!\n");
int b;
printf("Hello, World!! %d\n", __gnu_Unwind_Find_exidx(0, &b));
return 0;
}
20 changes: 19 additions & 1 deletion apps/examples/helloxx/helloxx_main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,21 @@ static CHelloWorld g_HelloWorld;
* Name: helloxx_main
****************************************************************************/

static void test_exception(void)
{
printf("============ Test Exception =============================\n");
try
{
throw 5;
}

catch (int e)
{
printf("Catch exception\n");
}
}


extern "C"
{
int helloxx_main(int argc, char *argv[])
Expand Down Expand Up @@ -172,8 +187,11 @@ extern "C"
printf("helloxx_main: Saying hello from the statically constructed instance\n");
g_HelloWorld.HelloWorld();
#endif

delete pHelloWorld;

test_exception();

return 0;
}
}
4 changes: 4 additions & 0 deletions apps/platform/gnu/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ ifeq ($(CONFIG_HAVE_CXXINITIALIZE),y)
CSRCS += gnu_cxxinitialize.c
endif

ifeq ($(CONFIG_LIBCXX_EXCEPTION),y)
CSRCS += gnu_unwind_find_exidx.c
endif

# Add the gnu/ sub-directory to the build

VPATH += :gnu
Expand Down
56 changes: 56 additions & 0 deletions apps/platform/gnu/gnu_unwind_find_exidx.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/****************************************************************************
*
* Copyright 2023 Samsung Electronics All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/

/****************************************************************************
* Included Files
****************************************************************************/

#include <stdbool.h>
#include <elf32.h>
#include <tinyara/elf.h>

#include <unwind.h>

/****************************************************************************
* Private Data
****************************************************************************/

extern void *__exidx_start;
extern void *__exidx_end;

/****************************************************************************
* Public Functions
****************************************************************************/

/****************************************************************************
* Name: __gnu_Unwind_Find_exidx
*
* Description:
* This function is called (if exists) by the gcc generated unwind
* run-time in order to retrieve an alternative .ARM.exidx Exception
* index section.
* This is the case for an ELF module loaded by the elf binary loader.
* It is needed to support exception handling for loadable ELF modules.
*
****************************************************************************/

_Unwind_Ptr __gnu_Unwind_Find_exidx(_Unwind_Ptr return_address, int *nrecp)
{
*nrecp = &__exidx_end - &__exidx_start;
return (_Unwind_Ptr)&__exidx_start;
}
Loading