C++ constructors work with ELF load now

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5273 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2012-10-29 19:32:05 +00:00
parent 0f70f8c9e1
commit ef6dcd6f90
22 changed files with 618 additions and 389 deletions
+66 -10
View File
@@ -1,7 +1,7 @@
/****************************************************************************
* binfmt/binfmt_loadmodule.c
*
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
* Copyright (C) 2009, 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -67,6 +67,39 @@
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: exec_dtors
*
* Description:
* Execute C++ static constructors.
*
* Input Parameters:
* loadinfo - Load state information
*
* Returned Value:
* 0 (OK) is returned on success and a negated errno is returned on
* failure.
*
****************************************************************************/
#ifdef CONFIG_BINFMT_CONSTRUCTORS
static inline void exec_dtors(FAR const struct binary_s *binp)
{
elf_dtor_t *dtor = binp->dtors;
int i;
/* Execute each destructor */
for (i = 0; i < binp->ndtors; i++)
{
bvdbg("Calling dtor %d at %p\n", i, (FAR void *)dtor);
(*dtor)();
dtor++;
}
}
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -76,7 +109,12 @@
*
* Description:
* Unload a (non-executing) module from memory. If the module has
* been started (via exec_module), calling this will be fatal.
* been started (via exec_module) and has not exited, calling this will
* be fatal.
*
* However, this function must be called after the module exist. How
* this is done is up to your logic. Perhaps you register it to be
* called by on_exit()?
*
* Returned Value:
* This is a NuttX internal function so it follows the convention that
@@ -85,22 +123,40 @@
*
****************************************************************************/
int unload_module(FAR const struct binary_s *bin)
int unload_module(FAR const struct binary_s *binp)
{
if (bin)
int i;
if (binp)
{
if (bin->ispace)
/* Execute C++ desctructors */
#ifdef CONFIG_BINFMT_CONSTRUCTORS
exec_dtors(binp);
#endif
/* Unmap mapped address spaces */
if (binp->mapped)
{
bvdbg("Unmapping ISpace: %p\n", bin->ispace);
munmap(bin->ispace, bin->isize);
bvdbg("Unmapping address space: %p\n", binp->mapped);
munmap(binp->mapped, binp->mapsize);
}
if (bin->dspace)
/* Free allocated address spaces */
for (i = 0; i < BINFMT_NALLOC; i++)
{
bvdbg("Freeing DSpace: %p\n", bin->dspace);
free(bin->dspace);
if (binp->alloc[i])
{
bvdbg("Freeing alloc[%d]: %p\n", i, binp->alloc[i]);
free(binp->alloc[i]);
}
}
}
return OK;
}