2012-11-01 17:50:53 +01:00
|
|
|
//***************************************************************************
|
2018-05-29 21:21:26 +02:00
|
|
|
// libs/libxx/libxx_eabi_atexit.cxx
|
2012-11-01 17:50:53 +01:00
|
|
|
//
|
2021-02-23 19:12:11 +01:00
|
|
|
// Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
// contributor license agreements. See the NOTICE file distributed with
|
|
|
|
// this work for additional information regarding copyright ownership. The
|
|
|
|
// ASF licenses this file to you 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
|
2012-11-01 17:50:53 +01:00
|
|
|
//
|
2021-02-23 19:12:11 +01:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2012-11-01 17:50:53 +01:00
|
|
|
//
|
2021-02-23 19:12:11 +01:00
|
|
|
// 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
|
2012-11-01 17:50:53 +01:00
|
|
|
//
|
|
|
|
//***************************************************************************
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
// Included Files
|
|
|
|
//***************************************************************************
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <cassert>
|
2021-08-29 15:36:24 +02:00
|
|
|
#include <nuttx/lib/lib.h>
|
2012-11-01 17:50:53 +01:00
|
|
|
|
2015-12-30 14:56:56 +01:00
|
|
|
#include "libxx.hxx"
|
2012-11-01 17:50:53 +01:00
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
// Pre-processor Definitions
|
|
|
|
//***************************************************************************
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
// Private Types
|
|
|
|
//***************************************************************************
|
|
|
|
|
|
|
|
struct __cxa_atexit_s
|
|
|
|
{
|
|
|
|
__cxa_exitfunc_t func;
|
|
|
|
FAR void *arg;
|
|
|
|
};
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
// Private Data
|
|
|
|
//***************************************************************************
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
//*************************************************************************
|
|
|
|
// Public Data
|
|
|
|
//*************************************************************************
|
|
|
|
|
2020-07-08 05:19:14 +02:00
|
|
|
FAR void *__dso_handle = &__dso_handle;
|
2012-11-01 17:50:53 +01:00
|
|
|
|
|
|
|
//*************************************************************************
|
|
|
|
// Private Functions
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
|
|
//*************************************************************************
|
|
|
|
// Name: __cxa_callback
|
|
|
|
//
|
|
|
|
// Description:
|
|
|
|
// This is really just an "adaptor" function that matches the form of
|
|
|
|
// the __cxa_exitfunc_t to an onexitfunc_t using an allocated structure
|
|
|
|
// to marshall the call parameters.
|
|
|
|
//
|
|
|
|
//*************************************************************************
|
|
|
|
|
2015-09-01 15:04:09 +02:00
|
|
|
#ifdef CONFIG_SCHED_ONEXIT
|
2012-11-01 17:50:53 +01:00
|
|
|
static void __cxa_callback(int exitcode, FAR void *arg)
|
|
|
|
{
|
|
|
|
FAR struct __cxa_atexit_s *alloc = (FAR struct __cxa_atexit_s *)arg;
|
|
|
|
DEBUGASSERT(alloc && alloc->func);
|
|
|
|
|
|
|
|
alloc->func(alloc->arg);
|
2013-03-09 22:12:20 +01:00
|
|
|
lib_free(alloc);
|
2012-11-01 17:50:53 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//*************************************************************************
|
|
|
|
// Public Functions
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
|
|
//*************************************************************************
|
|
|
|
// Name: __cxa_atexit
|
|
|
|
//
|
|
|
|
// Description:
|
|
|
|
// __cxa_atexit() registers a destructor function to be called by exit().
|
|
|
|
// On a call to exit(), the registered functions should be called with
|
|
|
|
// the single argument 'arg'. Destructor functions shall always be
|
|
|
|
// called in the reverse order to their registration (i.e. the most
|
|
|
|
// recently registered function shall be called first),
|
|
|
|
//
|
|
|
|
// If shared libraries were supported, the callbacks should be invoked
|
|
|
|
// when the shared library is unloaded as well.
|
|
|
|
//
|
|
|
|
// Reference:
|
|
|
|
// Linux base
|
|
|
|
//
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
|
|
int __cxa_atexit(__cxa_exitfunc_t func, FAR void *arg, FAR void *dso_handle)
|
|
|
|
{
|
2015-09-01 15:04:09 +02:00
|
|
|
#ifdef CONFIG_SCHED_ONEXIT
|
2012-11-01 17:50:53 +01:00
|
|
|
// Allocate memory to hold the marshaled __cxa_exitfunc_t call
|
|
|
|
// information.
|
|
|
|
|
|
|
|
FAR struct __cxa_atexit_s *alloc =
|
2013-03-09 22:12:20 +01:00
|
|
|
(FAR struct __cxa_atexit_s *)lib_malloc(sizeof(struct __cxa_atexit_s));
|
2012-11-01 17:50:53 +01:00
|
|
|
|
|
|
|
if (alloc)
|
|
|
|
{
|
|
|
|
// Register the function to be called when the task/thread exists.
|
|
|
|
|
2012-11-01 22:08:56 +01:00
|
|
|
alloc->func = func;
|
|
|
|
alloc->arg = arg;
|
|
|
|
|
2012-11-01 17:50:53 +01:00
|
|
|
return on_exit(__cxa_callback, alloc);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
// What else can we do?
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|