incubator-nuttx/include/nuttx/module.h

147 lines
5.2 KiB
C

/****************************************************************************
* include/nuttx/module.h
*
* SPDX-License-Identifier: Apache-2.0
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*
****************************************************************************/
#ifndef __INCLUDE_NUTTX_MODULE_H
#define __INCLUDE_NUTTX_MODULE_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Name: insmod
*
* Description:
* Verify that the file is an ELF module binary and, if so, load the
* module into kernel memory and initialize it for use.
*
* NOTE:
* modlib_setsymtab had to have been called in board-specific OS logic
* prior to calling this function from application logic (perhaps via
* boardctl(BOARDIOC_OS_SYMTAB). Otherwise, insmod will be unable to
* resolve symbols in the OS module.
*
* Input Parameters:
*
* filename - Full path to the module binary to be loaded
* modname - The name that can be used to refer to the module after
* it has been loaded.
*
* Returned Value:
* A non-NULL module handle that can be used on subsequent calls to other
* module interfaces is returned on success. If insmod() was unable to
* load the module insmod() will return a NULL handle and the errno
* variable will be set appropriately.
*
****************************************************************************/
FAR void *insmod(FAR const char *filename, FAR const char *modname);
/****************************************************************************
* Name: rmmod
*
* Description:
* Remove a previously installed module from memory.
*
* Input Parameters:
* handle - The module handler previously returned by insmod().
*
* Returned Value:
* Zero (OK) on success. On any failure, -1 (ERROR) is returned the
* errno value is set appropriately.
*
****************************************************************************/
int rmmod(FAR void *handle);
/****************************************************************************
* Name: modsym
*
* Description:
* modsym() returns the address of a symbol defined within the object that
* was previously made accessible through a insmod() call. handle is the
* value returned from a call to insmod() (and which has not since been
* released via a call to rmmod()), name is the symbol's name as a
* character string.
*
* The returned symbol address will remain valid until rmmod() is called.
*
* Input Parameters:
* handle - The opaque, non-NULL value returned by a previous successful
* call to insmod().
* name - A pointer to the symbol name string.
*
* Returned Value:
* The address associated with the symbol is returned on success.
* If handle does not refer to a valid module opened by insmod(), or if
* the named symbol cannot be found within any of the objects associated
* with handle, modsym() will return NULL and the errno variable will be
* set appropriately.
*
****************************************************************************/
FAR const void *modsym(FAR void *handle, FAR const char *name);
/****************************************************************************
* Name: modhandle
*
* Description:
* modhandle() returns the module handle for the installed module with the
* provided name. A secondary use of this function is to determine if a
* module has been loaded or not.
*
* Input Parameters:
* name - A pointer to the module name string.
*
* Returned Value:
* The non-NULL module handle previously returned by insmod() is returned
* on success. If no module with that name is installed, modhandle() will
* return a NULL handle and the errno variable will be set appropriately.
*
****************************************************************************/
FAR void *modhandle(FAR const char *name);
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __INCLUDE_NUTTX_MODULE_H */