diff --git a/boards/boardctl.c b/boards/boardctl.c index a2ea7e9306..343dc937b8 100644 --- a/boards/boardctl.c +++ b/boards/boardctl.c @@ -394,6 +394,40 @@ int boardctl(unsigned int cmd, uintptr_t arg) break; #endif +#ifdef CONFIG_BUILTIN + /* CMD: BOARDIOC_BUILTINS + * DESCRIPTION: Provide the user-space list of built-in applications for + * use by BINFS in protected mode. Normally this is small + * set of globals provided by user-space logic. It provides + * name-value pairs for associating built-in application + * names with user-space entry point addresses. These + * globals are only needed for use by BINFS which executes + * built-in applications from kernel-space in PROTECTED mode. + * In the FLAT build, the user space globals are readily + * available. (BINFS is not supportable in KERNEL mode since + * user-space address have no general meaning that + * configuration). + * ARG: A pointer to an instance of struct boardioc_builtin_s + * CONFIGURATION: This BOARDIOC command is always available when + * CONFIG_BUILTIN is enabled, but does nothing unless + * CONFIG_BUILD_KERNEL and CONFIG_FS_BINFS are selected. + * DEPENDENCIES: None + */ + + case BOARDIOC_BUILTINS: + { +#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_FS_BINFS) + FAR const struct boardioc_builtin_s *builtin = + (FAR const struct boardioc_builtin_s *)arg; + + DEBUGASSERT(builtin != NULL); + builtin_setlist(builtin->builtins, builtin->count); +#endif + ret = OK; + } + break; +#endif + #ifdef CONFIG_BOARDCTL_USBDEVCTRL /* CMD: BOARDIOC_USBDEV_CONTROL * DESCRIPTION: Manage USB device classes diff --git a/include/nuttx/compiler.h b/include/nuttx/compiler.h index d6ea6c9dec..c583b39749 100644 --- a/include/nuttx/compiler.h +++ b/include/nuttx/compiler.h @@ -258,7 +258,7 @@ # undef CONFIG_PTR_IS_NOT_INT #endif -/* GCC supports inlined functions for version C99 and above */ +/* GCC supports inlined functions for C++ and for C version C99 and above */ # if defined(__cplusplus) || !defined(__STDC_VERSION__) || __STDC_VERSION__ >= 199901L # define CONFIG_HAVE_INLINE 1 diff --git a/include/nuttx/lib/builtin.h b/include/nuttx/lib/builtin.h index 25cad420e5..2050b20f27 100644 --- a/include/nuttx/lib/builtin.h +++ b/include/nuttx/lib/builtin.h @@ -56,12 +56,9 @@ * Pre-processor Definitions ****************************************************************************/ -/* This logic is not usable in the KERNEL build and, furthermore, it has no - * meaning in __KERNEL__ blob of a protected build. - */ +/* This logic is not usable in the KERNEL build from within the kernel. */ -#if (defined(CONFIG_BUILD_FLAT) || \ - (defined(CONFIG_BUILD_PROTECTED )&& !__KERNEL__)) +#if !defined(CONFIG_BUILD_KERNEL) || !defined(__KERNEL__) # define HAVE_BUILTIN_CONTEXT #endif @@ -89,15 +86,65 @@ extern "C" #define EXTERN extern #endif -/* These must be provided the application layer */ +#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_FS_BINFS) && \ + defined(__KERNEL__) +/* In the PROTECTED build, the builtin arrays are only needed by BINFS. + * in this case, the user-space globals are not accessible and must be + * provided to the OS via the boardctl(BOARDIOC_BUILTINS) call. In this + * case, the PROTECTED kernel will keep its own copy of the user-space + * array. + * + * The call to boardctl(BOARDIOC_BUILTINS) must be provided by the + * application layer. + */ -EXTERN const struct builtin_s g_builtins[]; +EXTERN FAR struct builtin_s * const *g_builtins; +EXTERN int g_builtin_count; + +#else +/* In the FLAT build, the builtin list is just a global global array and + * count exported from user space via the backdoor left open by the FLAT + * address space. These globals must be provided the application layer. + */ + +EXTERN FAR const struct builtin_s g_builtins[]; EXTERN const int g_builtin_count; +#endif /**************************************************************************** * Public Functions ****************************************************************************/ +/**************************************************************************** + * Name: builtin_setlist + * + * Description: + * Saves the user-space list of built-in applications for use by BINFS in + * protected mode. Normally this is small set of globals provided by + * user-space logic. It provides name-value pairs for associating + * built-in application names with user-space entry point addresses. + * These globals are only needed for use by BINFS which executes built-in + * applications from kernel-space in PROTECTED mode. In the FLAT build, + * the user space globals are readily available. (BINFS is not + * supportable in KERNEL mode since user-space address have no general + * meaning that configuration). + * + * Input Parameters: + * builtins - The list of built-in functions. Each entry is a name-value + * pair that maps a builtin function name to its user-space + * entry point address. + * count - The number of name-value pairs in the builtin list. + * + * Returned Value: + * None + * + ****************************************************************************/ + +#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_FS_BINFS) && \ + defined(__KERNEL__) +void builtin_setlist(FAR struct builtin_s * const *builtins, int count); +#endif + /**************************************************************************** * Name: builtin_isavail * diff --git a/include/sys/boardctl.h b/include/sys/boardctl.h index d20a0ee12c..230ab0bec2 100644 --- a/include/sys/boardctl.h +++ b/include/sys/boardctl.h @@ -111,6 +111,25 @@ * CONFIGURATION: CONFIG_BOARDCTL_OS_SYMTAB * DEPENDENCIES: None * + * CMD: BOARDIOC_BUILTINS + * DESCRIPTION: Provide the user-space list of built-in applications for + * use by BINFS in protected mode. Normally this is small + * set of globals provided by user-space logic. It provides + * name-value pairs for associating built-in application + * names with user-space entry point addresses. These + * globals are only needed for use by BINFS which executes + * built-in applications from kernel-space in PROTECTED mode. + * In the FLAT build, the user space globals are readily + * available. (BINFS is not supportable in KERNEL mode since + * user-space address have no general meaning that + * configuration). + * ARG: A pointer to an instance of struct boardioc_builtin_s + * CONFIGURATION: This BOARDIOC command is always available when + * CONFIG_BUILTIN is enabled, but does nothing unless + * CONFIG_BUILD_PROTECTED and CONFIG_FS_BINFS are also + * selected. + * DEPENDENCIES: None + * * CMD: BOARDIOC_USBDEV_CONTROL * DESCRIPTION: Manage USB device classes * ARG: A pointer to an instance of struct boardioc_usbdev_ctrl_s @@ -163,12 +182,13 @@ #define BOARDIOC_UNIQUEID _BOARDIOC(0x0005) #define BOARDIOC_APP_SYMTAB _BOARDIOC(0x0006) #define BOARDIOC_OS_SYMTAB _BOARDIOC(0x0007) -#define BOARDIOC_USBDEV_CONTROL _BOARDIOC(0x0008) -#define BOARDIOC_NX_START _BOARDIOC(0x0009) -#define BOARDIOC_VNC_START _BOARDIOC(0x000a) -#define BOARDIOC_NXTERM _BOARDIOC(0x000b) -#define BOARDIOC_NXTERM_IOCTL _BOARDIOC(0x000c) -#define BOARDIOC_TESTSET _BOARDIOC(0x000d) +#define BOARDIOC_BUILTINS _BOARDIOC(0x0008) +#define BOARDIOC_USBDEV_CONTROL _BOARDIOC(0x0009) +#define BOARDIOC_NX_START _BOARDIOC(0x000a) +#define BOARDIOC_VNC_START _BOARDIOC(0x000b) +#define BOARDIOC_NXTERM _BOARDIOC(0x000c) +#define BOARDIOC_NXTERM_IOCTL _BOARDIOC(0x000d) +#define BOARDIOC_TESTSET _BOARDIOC(0x000e) /* If CONFIG_BOARDCTL_IOCTL=y, then board-specific commands will be support. * In this case, all commands not recognized by boardctl() will be forwarded @@ -190,13 +210,24 @@ * required. */ -struct symtab_s; /* Forward reference */ +struct symtab_s; /* Forward reference */ struct boardioc_symtab_s { FAR struct symtab_s *symtab; int nsymbols; }; +#ifdef CONFIG_BUILTIN +/* Arguments passed with the BOARDIOC_BUILTIN command */ + +struct builtin_s; /* Forward reference */ +struct boardioc_builtin_s +{ + FAR char * const *builtins; + int count; +}; +#endif + #ifdef CONFIG_BOARDCTL_USBDEVCTRL /* This structure provides the argument BOARDIOC_USBDEV_CONTROL and * describes which device should be controlled and what should be diff --git a/libs/libc/builtin/Make.defs b/libs/libc/builtin/Make.defs index 6e2528d73d..4b35f107f2 100644 --- a/libs/libc/builtin/Make.defs +++ b/libs/libc/builtin/Make.defs @@ -38,6 +38,7 @@ ifeq ($(CONFIG_BUILTIN),y) # Builtin library files CSRCS += lib_builtin_getname.c lib_builtin_isavail.c lib_builtin_forindex.c +CSRCS += lib_builtin_setlist.c # Hook the builtin subdirectory into the build diff --git a/libs/libc/builtin/lib_builtin_setlist.c b/libs/libc/builtin/lib_builtin_setlist.c new file mode 100644 index 0000000000..d20f4e1d2d --- /dev/null +++ b/libs/libc/builtin/lib_builtin_setlist.c @@ -0,0 +1,96 @@ +/**************************************************************************** + * libs/libc/builtin/libbuiltin_getname.c + * + * Originally by: + * + * Copyright (C) 2011 Uros Platise. All rights reserved. + * Author: Uros Platise + * + * With subsequent updates, modifications, and general maintenance by: + * + * Copyright (C) 2012-2013, 2019 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_FS_BINFS) && \ + defined(__KERNEL__) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +FAR struct builtin_s * const *g_builtins; +int g_builtin_count; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: builtin_setlist + * + * Description: + * Saves the user-space list of built-in applications for use by BINFS in + * protected mode. Normally this is small set of globals provided by + * user-space logic. It provides name-value pairs for associating + * built-in application names with user-space entry point addresses. + * These globals are only needed for use by BINFS which executes built-in + * applications from kernel-space in PROTECTED mode. In the FLAT build, + * the user space globals are readily available. (BINFS is not + * supportable in KERNEL mode since user-space address have no general + * meaning that configuration). + * + * Input Parameters: + * builtins - The list of built-in functions. Each entry is a name-value + * pair that maps a builtin function name to its user-space + * entry point address. + * count - The number of name-value pairs in the builtin list. + * + * Returned Value: + * None + * + ****************************************************************************/ + +void builtin_setlist(FAR struct builtin_s * const *builtins, int count) +{ + g_builtins = builtins; + g_builtin_count = builtins; +} + +#endif /* CONFIG_BUILD_PROTECTED && CONFIG_FS_BINFS && __KERNEL__ */