summaryrefslogtreecommitdiff
path: root/nuttx/binfmt
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-08-26 10:42:42 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-08-26 10:42:42 -0600
commit13888a7933b18b6b5360a162338f075ea2ae3ba0 (patch)
tree0cddd13384452dc4ce9d97d1793f2ee492c42f44 /nuttx/binfmt
parent48a85c493acf0f59eadf84e6e7dfec6de5b998fc (diff)
downloadpx4-nuttx-13888a7933b18b6b5360a162338f075ea2ae3ba0.tar.gz
px4-nuttx-13888a7933b18b6b5360a162338f075ea2ae3ba0.tar.bz2
px4-nuttx-13888a7933b18b6b5360a162338f075ea2ae3ba0.zip
Can't dump loaded code unless we first establish the mappings
Diffstat (limited to 'nuttx/binfmt')
-rw-r--r--nuttx/binfmt/elf.c51
1 files changed, 47 insertions, 4 deletions
diff --git a/nuttx/binfmt/elf.c b/nuttx/binfmt/elf.c
index cff3463a7..98924a6a8 100644
--- a/nuttx/binfmt/elf.c
+++ b/nuttx/binfmt/elf.c
@@ -47,9 +47,13 @@
#include <errno.h>
#include <arpa/inet.h>
+
+#include <nuttx/arch.h>
#include <nuttx/binfmt/binfmt.h>
#include <nuttx/binfmt/elf.h>
+#include "libelf/libelf.h"
+
#ifdef CONFIG_ELF
/****************************************************************************
@@ -171,6 +175,47 @@ static void elf_dumploadinfo(FAR struct elf_loadinfo_s *loadinfo)
#endif
/****************************************************************************
+ * Name: elf_dumpentrypt
+ ****************************************************************************/
+
+#ifdef CONFIG_ELF_DUMPBUFFER
+static void elf_dumpentrypt(FAR struct binary_s *binp,
+ FAR struct elf_loadinfo_s *loadinfo)
+{
+#ifdef CONFIG_ARCH_ADDRENV
+ int ret;
+
+ /* If CONFIG_ARCH_ADDRENV=y, then the loaded ELF lies in a virtual address
+ * space that may not be in place now. elf_addrenv_select() will
+ * temporarily instantiate that address space.
+ */
+
+ ret = elf_addrenv_select(loadinfo);
+ if (ret < 0)
+ {
+ bdbg("ERROR: elf_addrenv_select() failed: %d\n", ret);
+ return;
+ }
+#endif
+
+ elf_dumpbuffer("Entry code", (FAR const uint8_t*)binp->entrypt,
+ MIN(loadinfo->textsize - loadinfo->ehdr.e_entry, 512));
+
+#ifdef CONFIG_ARCH_ADDRENV
+ /* Restore the original address environment */
+
+ ret = elf_addrenv_restore(loadinfo);
+ if (ret < 0)
+ {
+ bdbg("ERROR: elf_addrenv_restore() failed: %d\n", ret);
+ }
+#endif
+}
+#else
+# define elf_dumpentrypt(b,l)
+#endif
+
+/****************************************************************************
* Name: elf_loadbinary
*
* Description:
@@ -179,7 +224,7 @@ static void elf_dumploadinfo(FAR struct elf_loadinfo_s *loadinfo)
*
****************************************************************************/
-static int elf_loadbinary(struct binary_s *binp)
+static int elf_loadbinary(FAR struct binary_s *binp)
{
struct elf_loadinfo_s loadinfo; /* Contains globals for libelf */
int ret;
@@ -256,9 +301,7 @@ static int elf_loadbinary(struct binary_s *binp)
binp->addrenv = loadinfo.addrenv;
#endif
- elf_dumpbuffer("Entry code", (FAR const uint8_t*)binp->entrypt,
- MIN(loadinfo.textsize - loadinfo.ehdr.e_entry, 512));
-
+ elf_dumpentrypt(binp, &loadinfo);
elf_uninit(&loadinfo);
return OK;