mirror of
https://github.com/apache/nuttx.git
synced 2026-06-04 23:03:27 +08:00
Add basic module management logic
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1894 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
+9
-2
@@ -35,14 +35,21 @@
|
|||||||
|
|
||||||
-include $(TOPDIR)/Make.defs
|
-include $(TOPDIR)/Make.defs
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_NXFLAT),y)
|
||||||
include libnxflat/Make.defs
|
include libnxflat/Make.defs
|
||||||
|
LIBNXFLAT_CSRCS += nxflat.c
|
||||||
|
endif
|
||||||
|
|
||||||
|
BINFMT_ASRCS =
|
||||||
|
BINFMT_CSRCS = binfmt_globals.c binfmt_register.c binfmt_unregister.c \
|
||||||
|
binfmt_loadmodule.c binfmt_unloadmodule.c binfmt_dumpmodule.c
|
||||||
|
|
||||||
SUBDIRS = libnxflat
|
SUBDIRS = libnxflat
|
||||||
|
|
||||||
ASRCS = $(LIBNXFLAT_ASRCS)
|
ASRCS = $(BINFMT_ASRCS) $(LIBNXFLAT_ASRCS)
|
||||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||||
|
|
||||||
CSRCS = nxflat.c $(LIBNXFLAT_CSRCS)
|
CSRCS = $(BINFMT_CSRCS) $(LIBNXFLAT_CSRCS)
|
||||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||||
|
|
||||||
SRCS = $(ASRCS) $(CSRCS)
|
SRCS = $(ASRCS) $(CSRCS)
|
||||||
|
|||||||
@@ -0,0 +1,97 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* binfmt/binfmt_dumpmodule.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <sched.h>
|
||||||
|
#include <debug.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <nuttx/binfmt.h>
|
||||||
|
|
||||||
|
#include "binfmt_internal.h"
|
||||||
|
|
||||||
|
#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_BINFMT)
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
* Public Functions
|
||||||
|
***********************************************************************/
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
* Name: load_module
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Load a module into memory and prep it for execution.
|
||||||
|
*
|
||||||
|
***********************************************************************/
|
||||||
|
|
||||||
|
int dump_module(FAR const struct binary_s *bin)
|
||||||
|
{
|
||||||
|
if (bin)
|
||||||
|
{
|
||||||
|
bdbg("Module:\n");
|
||||||
|
bdbg(" filename: %s\n", bin->filename);
|
||||||
|
bdbg(" argv: %p\n", bin->argv);
|
||||||
|
bdbg(" entrypt: %p\n", bin->entrypt);
|
||||||
|
bdbg(" ispace: %p size=%d\n", bin->ispace, bin->isize);
|
||||||
|
bdbg(" dspace: %p\n", bin->dspace);
|
||||||
|
bdbg(" stacksize: %d\n", bin->stacksize);
|
||||||
|
}
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* binfmt/binfmt_globals.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <nuttx/binfmt.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* This is a list of registered handlers for different binary formats. This
|
||||||
|
* list should only be accessed by normal user programs. It should be sufficient
|
||||||
|
* protection to simply disable pre-emption when accessing this list.
|
||||||
|
*/
|
||||||
|
|
||||||
|
FAR struct binfmt_s *g_binfmts;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
* Public Functions
|
||||||
|
***********************************************************************/
|
||||||
|
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* binfmt/binfmt_internal.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __BINFMT_BINFMT_INTERNAL_H
|
||||||
|
#define __BINFMT_BINFMT_INTERNAL_H
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <nuttx/binfmt.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
#define EXTERN extern "C"
|
||||||
|
extern "C" {
|
||||||
|
#else
|
||||||
|
#define EXTERN extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* This is a list of registered handlers for different binary formats. This
|
||||||
|
* list should only be accessed by normal user programs. It should be sufficient
|
||||||
|
* protection to simply disable pre-emption when accessing this list.
|
||||||
|
*/
|
||||||
|
|
||||||
|
EXTERN FAR struct binfmt_s *g_binfmts;
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
***********************************************************************/
|
||||||
|
|
||||||
|
/* Dump the contents of strtuc binary_s */
|
||||||
|
|
||||||
|
#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_BINFMT)
|
||||||
|
EXTERN int dump_module(FAR const struct binary_s *bin);
|
||||||
|
#else
|
||||||
|
# define dump_module(bin)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __BINFMT_BINFMT_INTERNAL_H */
|
||||||
|
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* binfmt/binfmt_loadmodule.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <sched.h>
|
||||||
|
#include <debug.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <nuttx/binfmt.h>
|
||||||
|
|
||||||
|
#include "binfmt_internal.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
* Public Functions
|
||||||
|
***********************************************************************/
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
* Name: load_module
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Load a module into memory and prep it for execution.
|
||||||
|
*
|
||||||
|
***********************************************************************/
|
||||||
|
|
||||||
|
int load_module(const char *filename, FAR struct binary_s *bin)
|
||||||
|
{
|
||||||
|
FAR struct binfmt_s *binfmt;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
#ifdef CONFIG_DEBUG
|
||||||
|
if (!filename || !bin)
|
||||||
|
{
|
||||||
|
ret = -EINVAL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
bdbg("Loading %s\n", filename);
|
||||||
|
|
||||||
|
/* Disabling pre-emption should be sufficient protection while
|
||||||
|
* accessing the list of registered binary format handlers.
|
||||||
|
*/
|
||||||
|
|
||||||
|
sched_lock();
|
||||||
|
|
||||||
|
/* Traverse the list of registered binary format handlers. Stop
|
||||||
|
* when either (1) a handler recognized and loads the format, or
|
||||||
|
* (2) no handler recognizes the format.
|
||||||
|
*/
|
||||||
|
|
||||||
|
for (binfmt = g_binfmts; binfmt; binfmt = binfmt->next)
|
||||||
|
{
|
||||||
|
/* Use this handler to try to load the format */
|
||||||
|
|
||||||
|
ret = binfmt->load(bin);
|
||||||
|
if (ret == OK)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Successfully loaded -- break out with ret == 0 */
|
||||||
|
|
||||||
|
dump_module(bin);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sched_unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret < 0) bdbg("Returning %d\n", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* binfmt/binfmt_register.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <sched.h>
|
||||||
|
#include <debug.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <nuttx/binfmt.h>
|
||||||
|
|
||||||
|
#include "binfmt_internal.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
* Public Functions
|
||||||
|
***********************************************************************/
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
* Name: register_binfmt
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Register a loader for a binary format
|
||||||
|
*
|
||||||
|
***********************************************************************/
|
||||||
|
|
||||||
|
int register_binfmt(FAR struct binfmt_s *binfmt)
|
||||||
|
{
|
||||||
|
if (binfmt)
|
||||||
|
{
|
||||||
|
/* Add the new binary format handler to the head of the list of
|
||||||
|
* handlers
|
||||||
|
*/
|
||||||
|
|
||||||
|
sched_lock();
|
||||||
|
binfmt->next = g_binfmts;
|
||||||
|
g_binfmts = binfmt;
|
||||||
|
sched_unlock();
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* binfmt/binfmt_loadmodule.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sched.h>
|
||||||
|
#include <debug.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <nuttx/binfmt.h>
|
||||||
|
|
||||||
|
#include "binfmt_internal.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
* Public Functions
|
||||||
|
***********************************************************************/
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
* Name: unload_module
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Unload a (non-executing) module from memory. If the module has
|
||||||
|
* been started (via exec_module), calling this will be fatal.
|
||||||
|
*
|
||||||
|
***********************************************************************/
|
||||||
|
|
||||||
|
int unload_module(FAR const struct binary_s *bin)
|
||||||
|
{
|
||||||
|
if (bin)
|
||||||
|
{
|
||||||
|
if (bin->ispace)
|
||||||
|
{
|
||||||
|
bvdbg("Unmapping ISpace: %p\n", bin->ispace);
|
||||||
|
munmap(bin->ispace, bin->isize);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bin->dspace)
|
||||||
|
{
|
||||||
|
bvdbg("Freeing DSpace: %p\n", bin->dspace);
|
||||||
|
free(bin->dspace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,130 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* binfmt/binfmt_unregister.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <sched.h>
|
||||||
|
#include <debug.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <nuttx/binfmt.h>
|
||||||
|
|
||||||
|
#include "binfmt_internal.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
* Public Functions
|
||||||
|
***********************************************************************/
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
* Name: unregister_binfmt
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Register a loader for a binary format
|
||||||
|
*
|
||||||
|
***********************************************************************/
|
||||||
|
|
||||||
|
int unregister_binfmt(FAR struct binfmt_s *binfmt)
|
||||||
|
{
|
||||||
|
FAR struct binfmt_s *curr;
|
||||||
|
FAR struct binfmt_s *prev;
|
||||||
|
int ret = -EINVAL;
|
||||||
|
|
||||||
|
if (binfmt)
|
||||||
|
{
|
||||||
|
/* Disabling pre-emption should be sufficient protection while
|
||||||
|
* accessing the list of registered binary format handlers.
|
||||||
|
*/
|
||||||
|
|
||||||
|
sched_lock();
|
||||||
|
|
||||||
|
/* Search the list of registered binary format handlers for the
|
||||||
|
* one to be unregistered.
|
||||||
|
*/
|
||||||
|
|
||||||
|
for (prev = NULL, curr = g_binfmts;
|
||||||
|
curr && curr != binfmt;
|
||||||
|
prev = curr, curr = curr->next);
|
||||||
|
|
||||||
|
/* Was it in the list? */
|
||||||
|
|
||||||
|
if (curr)
|
||||||
|
{
|
||||||
|
/* Yes.. was it at the head of the list? */
|
||||||
|
|
||||||
|
if (!prev)
|
||||||
|
{
|
||||||
|
/* Yes.. remove it from the head of the list */
|
||||||
|
|
||||||
|
g_binfmts = binfmt->next;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* No.. remove it from the middle/end of the list */
|
||||||
|
|
||||||
|
prev->next = binfmt->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
binfmt->next = NULL;
|
||||||
|
ret = OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
sched_unlock();
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -136,34 +136,30 @@ int nxflat_init(const char *filename, struct nxflat_hdr_s *header,
|
|||||||
*
|
*
|
||||||
* Note that:
|
* Note that:
|
||||||
*
|
*
|
||||||
* ispace_size = the address range from 0 up to datastart.
|
* isize = the address range from 0 up to datastart.
|
||||||
* data_size = the address range from datastart up to dataend
|
* datasize = the address range from datastart up to dataend
|
||||||
* bss_size = the address range from dataend up to bssend.
|
* bsssize = the address range from dataend up to bssend.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
loadinfo->entry_offset = ntohl(header->h_entry);
|
loadinfo->entryoffs = ntohl(header->h_entry);
|
||||||
loadinfo->ispace_size = datastart;
|
loadinfo->isize = datastart;
|
||||||
|
|
||||||
loadinfo->data_size = dataend - datastart;
|
loadinfo->datasize = dataend - datastart;
|
||||||
loadinfo->bss_size = bssend - dataend;
|
loadinfo->bsssize = bssend - dataend;
|
||||||
loadinfo->stack_size = ntohl(header->h_stacksize);
|
loadinfo->stacksize = ntohl(header->h_stacksize);
|
||||||
|
|
||||||
/* This is the initial dspace size. We'll recaculate this later
|
/* This is the initial dspace size. We'll re-calculate this later
|
||||||
* after the memory has been allocated. So that the caller can feel
|
* after the memory has been allocated.
|
||||||
* free to modify dspace_size values from now until then.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
loadinfo->dspace_size = /* Total DSpace Size is: */
|
loadinfo->dsize = bssend - datastart;
|
||||||
(NXFLAT_DATA_OFFSET + /* Memory set aside for ldso */
|
|
||||||
bssend - datastart + /* Data and bss segment sizes */
|
|
||||||
loadinfo->stack_size); /* (Current) stack size */
|
|
||||||
|
|
||||||
/* Get the offset to the start of the relocations (we'll relocate
|
/* Get the offset to the start of the relocations (we'll relocate
|
||||||
* this later).
|
* this later).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
loadinfo->reloc_start = ntohl(header->h_relocstart);
|
loadinfo->relocstart = ntohl(header->h_relocstart);
|
||||||
loadinfo->reloc_count = ntohl(header->h_reloccount);
|
loadinfo->reloccount = ntohl(header->h_reloccount);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,11 +106,11 @@ static void nxflat_reloc(struct nxflat_loadinfo_s *loadinfo, uint32 rl)
|
|||||||
* section of the file image.
|
* section of the file image.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (reloc.s.r_offset > loadinfo->data_size)
|
if (reloc.s.r_offset > loadinfo->datasize)
|
||||||
{
|
{
|
||||||
bdbg("ERROR: Relocation at 0x%08x invalid -- "
|
bdbg("ERROR: Relocation at 0x%08x invalid -- "
|
||||||
"does not lie in the data segment, size=0x%08x\n",
|
"does not lie in the data segment, size=0x%08x\n",
|
||||||
reloc.s.r_offset, loadinfo->data_size);
|
reloc.s.r_offset, loadinfo->datasize);
|
||||||
bdbg(" Relocation not performed!\n");
|
bdbg(" Relocation not performed!\n");
|
||||||
}
|
}
|
||||||
else if ((reloc.s.r_offset & 0x00000003) != 0)
|
else if ((reloc.s.r_offset & 0x00000003) != 0)
|
||||||
@@ -126,7 +126,7 @@ static void nxflat_reloc(struct nxflat_loadinfo_s *loadinfo, uint32 rl)
|
|||||||
* DSpace to hold information needed by ld.so at run time.
|
* DSpace to hold information needed by ld.so at run time.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
datastart = loadinfo->dspace + NXFLAT_DATA_OFFSET;
|
datastart = loadinfo->dspace;
|
||||||
|
|
||||||
/* Get a pointer to the value that needs relocation in
|
/* Get a pointer to the value that needs relocation in
|
||||||
* DSpace.
|
* DSpace.
|
||||||
@@ -149,15 +149,14 @@ static void nxflat_reloc(struct nxflat_loadinfo_s *loadinfo, uint32 rl)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
/* DATA and BSS are always contiguous regions. DATA
|
/* DATA and BSS are always contiguous regions. DATA
|
||||||
* begins at an offset of NXFLAT_DATA_OFFSET from
|
* begins at the beginning of the allocated data segment.
|
||||||
* the beginning of the allocated data segment.
|
|
||||||
* BSS is positioned after DATA, unrelocated references
|
* BSS is positioned after DATA, unrelocated references
|
||||||
* to BSS include the data offset.
|
* to BSS include the data offset.
|
||||||
*
|
*
|
||||||
* In other contexts, is it necessary to add the data_size
|
* In other contexts, is it necessary to add the datasize
|
||||||
* to get the BSS offset like:
|
* to get the BSS offset like:
|
||||||
*
|
*
|
||||||
* *ptr += datastart + loadinfo->data_size;
|
* *ptr += datastart + loadinfo->datasize;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
case NXFLAT_RELOC_TYPE_DATA:
|
case NXFLAT_RELOC_TYPE_DATA:
|
||||||
@@ -198,11 +197,11 @@ int nxflat_load(struct nxflat_loadinfo_s *loadinfo)
|
|||||||
uint32 ret;
|
uint32 ret;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Calculate the extra space we need to map in. This region will be the
|
/* Calculate the extra space we need to allocate. This extra space will be
|
||||||
* BSS segment and the stack. It will also be used temporarily to hold
|
* the size of the BSS section. This extra space will also be used
|
||||||
* relocation information. So the size of this region will either be the
|
* temporarily to hold relocation information. So the allocated size of this
|
||||||
* size of the BSS section and the stack OR, it the size of the relocation
|
* region will either be the size of .data + size of.bss section OR, the
|
||||||
* entries, whichever is larger
|
* size of .data + the relocation entries, whichever is larger
|
||||||
*/
|
*/
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -213,35 +212,32 @@ int nxflat_load(struct nxflat_loadinfo_s *loadinfo)
|
|||||||
* relocations.
|
* relocations.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
relocsize = loadinfo->reloc_count * sizeof(uint32);
|
relocsize = loadinfo->reloccount * sizeof(uint32);
|
||||||
|
|
||||||
/* In the file, the relocations should lie at the same offset as BSS.
|
/* In the file, the relocations should lie at the same offset as BSS.
|
||||||
* The additional amount that we allocate have to be either (1) the
|
* The additional amount that we allocate have to be either (1) the
|
||||||
* BSS size + the stack size, or (2) the size of the relocation records,
|
* BSS size, or (2) the size of the relocation records, whicher is
|
||||||
* whicher is larger.
|
* larger.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extrasize = MAX(loadinfo->bss_size + loadinfo->stack_size, relocsize);
|
extrasize = MAX(loadinfo->bsssize, relocsize);
|
||||||
|
|
||||||
/* Use this addtional amount to adjust the total size of the dspace
|
/* Use this addtional amount to adjust the total size of the dspace
|
||||||
* region.
|
* region.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
loadinfo->dspace_size =
|
loadinfo->dsize = loadinfo->datasize + extrasize;
|
||||||
NXFLAT_DATA_OFFSET + /* Memory used by ldso */
|
|
||||||
loadinfo->data_size + /* Initialized data */
|
|
||||||
extrasize; /* bss+stack/relocs */
|
|
||||||
|
|
||||||
/* The number of bytes of data that we have to read from the file is
|
/* The number of bytes of data that we have to read from the file is
|
||||||
* the data size plus the size of the relocation table.
|
* the data size plus the size of the relocation table.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
dreadsize = loadinfo->data_size + relocsize;
|
dreadsize = loadinfo->datasize + relocsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We'll need this a few times as well. */
|
/* We'll need this a few times as well. */
|
||||||
|
|
||||||
doffset = loadinfo->ispace_size;
|
doffset = loadinfo->isize;
|
||||||
|
|
||||||
/* We will make two mmap calls create an address space for the executable.
|
/* We will make two mmap calls create an address space for the executable.
|
||||||
* We will attempt to map the file to get the ISpace address space and
|
* We will attempt to map the file to get the ISpace address space and
|
||||||
@@ -255,7 +251,7 @@ int nxflat_load(struct nxflat_loadinfo_s *loadinfo)
|
|||||||
* resides as long as it is fully initialized and ready to execute.
|
* resides as long as it is fully initialized and ready to execute.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
loadinfo->ispace = (uint32)mmap(NULL, loadinfo->ispace_size, PROT_READ,
|
loadinfo->ispace = (uint32)mmap(NULL, loadinfo->isize, PROT_READ,
|
||||||
MAP_SHARED|MAP_FILE, loadinfo->filfd, 0);
|
MAP_SHARED|MAP_FILE, loadinfo->filfd, 0);
|
||||||
if (loadinfo->ispace == (uint32)MAP_FAILED)
|
if (loadinfo->ispace == (uint32)MAP_FAILED)
|
||||||
{
|
{
|
||||||
@@ -263,14 +259,13 @@ int nxflat_load(struct nxflat_loadinfo_s *loadinfo)
|
|||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
bvdbg("Mapped ISpace (%d bytes) at 0x%08x\n",
|
bvdbg("Mapped ISpace (%d bytes) at 0x%08x\n", loadinfo->isize, loadinfo->ispace);
|
||||||
loadinfo->ispace_size, loadinfo->ispace);
|
|
||||||
|
|
||||||
/* The following call will give a pointer to the allocated but
|
/* The following call will give a pointer to the allocated but
|
||||||
* uninitialized ISpace memory.
|
* uninitialized ISpace memory.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
loadinfo->dspace = (uint32)malloc(loadinfo->dspace_size);
|
loadinfo->dspace = (uint32)malloc(loadinfo->dsize);
|
||||||
if (loadinfo->dspace == 0)
|
if (loadinfo->dspace == 0)
|
||||||
{
|
{
|
||||||
bdbg("Failed to allocate DSpace\n");
|
bdbg("Failed to allocate DSpace\n");
|
||||||
@@ -279,57 +274,46 @@ int nxflat_load(struct nxflat_loadinfo_s *loadinfo)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bvdbg("Allocated DSpace (%d bytes) at %08x\n",
|
bvdbg("Allocated DSpace (%d bytes) at %08x\n",
|
||||||
loadinfo->dspace_size, loadinfo->dspace);
|
loadinfo->dsize, loadinfo->dspace);
|
||||||
|
|
||||||
/* Now, read the data into allocated DSpace at doffset into the
|
/* Now, read the data into allocated DSpace at doffset into the
|
||||||
* allocated DSpace memory.
|
* allocated DSpace memory.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ret = nxflat_read(loadinfo, (char*)(loadinfo->dspace + NXFLAT_DATA_OFFSET), dreadsize, doffset);
|
ret = nxflat_read(loadinfo, (char*)loadinfo->dspace, dreadsize, doffset);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
bdbg("Failed to read .data section: %d\n", ret);
|
bdbg("Failed to read .data section: %d\n", ret);
|
||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Save information about the allocation. */
|
|
||||||
|
|
||||||
loadinfo->alloc_start = loadinfo->dspace;
|
|
||||||
loadinfo->alloc_size = loadinfo->dspace_size;
|
|
||||||
|
|
||||||
bvdbg("TEXT=0x%x Entry point offset=0x%08x, datastart is 0x%08x\n",
|
bvdbg("TEXT=0x%x Entry point offset=0x%08x, datastart is 0x%08x\n",
|
||||||
loadinfo->ispace, loadinfo->entry_offset, doffset);
|
loadinfo->ispace, loadinfo->entryoffs, doffset);
|
||||||
|
|
||||||
/* Resolve the address of the relocation table. In the file, the
|
/* Resolve the address of the relocation table. In the file, the
|
||||||
* relocations should lie at the same offset as BSS. The current
|
* relocations should lie at the same offset as BSS. The current
|
||||||
* value of reloc_start is the offset from the beginning of the file.
|
* value of relocstart is the offset from the beginning of the file.
|
||||||
* The following adjustment will convert it to an address in DSpace.
|
* The following adjustment will convert it to an address in DSpace.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
reloctab = (uint32*)
|
reloctab = (uint32*)(loadinfo->relocstart + loadinfo->dspace - loadinfo->isize);
|
||||||
(loadinfo->reloc_start /* File offset to reloc records */
|
|
||||||
+ loadinfo->dspace /* + Allocated DSpace memory */
|
|
||||||
+ NXFLAT_DATA_OFFSET /* + Offset for ldso usage */
|
|
||||||
- loadinfo->ispace_size); /* - File offset to DSpace */
|
|
||||||
|
|
||||||
bvdbg("Relocation table at 0x%p, reloc_count=%d\n",
|
bvdbg("Relocation table at 0x%p, reloccount=%d\n",
|
||||||
reloctab, loadinfo->reloc_count);
|
reloctab, loadinfo->reloccount);
|
||||||
|
|
||||||
/* Now run through the relocation entries. */
|
/* Now run through the relocation entries. */
|
||||||
|
|
||||||
for (i=0; i < loadinfo->reloc_count; i++)
|
for (i=0; i < loadinfo->reloccount; i++)
|
||||||
{
|
{
|
||||||
nxflat_reloc(loadinfo, htonl(reloctab[i]));
|
nxflat_reloc(loadinfo, htonl(reloctab[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Zero the BSS, BRK and stack areas, trashing the relocations
|
/* Zero the BSS area, trashing the relocations that lived in space
|
||||||
* that lived in the corresponding space in the file. */
|
* in the file.
|
||||||
|
*/
|
||||||
memset((void*)(loadinfo->dspace + NXFLAT_DATA_OFFSET + loadinfo->data_size),
|
|
||||||
0,
|
|
||||||
(loadinfo->dspace_size - NXFLAT_DATA_OFFSET -
|
|
||||||
loadinfo->data_size));
|
|
||||||
|
|
||||||
|
memset((void*)(loadinfo->dspace + loadinfo->datasize),
|
||||||
|
0, loadinfo->bsssize);
|
||||||
return OK;
|
return OK;
|
||||||
|
|
||||||
errout:
|
errout:
|
||||||
|
|||||||
@@ -75,16 +75,11 @@ int nxflat_unload(struct nxflat_loadinfo_s *loadinfo)
|
|||||||
{
|
{
|
||||||
/* Reset the contents of the info structure. */
|
/* Reset the contents of the info structure. */
|
||||||
|
|
||||||
/* Nothing is allocated */
|
|
||||||
|
|
||||||
loadinfo->alloc_start = 0;
|
|
||||||
loadinfo->alloc_size = 0;
|
|
||||||
|
|
||||||
/* Release the memory segments */
|
/* Release the memory segments */
|
||||||
|
|
||||||
if (loadinfo->ispace)
|
if (loadinfo->ispace)
|
||||||
{
|
{
|
||||||
munmap((void*)loadinfo->ispace, loadinfo->ispace_size);
|
munmap((void*)loadinfo->ispace, loadinfo->isize);
|
||||||
loadinfo->ispace = 0;
|
loadinfo->ispace = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,8 +67,6 @@
|
|||||||
|
|
||||||
int nxflat_verifyheader(const struct nxflat_hdr_s *header)
|
int nxflat_verifyheader(const struct nxflat_hdr_s *header)
|
||||||
{
|
{
|
||||||
uint16 revision;
|
|
||||||
|
|
||||||
if (!header)
|
if (!header)
|
||||||
{
|
{
|
||||||
bdbg("NULL NXFLAT header!");
|
bdbg("NULL NXFLAT header!");
|
||||||
@@ -88,15 +86,6 @@ int nxflat_verifyheader(const struct nxflat_hdr_s *header)
|
|||||||
header->h_magic[2], header->h_magic[3]);
|
header->h_magic[2], header->h_magic[3]);
|
||||||
return -ENOEXEC;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
return OK;
|
||||||
/* Complain a little more if the version does not match. */
|
|
||||||
|
|
||||||
revision = ntohs(header->h_rev);
|
|
||||||
if (revision != NXFLAT_VERSION_CURRENT)
|
|
||||||
{
|
|
||||||
bdbg("Unsupported NXFLAT version=%d\n", revision);
|
|
||||||
return -ENOEXEC;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+17
-28
@@ -64,7 +64,7 @@ static void nxflat_dumploadinfo(struct nxflat_loadinfo_s *loadinfo);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Constant Data
|
* Private Data
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static struct binfmt_s g_nxflatbinfmt =
|
static struct binfmt_s g_nxflatbinfmt =
|
||||||
@@ -103,45 +103,31 @@ static void nxflat_dumpmemory(void *addr, int nbytes)
|
|||||||
#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_BINFMT)
|
#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_BINFMT)
|
||||||
static void nxflat_dumploadinfo(struct nxflat_loadinfo_s *loadinfo)
|
static void nxflat_dumploadinfo(struct nxflat_loadinfo_s *loadinfo)
|
||||||
{
|
{
|
||||||
unsigned long dspace_size =
|
unsigned long dsize = loadinfo->datasize + loadinfo->bsssize;
|
||||||
NXFLAT_DATA_OFFSET +
|
|
||||||
loadinfo->data_size +
|
|
||||||
loadinfo->bss_size +
|
|
||||||
loadinfo->stack_size;
|
|
||||||
|
|
||||||
bdbg("LOAD_INFO:\n");
|
bdbg("LOAD_INFO:\n");
|
||||||
bdbg(" ISPACE:\n");
|
bdbg(" ISPACE:\n");
|
||||||
bdbg(" ispace: %08lx\n", loadinfo->ispace);
|
bdbg(" ispace: %08lx\n", loadinfo->ispace);
|
||||||
bdbg(" entry_offset: %08lx\n", loadinfo->entry_offset);
|
bdbg(" entryoffs: %08lx\n", loadinfo->entryoffs);
|
||||||
bdbg(" ispace_size: %08lx\n", loadinfo->ispace_size);
|
bdbg(" isize: %08lx\n", loadinfo->isize);
|
||||||
|
|
||||||
bdbg(" DSPACE:\n");
|
bdbg(" DSPACE:\n");
|
||||||
bdbg(" dspace: %08lx\n", loadinfo->dspace);
|
bdbg(" dspace: %08lx\n", loadinfo->dspace);
|
||||||
bdbg(" (ldso): %08x\n", NXFLAT_DATA_OFFSET);
|
bdbg(" datasize: %08lx\n", loadinfo->datasize);
|
||||||
bdbg(" data_size: %08lx\n", loadinfo->data_size);
|
bdbg(" bsssize: %08lx\n", loadinfo->bsssize);
|
||||||
bdbg(" bss_size: %08lx\n", loadinfo->bss_size);
|
bdbg(" (pad): %08lx\n", loadinfo->dsize - dsize);
|
||||||
bdbg(" (pad): %08lx\n", loadinfo->dspace_size - dspace_size);
|
bdbg(" stacksize: %08lx\n", loadinfo->stacksize);
|
||||||
bdbg(" stack_size: %08lx\n", loadinfo->stack_size);
|
bdbg(" dsize: %08lx\n", loadinfo->dsize);
|
||||||
bdbg(" dspace_size: %08lx\n", loadinfo->dspace_size);
|
|
||||||
|
|
||||||
bdbg(" ARGUMENTS:\n");
|
|
||||||
bdbg(" arg_start: %08lx\n", loadinfo->arg_start);
|
|
||||||
bdbg(" env_start: %08lx\n", loadinfo->env_start);
|
|
||||||
bdbg(" env_end: %08lx\n", loadinfo->env_end);
|
|
||||||
|
|
||||||
bdbg(" RELOCS:\n");
|
bdbg(" RELOCS:\n");
|
||||||
bdbg(" reloc_start: %08lx\n", loadinfo->reloc_start);
|
bdbg(" relocstart: %08lx\n", loadinfo->relocstart);
|
||||||
bdbg(" reloc_count: %08lx\n", loadinfo->reloc_count);
|
bdbg(" reloccount: %08lx\n", loadinfo->reloccount);
|
||||||
|
|
||||||
bdbg(" HANDLES:\n");
|
bdbg(" HANDLES:\n");
|
||||||
bdbg(" filfd: %d\n", loadinfo->filfd);
|
bdbg(" filfd: %d\n", loadinfo->filfd);
|
||||||
|
|
||||||
bdbg(" NXFLT HEADER:");
|
bdbg(" NXFLT HEADER:");
|
||||||
bdbg(" header: %p\n", loadinfo->header);
|
bdbg(" header: %p\n", loadinfo->header);
|
||||||
|
|
||||||
bdbg(" ALLOCATIONS:\n");
|
|
||||||
bdbg(" alloc_start: %08lx\n", loadinfo->alloc_start);
|
|
||||||
bdbg(" alloc_size: %08lx\n", loadinfo->alloc_size);
|
|
||||||
}
|
}
|
||||||
#else /* CONFIG_XFLAT_DEBUG */
|
#else /* CONFIG_XFLAT_DEBUG */
|
||||||
# define nxflat_dumploadinfo(i)
|
# define nxflat_dumploadinfo(i)
|
||||||
@@ -187,11 +173,14 @@ static int nxflat_loadbinary(struct binary_s *binp)
|
|||||||
|
|
||||||
/* Return the load information */
|
/* Return the load information */
|
||||||
|
|
||||||
binp->entrypt = (main_t)(loadinfo.ispace + loadinfo.entry_offset);
|
binp->entrypt = (main_t)(loadinfo.ispace + loadinfo.entryoffs);
|
||||||
binp->picbase = (void*)loadinfo.dspace;
|
binp->ispace = (void*)loadinfo.ispace;
|
||||||
|
binp->dspace = (void*)loadinfo.dspace;
|
||||||
|
binp->isize = loadinfo.isize;
|
||||||
|
binp->stacksize = loadinfo.stacksize;
|
||||||
|
|
||||||
bvdbg("ENTRY CODE:\n");
|
bvdbg("ENTRY CODE:\n");
|
||||||
nxflat_dumpmemory(binp->entrypt, 16*sizeof(unsigned long));
|
nxflat_dumpmemory(binp->entrypt, 16*sizeof(uint32));
|
||||||
nxflat_uninit(&loadinfo);
|
nxflat_uninit(&loadinfo);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-8
@@ -58,21 +58,24 @@ struct binary_s
|
|||||||
{
|
{
|
||||||
/* Provided to the loader */
|
/* Provided to the loader */
|
||||||
|
|
||||||
const char *filename; /* Full path to the binary */
|
FAR const char *filename; /* Full path to the binary */
|
||||||
const char **argv; /* Argument list */
|
FAR const char **argv; /* Argument list */
|
||||||
|
|
||||||
/* Provided by the loader (if successful) */
|
/* Provided by the loader (if successful) */
|
||||||
|
|
||||||
main_t entrypt; /* Entry point into a program module */
|
main_t entrypt; /* Entry point into a program module */
|
||||||
void *picbase; /* Address of the allocate .data/.bss space */
|
FAR void *ispace; /* Memory-mapped, I-space (.text) address */
|
||||||
|
FAR void *dspace; /* Address of the allocated .data/.bss space */
|
||||||
|
size_t isize; /* Size of the I-space region (needed for munmap) */
|
||||||
|
size_t stacksize; /* Size of the stack in bytes (unallocated) */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* This describes one binary format handler */
|
/* This describes one binary format handler */
|
||||||
|
|
||||||
struct binfmt_s
|
struct binfmt_s
|
||||||
{
|
{
|
||||||
struct binfmt_s *next; /* Supports a singly-linked list */
|
FAR struct binfmt_s *next; /* Supports a singly-linked list */
|
||||||
int (*load)(struct binary_s *bin); /* Verify and load binary into memory */
|
int (*load)(FAR struct binary_s *bin); /* Verify and load binary into memory */
|
||||||
};
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -87,10 +90,25 @@ extern "C" {
|
|||||||
#define EXTERN extern
|
#define EXTERN extern
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Register/unregister a binary format */
|
/* Register a binary format handler */
|
||||||
|
|
||||||
EXTERN int register_binfmt(struct binfmt_s *binfmt);
|
EXTERN int register_binfmt(FAR struct binfmt_s *binfmt);
|
||||||
EXTERN int unregister_binfmt(struct binfmt_s *binfmt);
|
|
||||||
|
/* Unregister a binary format handler */
|
||||||
|
|
||||||
|
EXTERN int unregister_binfmt(FAR struct binfmt_s *binfmt);
|
||||||
|
|
||||||
|
/* Load a module into memory */
|
||||||
|
|
||||||
|
EXTERN int load_module(const char *filename, FAR struct binary_s *bin);
|
||||||
|
|
||||||
|
/* Unload a (non-running) module from memory */
|
||||||
|
|
||||||
|
EXTERN int unload_module(FAR const struct binary_s *bin);
|
||||||
|
|
||||||
|
/* Execute a module that has been loaded into memory */
|
||||||
|
|
||||||
|
EXTERN int exec_module(FAR const struct binary_s *bin);
|
||||||
|
|
||||||
#undef EXTERN
|
#undef EXTERN
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
@@ -98,3 +116,4 @@ EXTERN int unregister_binfmt(struct binfmt_s *binfmt);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* __INCLUDE_NUTTX_BINFMT_H */
|
#endif /* __INCLUDE_NUTTX_BINFMT_H */
|
||||||
|
|
||||||
|
|||||||
+17
-46
@@ -50,71 +50,42 @@
|
|||||||
* Public Types
|
* Public Types
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* When DSpace is allocated, space is reserved at the beginning to
|
/* This struct provides a desciption of the currently loaded instantiation
|
||||||
* hold ldso-specific information. The following structure defines
|
* of an nxflat binary.
|
||||||
* that information. This structure can be referenced at run-time
|
|
||||||
* using a negative offset from the PID base address.
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct nxflat_ldso_info
|
|
||||||
{
|
|
||||||
uint32 dspace; /* The beginning of ldso DSpace */
|
|
||||||
};
|
|
||||||
#define NXFLAT_DATA_OFFSET sizeof(struct nxflat_ldso_info)
|
|
||||||
|
|
||||||
/* This struct provides a desciption of the currently loaded
|
|
||||||
* instantiation of an xflat binary.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct nxflat_loadinfo_s
|
struct nxflat_loadinfo_s
|
||||||
{
|
{
|
||||||
/* Instruction Space (ISpace): This region contains the flat
|
/* Instruction Space (ISpace): This region contains the nxflat file header
|
||||||
* file header plus everything from the text section. Ideally,
|
* plus everything from the text section. Ideally, will have only one mmap'ed
|
||||||
* will have only one text section instance in the system.
|
* text section instance in the system for each module.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
uint32 ispace; /* Address where hdr/text is loaded */
|
uint32 ispace; /* Address where hdr/text is loaded */
|
||||||
/* 1st: struct nxflat_hdr_s */
|
uint32 entryoffs; /* Offset from ispace to entry point */
|
||||||
/* 2nd: text section */
|
uint32 isize; /* Size of ispace. */
|
||||||
uint32 entry_offset; /* Offset from ispace to entry point */
|
|
||||||
uint32 ispace_size; /* Size of ispace. */
|
|
||||||
|
|
||||||
/* Data Space (DSpace): This region contains all information that
|
/* Data Space (DSpace): This region contains all information that in referenced
|
||||||
* in referenced as data. There will be a unique instance of
|
* as data (other than the stack which is separately allocated). There will be
|
||||||
* DSpace for each instance of a process.
|
* a unique instance of DSpace (and stack) for each instance of a process.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
uint32 dspace; /* Address where data/bss/stack/etc. is loaded */
|
uint32 dspace; /* Address where data/bss/etc. is loaded */
|
||||||
/* 1st: Memory set aside for ldso */
|
uint32 datasize; /* Size of data segment in dspace */
|
||||||
uint32 data_size; /* 2nd: Size of data segment in dspace */
|
uint32 bsssize; /* Size of bss segment in dspace */
|
||||||
uint32 bss_size; /* 3rd: Size of bss segment in dspace */
|
uint32 stacksize; /* Size of stack (not allocated) */
|
||||||
/* 4th: Potential padding from relocs/mm/etc. */
|
uint32 dsize; /* Size of dspace (may be large than parts) */
|
||||||
uint32 stack_size; /* 5th: Size of stack in dspace */
|
|
||||||
uint32 dspace_size; /* Size of dspace (may be large than parts) */
|
|
||||||
|
|
||||||
/* Program arguments (addresses in dspace) */
|
|
||||||
|
|
||||||
uint32 arg_start; /* Beginning of program arguments */
|
|
||||||
uint32 env_start; /* End of argments, beginning of env */
|
|
||||||
uint32 env_end; /* End(+4) of env */
|
|
||||||
|
|
||||||
/* This is temporary memory where relocation records will be loaded. */
|
/* This is temporary memory where relocation records will be loaded. */
|
||||||
|
|
||||||
uint32 reloc_start; /* Start of array of struct flat_reloc */
|
uint32 relocstart; /* Start of array of struct flat_reloc */
|
||||||
uint32 reloc_count; /* Number of elements in reloc array */
|
uint32 reloccount; /* Number of elements in reloc array */
|
||||||
|
|
||||||
/* File descriptors */
|
/* File descriptors */
|
||||||
|
|
||||||
int filfd; /* Descriptor for the file being loaded */
|
int filfd; /* Descriptor for the file being loaded */
|
||||||
|
|
||||||
const struct nxflat_hdr_s *header; /* A reference to the flat file header */
|
const struct nxflat_hdr_s *header; /* A reference to the flat file header */
|
||||||
|
|
||||||
/* At most one memory allocation will be made. These describe that
|
|
||||||
* allocation.
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32 alloc_start; /* Start of the allocation */
|
|
||||||
uint32 alloc_size; /* Size of the allocation */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
+3
-47
@@ -60,16 +60,12 @@
|
|||||||
struct nxflat_hdr_s
|
struct nxflat_hdr_s
|
||||||
{
|
{
|
||||||
/* The "magic number identifying the file type. This field should contain
|
/* The "magic number identifying the file type. This field should contain
|
||||||
* "NxFT"
|
* "NxFT". NOTE that there is not other versioning information other than
|
||||||
|
* this magic number.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char h_magic[4];
|
char h_magic[4];
|
||||||
|
|
||||||
/* NXFLAT revision number number. */
|
|
||||||
|
|
||||||
uint16 h_rev;
|
|
||||||
uint16 h_pad;
|
|
||||||
|
|
||||||
/* The following fields provide the memory map for the nxflat binary.
|
/* The following fields provide the memory map for the nxflat binary.
|
||||||
*
|
*
|
||||||
* h_entry - Offset to the the first executable insruction from
|
* h_entry - Offset to the the first executable insruction from
|
||||||
@@ -113,7 +109,7 @@ struct nxflat_hdr_s
|
|||||||
uint32 h_relocstart; /* Offset of relocation records */
|
uint32 h_relocstart; /* Offset of relocation records */
|
||||||
uint32 h_reloccount; /* Number of relocation records */
|
uint32 h_reloccount; /* Number of relocation records */
|
||||||
|
|
||||||
/* Imported and exported symbol tables
|
/* Imported symbol table (NOTE no symbols are exported)
|
||||||
*
|
*
|
||||||
* h_importsymbols - Offset to the beginning of an array of imported
|
* h_importsymbols - Offset to the beginning of an array of imported
|
||||||
* symbol structures (struct nxflat_import). The
|
* symbol structures (struct nxflat_import). The
|
||||||
@@ -123,39 +119,12 @@ struct nxflat_hdr_s
|
|||||||
* the beginning of the file) to the name of
|
* the beginning of the file) to the name of
|
||||||
* a symbol string. This string is null-terminated.
|
* a symbol string. This string is null-terminated.
|
||||||
* h_importcount - The number of records in the h_exportsymbols array.
|
* h_importcount - The number of records in the h_exportsymbols array.
|
||||||
* h_exportsymbols - Offset to the beginning of an array of export
|
|
||||||
* symbol structures (struct nxflat_export). The
|
|
||||||
* h_importsymbols offset is relative to the
|
|
||||||
* beginning of the file. Each entry of the
|
|
||||||
* array contains an uint32 offset (again from
|
|
||||||
* the beginning of the file) to the name of
|
|
||||||
* a symbol string. This string is null-terminated.
|
|
||||||
* h_exportcount - The number of records in the h_exportsymbols array.
|
|
||||||
*
|
|
||||||
* NOTE: All of the arrays referenced in the header reside in the
|
|
||||||
* the .text section. This is possible because these arrays are
|
|
||||||
* read-only and are only referenced by the load. Residing in text
|
|
||||||
* also guarantees that only one copy of the array is required.
|
|
||||||
*
|
|
||||||
* An exception is the h_importsymbols array with will lie
|
|
||||||
* in .data. This array contains write-able data and must have
|
|
||||||
* a single instance per process. NOTE: The string offset contained
|
|
||||||
* within nxflat_import still refers to strings residing in the text
|
|
||||||
* section.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
uint32 h_importsymbols; /* Offset to list of imported symbols */
|
uint32 h_importsymbols; /* Offset to list of imported symbols */
|
||||||
uint32 h_exportsymbols; /* Offset to list of exported symbols */
|
|
||||||
uint16 h_importcount; /* Number of imported symbols */
|
uint16 h_importcount; /* Number of imported symbols */
|
||||||
uint16 h_exportcount; /* Number of imported symbols */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Legal values for the version field. */
|
|
||||||
|
|
||||||
#define NXFLAT_VERSION_NONE 0 /* Invalid NXFLAT version */
|
|
||||||
#define NXFLAT_VERSION_CURRENT 1 /* Current version */
|
|
||||||
#define NXFLAT_VERSION_NUM 2
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* NXFLAT Relocation types.
|
* NXFLAT Relocation types.
|
||||||
*
|
*
|
||||||
@@ -193,17 +162,4 @@ struct nxflat_import_s
|
|||||||
uint32 i_funcaddress; /* Resolved address of imported function */
|
uint32 i_funcaddress; /* Resolved address of imported function */
|
||||||
};
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Exported symbol type
|
|
||||||
*
|
|
||||||
* The exported symbols are an array of the following type. The fields
|
|
||||||
* in each element are stored in native machine order.
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
struct nxflat_export_s
|
|
||||||
{
|
|
||||||
uint32 x_funcname; /* Offset to name of exported function */
|
|
||||||
uint32 x_funcaddress; /* Address of exported function */
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* __INCLUDE_NXFLAT_H */
|
#endif /* __INCLUDE_NXFLAT_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user