svcadm(8)을 검색하려면 섹션에서 8 을 선택하고, 맨 페이지 이름에 svcadm을 입력하고 검색을 누른다.
_init(9e)
_fini(9E) Driver Entry Points _fini(9E)
NAME
_fini, _info, _init - loadable module configuration entry points
SYNOPSIS
#include <sys/modctl.h>
int _fini(void)
int _info(struct modinfo *modinfop);
int _init(void)
INTERFACE LEVEL
Solaris DDI specific (Solaris DDI). These entry points are required to
exist in a loadable module.
PARAMETERS
modinfop A pointer to an opaque modinfo structure.
DESCRIPTION
_init() initializes a loadable module, and is called as part of initial
module loading. _init() may optionally perform some module initializa‐
tion, and must return an appropriate error if this initialization
fails. Following any initialization, _init() must call mod_install(9F).
If mod_install() fails, _init() must free any resources initialized
earlier. _init() must return the value returned from mod_install().
_info() returns information about a loadable module. _info() should be
confined to returning the value that is returned by mod_info(9F).
_info() is called as part of initial module loading, and is also called
to provide information to modinfo(8).
_fini() prepares a loadable module for unloading. _fini() is called
when the system wants to unload a module. If the module determines that
it can be unloaded, then _fini() must call mod_remove(9F). Upon suc‐
cessful return from mod_remove(), global resources, such as those ini‐
tialized with _init() or created via ddi_soft_state(9F) routines,
should be destroyed. _fini() must return the value returned from
mod_remove().
_init() is always called to initialize a module, and must return suc‐
cess for the module to be successfully loaded and available for use.
_fini() can only be called at some point after _init() returns success,
when the system tries to unload the module. Upon successful return from
_fini(), no other routine in the module can be called before a subse‐
quent _init() is called. _info() can be called before _init(), and
repeatedly up until _fini() is called, to provide information to the
system about the module.
RETURN VALUES
_init() must return an appropriate error if any module initialization
fails, or must return the return value from mod_install(9F).
_info() must return the return value from mod_remove(9F).
_fini() can return EBUSY if the module should not be unloaded. Other‐
wise, _fini() must return the value that is returned by mod_remove(9F).
EXAMPLES
Example 1 Initializing and Freeing a Mutex
The following example demonstrates how to initialize and free a
mutex(9F).
#include <sys/modctl.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
static struct dev_ops drv_ops;
/* Module linkage information for the kernel */
static struct modldrv modldrv = {
&mod_driverops, /* Type of module. This one is a driver */
"Sample Driver",
&drv_ops /* driver ops */
};
static struct modlinkage modlinkage = {
MODREV_1,
&modldrv,
NULL
};
/* Global driver mutex */
static kmutex_t kmutex;
int
_init(void)
{
int i;
/*
* Initialize global mutex before mod_install()'ing the driver.
* If mod_install() fails, clean up mutex initialization.
*/
mutex_init(&kmutex, NULL, MUTEX_DRIVER, (void *)NULL);
if ((i = mod_install(&modlinkage)) != 0)
mutex_destroy(&kmutex);
return (i);
}
int
_info(struct modinfo *modinfop)
{
return (mod_info(&modlinkage, modinfop));
}
int
_fini(void)
{
int i;
/* If mod_remove() is successful, destroy the global mutex */
if ((i = mod_remove(&modlinkage)) == 0)
mutex_destroy(&kmutex);
return (i);
}
SEE ALSO
add_drv(8), modinfo(8), ddi_soft_state(9F), mod_info(9F),
mod_install(9F), mod_remove(9F), mutex(9F), modldrv(9S), modlink‐
age(9S), modlstrmod(9S)
Writing Device Drivers in Oracle Solaris 11.4
WARNINGS
Do not change the structures referred to by the modlinkage structure
after the call to mod_install(), as the system may copy or change them.
NOTES
Even though the identifiers _fini(), _info(), and _init() appear to be
declared as globals, their scope is restricted by the kernel to the
module that they are defined in.
Oracle Solaris 11.4 9 Mar 2018 _fini(9E)