mirror of
https://github.com/apache/nuttx.git
synced 2026-09-28 15:54:57 +08:00
Easing in binfmt support
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1892 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
+28
-4
@@ -1,5 +1,5 @@
|
||||
/****************************************************************************
|
||||
* debug.h
|
||||
* include/debug.h
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
@@ -33,8 +33,8 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __DEBUG_H
|
||||
#define __DEBUG_H
|
||||
#ifndef __INCLUDE_DEBUG_H
|
||||
#define __INCLUDE_DEBUG_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
@@ -175,6 +175,18 @@
|
||||
# define gllvdbg(x...)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DEBUG_BINFMT
|
||||
# define bdbg(format, arg...) dbg(format, ##arg)
|
||||
# define blldbg(format, arg...) lldbg(format, ##arg)
|
||||
# define bvdbg(format, arg...) vdbg(format, ##arg)
|
||||
# define bllvdbg(format, arg...) llvdbg(format, ##arg)
|
||||
#else
|
||||
# define bdbg(x...)
|
||||
# define blldbg(x...)
|
||||
# define bvdbg(x...)
|
||||
# define bllvdbg(x...)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DEBUG_LIB
|
||||
# define ldbg(format, arg...) dbg(format, ##arg)
|
||||
# define llldbg(format, arg...) lldbg(format, ##arg)
|
||||
@@ -284,6 +296,18 @@
|
||||
# define gllvdbg (void)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DEBUG_BINFMT
|
||||
# define bdbg dbg
|
||||
# define blldbg lldbg
|
||||
# define bvdbg vdbg
|
||||
# define bllvdbg llvdbg
|
||||
#else
|
||||
# define bdbg (void)
|
||||
# define blldbg (void)
|
||||
# define bvdbg (void)
|
||||
# define bllvdbg (void)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DEBUG_LIB
|
||||
# define ldbg dbg
|
||||
# define llldbg lldbg
|
||||
@@ -357,4 +381,4 @@ EXTERN int llvdbg(const char *format, ...);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __DEBUG_H */
|
||||
#endif /* __INCLUDE_DEBUG_H */
|
||||
|
||||
+4
-4
@@ -1,7 +1,7 @@
|
||||
/************************************************************************
|
||||
* include/errno.h
|
||||
*
|
||||
* Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -33,8 +33,8 @@
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
#ifndef __ERRNO_H
|
||||
#define __ERRNO_H
|
||||
#ifndef __INCLUDE_ERRNO_H
|
||||
#define __INCLUDE_ERRNO_H
|
||||
|
||||
/************************************************************************
|
||||
* Included Files
|
||||
@@ -324,4 +324,4 @@ extern FAR int *get_errno_ptr(void);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ERRNO_H */
|
||||
#endif /* __INCLUDE_ERRNO_H */
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/binfmt.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 __INCLUDE_NUTTX_BINFMT_H
|
||||
#define __INCLUDE_NUTTX_BINFMT_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <sys/types.h>
|
||||
#include <nxflat.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* This describes the file to be loaded */
|
||||
|
||||
struct binary_s
|
||||
{
|
||||
/* Provided to the loader */
|
||||
|
||||
const char *filename; /* Full path to the binary */
|
||||
const char **argv; /* Argument list */
|
||||
|
||||
/* Provided by the loader (if successful) */
|
||||
|
||||
main_t entrypt; /* Entry point into a program module */
|
||||
void *picbase; /* Address of the allocate .data/.bss space */
|
||||
};
|
||||
|
||||
/* This describes one binary format handler */
|
||||
|
||||
struct binfmt_s
|
||||
{
|
||||
struct binfmt_s *next; /* Supports a singly-linked list */
|
||||
int (*load)(struct binary_s *bin); /* Verify and load binary into memory */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/* Register/unregister a binary format */
|
||||
|
||||
EXTERN int register_binfmt(struct binfmt_s *binfmt);
|
||||
EXTERN int unregister_binfmt(struct binfmt_s *binfmt);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_BINFMT_H */
|
||||
+23
-81
@@ -62,45 +62,6 @@ struct nxflat_ldso_info
|
||||
};
|
||||
#define NXFLAT_DATA_OFFSET sizeof(struct nxflat_ldso_info)
|
||||
|
||||
/* An "opaque" handle that describes the xflat binary to be loaded. */
|
||||
|
||||
typedef void *bin_handle_t;
|
||||
|
||||
/* An "opaque" handle that describes an open file */
|
||||
|
||||
typedef void *file_handle_t;
|
||||
|
||||
/* This is a call table that is used by the xflat library to call
|
||||
* obtain system information. The use of this call table allows the
|
||||
* library to be designed in a platform independent way.
|
||||
*/
|
||||
|
||||
struct nxflat_vtbl_s
|
||||
{
|
||||
/* Allocators. These imports keep the xflat library independent of
|
||||
* the memory mapping and memory management facilities of the host
|
||||
* system.
|
||||
*
|
||||
* map/unmap will map/unmap a program file onto an address;
|
||||
* alloc/free will allocate/deallocate program memory.
|
||||
*/
|
||||
|
||||
void *(*map)(file_handle_t file_handle, uint32 nbytes);
|
||||
void (*unmap)(void *address, uint32 nbytes);
|
||||
void *(*alloc)(uint32 nbytes);
|
||||
void (*free)(void *address, uint32 nbytes);
|
||||
|
||||
/* File access utilities. These imports keep the xflat libary independent
|
||||
* of the host system's file system.
|
||||
*/
|
||||
|
||||
file_handle_t (*open)(bin_handle_t bin_handle, const char *filename);
|
||||
int (*read)(bin_handle_t bin_handle, file_handle_t file_handle,
|
||||
char *dest, uint32 nbytes,
|
||||
uint32 fpos);
|
||||
void (*close)(file_handle_t file_handle);
|
||||
};
|
||||
|
||||
/* This struct provides a desciption of the currently loaded
|
||||
* instantiation of an xflat binary.
|
||||
*/
|
||||
@@ -113,8 +74,8 @@ struct nxflat_loadinfo_s
|
||||
*/
|
||||
|
||||
uint32 ispace; /* Address where hdr/text is loaded */
|
||||
/* 1st: struct nxflat_hdr_s */
|
||||
/* 2nd: text section */
|
||||
/* 1st: struct nxflat_hdr_s */
|
||||
/* 2nd: text section */
|
||||
uint32 entry_offset; /* Offset from ispace to entry point */
|
||||
uint32 ispace_size; /* Size of ispace. */
|
||||
|
||||
@@ -142,25 +103,18 @@ struct nxflat_loadinfo_s
|
||||
uint32 reloc_start; /* Start of array of struct flat_reloc */
|
||||
uint32 reloc_count; /* Number of elements in reloc array */
|
||||
|
||||
/* These are hooks stored by nxflat_init for subsequent use.
|
||||
* These constitute all points of contact between the flat
|
||||
* library and the rest of the world. These allows the flat
|
||||
* library to opperate in a variey of contexts without change.
|
||||
*/
|
||||
/* File descriptors */
|
||||
|
||||
bin_handle_t bin_handle; /* Like a "this" pointer. Retains
|
||||
* calling context information in callbacks */
|
||||
file_handle_t file_handle; /* Describes an open file */
|
||||
int filfd; /* Descriptor for the file being loaded */
|
||||
|
||||
const struct nxflat_hdr_s *header; /* A reference to the flat file header */
|
||||
const struct nxflat_vtbl_s *vtbl; /* Systam callback vtbl */
|
||||
|
||||
/* 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 */
|
||||
uint32 alloc_start; /* Start of the allocation */
|
||||
uint32 alloc_size; /* Size of the allocation */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
@@ -175,54 +129,42 @@ extern "C" {
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/* Given the header from a possible xFLT executable, verify that it
|
||||
/* Given the header from a possible NXFLAT executable, verify that it
|
||||
* is an NXFLAT executable.
|
||||
*/
|
||||
|
||||
EXTERN int nxflat_verifyheader(const struct nxflat_hdr_s *header);
|
||||
|
||||
/* This function is called to configure xflatlib to process an xFLT
|
||||
* program binary. Upon return, the controlling logic has the opportunity
|
||||
* to adjust the contents of the load_info structure.
|
||||
/* This function is called to configure the library to process an NXFLAT
|
||||
* program binary.
|
||||
*/
|
||||
|
||||
EXTERN int nxflat_init(bin_handle_t bin_handle, file_handle_t file_handle,
|
||||
const struct nxflat_hdr_s *header,
|
||||
const struct nxflat_vtbl_s *vtbl,
|
||||
struct nxflat_loadinfo_s *load_info);
|
||||
|
||||
/* This function unloads the object from memory. This essentially
|
||||
* undoes the actions of nxflat_load.
|
||||
*/
|
||||
|
||||
EXTERN int nxflat_unload(struct nxflat_loadinfo_s *load_info);
|
||||
EXTERN int nxflat_init(const char *filename,
|
||||
struct nxflat_hdr_s *header,
|
||||
struct nxflat_loadinfo_s *loadinfo);
|
||||
|
||||
/* Releases any resources committed by nxflat_init(). This essentially
|
||||
* undoes the actions of nxflat_init or nxflat_init_interpreter. */
|
||||
* undoes the actions of nxflat_init.
|
||||
*/
|
||||
|
||||
EXTERN int nxflat_uninit(struct nxflat_loadinfo_s *load_info);
|
||||
EXTERN int nxflat_uninit(struct nxflat_loadinfo_s *loadinfo);
|
||||
|
||||
/* Loads the binary specified by nxflat_init into memory,
|
||||
* Completes all relocations, and clears BSS.
|
||||
*/
|
||||
|
||||
EXTERN int nxflat_load(struct nxflat_loadinfo_s *load_info);
|
||||
EXTERN int nxflat_load(struct nxflat_loadinfo_s *loadinfo);
|
||||
|
||||
/* Adjust stack size to include argc, envc, xFLT internal usage and
|
||||
* system internal usage. */
|
||||
/* Read 'readsize' bytes from the object file at 'offset' */
|
||||
|
||||
EXTERN void nxflat_adjuststacksize(struct nxflat_loadinfo_s *load_info,
|
||||
int argc, int envc, int system_usage);
|
||||
EXTERN int nxflat_read(struct nxflat_loadinfo_s *loadinfo, char *buffer,
|
||||
int readsize, int offset);
|
||||
|
||||
/* Initialize stack frame for execution */
|
||||
/* This function unloads the object from memory. This essentially
|
||||
* undoes the actions of nxflat_load.
|
||||
*/
|
||||
|
||||
EXTERN uint32 nxflat_initstack(struct nxflat_loadinfo_s *prog_load_info,
|
||||
struct nxflat_loadinfo_s *lib_load_info,
|
||||
int argc, int envc, char *p);
|
||||
|
||||
/* Releases any resources committed by nxflat_init(). */
|
||||
|
||||
EXTERN int nxflat_uninit(struct nxflat_loadinfo_s *load_info);
|
||||
EXTERN int nxflat_unload(struct nxflat_loadinfo_s *loadinfo);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
|
||||
+1
-1
@@ -135,7 +135,7 @@ typedef int STATUS;
|
||||
typedef unsigned int socklen_t;
|
||||
typedef uint16 sa_family_t;
|
||||
|
||||
/* Process entry point */
|
||||
/* Task entry point */
|
||||
|
||||
typedef int (*main_t)(int argc, char *argv[]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user