2009-06-17 20:45:48 +02:00
|
|
|
/****************************************************************************
|
2015-11-14 14:29:47 +01:00
|
|
|
* binfmt/binfmt.h
|
2009-06-17 20:45:48 +02:00
|
|
|
*
|
2021-02-03 14:47:23 +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
|
2009-06-17 20:45:48 +02:00
|
|
|
*
|
2021-02-03 14:47:23 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2009-06-17 20:45:48 +02:00
|
|
|
*
|
2021-02-03 14:47:23 +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
|
|
|
|
* under the License.
|
2009-06-17 20:45:48 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-11-14 14:29:47 +01:00
|
|
|
#ifndef __BINFMT_BINFMT_H
|
|
|
|
#define __BINFMT_BINFMT_H
|
2009-06-17 20:45:48 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2012-10-24 22:19:44 +02:00
|
|
|
#include <nuttx/binfmt/binfmt.h>
|
2009-06-17 20:45:48 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
#define EXTERN extern "C"
|
2014-09-14 22:10:23 +02:00
|
|
|
extern "C"
|
|
|
|
{
|
2009-06-17 20:45:48 +02:00
|
|
|
#else
|
|
|
|
#define EXTERN extern
|
|
|
|
#endif
|
|
|
|
|
2020-04-22 10:24:15 +02:00
|
|
|
/* 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.
|
2009-06-17 20:45:48 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
EXTERN FAR struct binfmt_s *g_binfmts;
|
|
|
|
|
2015-10-03 01:48:24 +02:00
|
|
|
/****************************************************************************
|
2009-06-17 20:45:48 +02:00
|
|
|
* Public Function Prototypes
|
2015-10-03 01:48:24 +02:00
|
|
|
****************************************************************************/
|
2009-06-17 20:45:48 +02:00
|
|
|
|
2014-09-14 22:10:23 +02:00
|
|
|
/****************************************************************************
|
2021-05-23 20:32:34 +02:00
|
|
|
* Name: binfmt_dumpmodule
|
2014-09-14 22:10:23 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Dump the contents of struct binary_s.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2014-09-14 22:10:23 +02:00
|
|
|
* bin - Load structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2018-09-14 14:55:45 +02:00
|
|
|
* Zero (OK) on success; a negated errno value on failure
|
2014-09-14 22:10:23 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
2009-06-17 20:45:48 +02:00
|
|
|
|
2016-06-11 22:14:08 +02:00
|
|
|
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_DEBUG_BINFMT)
|
2021-05-23 20:32:34 +02:00
|
|
|
int binfmt_dumpmodule(FAR const struct binary_s *bin);
|
2009-06-17 20:45:48 +02:00
|
|
|
#else
|
2021-05-23 20:32:34 +02:00
|
|
|
# define binfmt_dumpmodule(bin)
|
2009-06-17 20:45:48 +02:00
|
|
|
#endif
|
|
|
|
|
2015-11-14 14:29:47 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: binfmt_copyargv
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* In the kernel build, the argv list will likely lie in the caller's
|
2021-03-10 21:13:31 +01:00
|
|
|
* address environment and, hence, be inaccessible when we switch to the
|
2015-11-14 14:29:47 +01:00
|
|
|
* address environment of the new process address environment. So we
|
|
|
|
* do not have any real option other than to copy the callers argv[] list.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2015-11-14 14:29:47 +01:00
|
|
|
* argv - Argument list
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2021-05-24 09:06:29 +02:00
|
|
|
* A non-zero copy is returned on success.
|
2015-11-14 14:29:47 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-10-17 17:24:34 +02:00
|
|
|
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
|
|
|
|
int binfmt_copyargv(FAR char * const **copy, FAR char * const *argv);
|
|
|
|
#else
|
|
|
|
# define binfmt_copyargv(copy, argv) (*(copy) = (argv), 0)
|
|
|
|
#endif
|
2015-11-14 14:29:47 +01:00
|
|
|
|
2014-09-14 22:10:23 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: binfmt_freeargv
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Release the copied argv[] list.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2021-05-24 09:06:29 +02:00
|
|
|
* argv - Argument list
|
2014-09-14 22:10:23 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
|
2021-05-24 09:06:29 +02:00
|
|
|
void binfmt_freeargv(FAR char * const *argv);
|
2014-09-14 22:10:23 +02:00
|
|
|
#else
|
2021-05-24 09:06:29 +02:00
|
|
|
# define binfmt_freeargv(argv)
|
2014-09-14 22:10:23 +02:00
|
|
|
#endif
|
2022-04-04 12:11:06 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: binfmt_copyenv
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* In the kernel build, the environment exists in the parent's address
|
|
|
|
* environment and, hence, will be inaccessible when we switch to the
|
|
|
|
* address environment of the new process. So we do not have any real
|
|
|
|
* option other than to copy the parents envp list into an intermediate
|
|
|
|
* buffer that resides in neutral kernel memory.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* envp - Allocated environment strings
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* A non-zero copy is returned on success.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_DISABLE_ENVIRON
|
2022-10-17 17:24:34 +02:00
|
|
|
# define binfmt_copyenv(copy, envp) binfmt_copyargv(copy, envp)
|
2022-04-04 12:11:06 +02:00
|
|
|
#else
|
2022-10-17 17:24:34 +02:00
|
|
|
# define binfmt_copyenv(copy, envp) (*(copy) = (envp), 0)
|
2022-04-04 12:11:06 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: binfmt_freeenv
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Release the copied envp[] list.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* envp - Allocated environment strings
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_DISABLE_ENVIRON
|
|
|
|
# define binfmt_freeenv(envp) binfmt_freeargv(envp)
|
|
|
|
#else
|
|
|
|
# define binfmt_freeenv(envp)
|
|
|
|
#endif
|
2014-09-14 22:10:23 +02:00
|
|
|
|
2019-08-23 17:07:40 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: builtin_initialize
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* In order to use the builtin binary format, this function must be called
|
|
|
|
* during system initialize to register the builtin binary format.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* This is a NuttX internal function so it follows the convention that
|
|
|
|
* 0 (OK) is returned on success and a negated errno is returned on
|
|
|
|
* failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-02-13 13:07:18 +01:00
|
|
|
#ifdef CONFIG_BUILTIN
|
2019-08-23 17:07:40 +02:00
|
|
|
int builtin_initialize(void);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: builtin_uninitialize
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Unregister the builtin binary loader
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-02-13 13:07:18 +01:00
|
|
|
#ifdef CONFIG_BUILTIN
|
2019-08-23 17:07:40 +02:00
|
|
|
void builtin_uninitialize(void);
|
|
|
|
#endif
|
|
|
|
|
2009-06-17 20:45:48 +02:00
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-11-14 14:29:47 +01:00
|
|
|
#endif /* __BINFMT_BINFMT_H */
|