2013-01-16 20:08:23 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* binfmt/builtin.c
|
|
|
|
*
|
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
|
2013-01-16 20:08:23 +01:00
|
|
|
*
|
2021-02-03 14:47:23 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-01-16 20:08:23 +01: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.
|
2013-01-16 20:08:23 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <debug.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <nuttx/binfmt/binfmt.h>
|
2019-08-23 17:07:40 +02:00
|
|
|
#include <nuttx/lib/builtin.h>
|
2013-01-16 20:08:23 +01:00
|
|
|
|
2022-02-13 13:07:18 +01:00
|
|
|
#ifdef CONFIG_BUILTIN
|
2013-01-16 20:08:23 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-05-24 11:12:06 +02:00
|
|
|
static int builtin_loadbinary(FAR struct binary_s *binp,
|
|
|
|
FAR const char *filename,
|
|
|
|
FAR const struct symtab_s *exports,
|
|
|
|
int nexports);
|
2013-01-16 20:08:23 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static struct binfmt_s g_builtin_binfmt =
|
|
|
|
{
|
|
|
|
NULL, /* next */
|
|
|
|
builtin_loadbinary, /* load */
|
2014-05-09 00:58:10 +02:00
|
|
|
NULL, /* unload */
|
2013-01-16 20:08:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: builtin_loadbinary
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Verify that the file is an builtin binary.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-05-24 11:12:06 +02:00
|
|
|
static int builtin_loadbinary(FAR struct binary_s *binp,
|
|
|
|
FAR const char *filename,
|
|
|
|
FAR const struct symtab_s *exports,
|
|
|
|
int nexports)
|
2013-01-16 20:08:23 +01:00
|
|
|
{
|
2018-09-15 19:47:24 +02:00
|
|
|
FAR const struct builtin_s *builtin;
|
2021-08-31 09:58:16 +02:00
|
|
|
FAR char *name;
|
2013-01-16 20:08:23 +01:00
|
|
|
int index;
|
|
|
|
|
2021-05-24 11:12:06 +02:00
|
|
|
binfo("Loading file: %s\n", filename);
|
2013-01-16 20:08:23 +01:00
|
|
|
|
2021-08-31 09:58:16 +02:00
|
|
|
name = strrchr(filename, '/');
|
|
|
|
if (name != NULL)
|
2013-01-16 20:08:23 +01:00
|
|
|
{
|
2021-08-31 09:58:16 +02:00
|
|
|
filename = name + 1;
|
2013-01-16 20:08:23 +01:00
|
|
|
}
|
|
|
|
|
2021-08-31 09:58:16 +02:00
|
|
|
/* Looking up the index to this name in g_builtins[] */
|
2013-01-16 20:08:23 +01:00
|
|
|
|
|
|
|
index = builtin_isavail(filename);
|
|
|
|
if (index < 0)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
berr("ERROR: %s is not a builtin application\n", filename);
|
2019-09-11 20:37:29 +02:00
|
|
|
return index;
|
2013-01-16 20:08:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the load information. NOTE: that there is no way to configure
|
|
|
|
* the priority. That is a bug and needs to be fixed.
|
|
|
|
*/
|
|
|
|
|
2023-07-02 18:11:02 +02:00
|
|
|
builtin = builtin_for_index(index);
|
2022-09-03 07:10:23 +02:00
|
|
|
if (builtin == NULL)
|
|
|
|
{
|
|
|
|
berr("ERROR: %s is not a builtin application\n", filename);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2018-09-15 19:47:24 +02:00
|
|
|
binp->entrypt = builtin->main;
|
|
|
|
binp->stacksize = builtin->stacksize;
|
|
|
|
binp->priority = builtin->priority;
|
2023-08-12 01:39:45 +02:00
|
|
|
#ifdef CONFIG_SCHED_USER_IDENTITY
|
|
|
|
binp->uid = builtin->uid;
|
|
|
|
binp->gid = builtin->gid;
|
|
|
|
binp->mode = builtin->mode;
|
|
|
|
#endif
|
|
|
|
|
2013-01-16 20:08:23 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: builtin_initialize
|
|
|
|
*
|
|
|
|
* Description:
|
2018-08-24 14:10:50 +02:00
|
|
|
* In order to use the builtin binary format, this function must be called
|
|
|
|
* during system initialize to register the builtin binary format.
|
2013-01-16 20:08:23 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int builtin_initialize(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Register ourselves as a binfmt loader */
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
binfo("Registering Builtin Loader\n");
|
2013-01-16 20:08:23 +01:00
|
|
|
|
|
|
|
ret = register_binfmt(&g_builtin_binfmt);
|
|
|
|
if (ret != 0)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
berr("Failed to register binfmt: %d\n", ret);
|
2013-01-16 20:08:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: builtin_uninitialize
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Unregister the builtin binary loader
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void builtin_uninitialize(void)
|
|
|
|
{
|
2020-01-02 17:49:34 +01:00
|
|
|
unregister_binfmt(&g_builtin_binfmt);
|
2013-01-16 20:08:23 +01:00
|
|
|
}
|
|
|
|
|
2022-02-13 13:07:18 +01:00
|
|
|
#endif /* CONFIG_BUILTIN */
|