#include <sys/types.h>
#include <sys/systm.h>
#include <sys/param.h>
#include <sys/user.h>
#include <sys/vm.h>
#include <sys/conf.h>
#include <sys/class.h>
#include <sys/vfs.h>
#include <sys/vnode.h>
#include <sys/mount.h>
#include <sys/systm.h>
#include <sys/modctl.h>
#include <sys/exec.h>
#include <sys/exechdr.h>
#include <sys/devops.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <sys/cmn_err.h>
#include <sys/hwconf.h>
#include <sys/ddi_impldefs.h>
#include <sys/autoconf.h>
#include <sys/disp.h>
#include <sys/kmem.h>
#include <sys/instance.h>
#include <sys/modhash.h>
#include <sys/dacf.h>
#include <sys/debug.h>
#include <ipp/ipp.h>
#include <sys/strsubr.h>
#include <sys/kcpc.h>
#include <sys/brand.h>
#include <sys/cpc_pcbe.h>
#include <sys/kstat.h>
#include <sys/socketvar.h>
#include <sys/kiconv.h>
extern int moddebug;
extern struct cb_ops no_cb_ops;
extern struct dev_ops nodev_ops;
extern struct dev_ops mod_nodev_ops;
extern struct modctl *mod_getctl(struct modlinkage *);
extern int errsys(), nodev(), nulldev();
extern int findmodbyname(char *);
extern int mod_getsysnum(const char *);
extern struct execsw execsw[];
struct dev_ops mod_nodev_ops = {
DEVO_REV,
0,
ddi_no_info,
nulldev,
nulldev,
ddifail,
nodev,
nulldev,
&no_cb_ops,
(struct bus_ops *)0
};
static int mod_null(struct modldrv *, struct modlinkage *);
static int mod_infonull(void *, struct modlinkage *, int *);
struct mod_ops mod_miscops = {
mod_null, mod_null, mod_infonull
};
struct mod_ops mod_cpuops = {
mod_null, mod_null, mod_infonull
};
struct mod_ops mod_cryptoops = {
mod_null, mod_null, mod_infonull
};
static int mod_installipp(struct modlipp *, struct modlinkage *);
static int mod_removeipp(struct modlipp *, struct modlinkage *);
static int mod_infoipp(struct modlipp *, struct modlinkage *, int *);
struct mod_ops mod_ippops = {
mod_installipp, mod_removeipp, mod_infoipp
};
static int mod_infodrv(struct modldrv *, struct modlinkage *, int *);
static int mod_installdrv(struct modldrv *, struct modlinkage *);
static int mod_removedrv(struct modldrv *, struct modlinkage *);
struct mod_ops mod_driverops = {
mod_installdrv, mod_removedrv, mod_infodrv
};
static int mod_infosys(struct modlsys *, struct modlinkage *, int *);
static int mod_installsys(struct modlsys *, struct modlinkage *);
static int mod_removesys(struct modlsys *, struct modlinkage *);
struct mod_ops mod_syscallops = {
mod_installsys, mod_removesys, mod_infosys
};
#ifdef _SYSCALL32_IMPL
static int mod_infosys32(struct modlsys *, struct modlinkage *, int *);
static int mod_installsys32(struct modlsys *, struct modlinkage *);
static int mod_removesys32(struct modlsys *, struct modlinkage *);
struct mod_ops mod_syscallops32 = {
mod_installsys32, mod_removesys32, mod_infosys32
};
#endif
static int mod_infofs(struct modlfs *, struct modlinkage *, int *);
static int mod_installfs(struct modlfs *, struct modlinkage *);
static int mod_removefs(struct modlfs *, struct modlinkage *);
struct mod_ops mod_fsops = {
mod_installfs, mod_removefs, mod_infofs
};
static int mod_infostrmod(struct modlstrmod *, struct modlinkage *, int *);
static int mod_installstrmod(struct modlstrmod *, struct modlinkage *);
static int mod_removestrmod(struct modlstrmod *, struct modlinkage *);
struct mod_ops mod_strmodops = {
mod_installstrmod, mod_removestrmod, mod_infostrmod
};
static int mod_infosockmod(struct modlsockmod *, struct modlinkage *, int *);
static int mod_installsockmod(struct modlsockmod *, struct modlinkage *);
static int mod_removesockmod(struct modlsockmod *, struct modlinkage *);
struct mod_ops mod_sockmodops = {
mod_installsockmod, mod_removesockmod, mod_infosockmod
};
static int mod_infosched(struct modlsched *, struct modlinkage *, int *);
static int mod_installsched(struct modlsched *, struct modlinkage *);
static int mod_removesched(struct modlsched *, struct modlinkage *);
struct mod_ops mod_schedops = {
mod_installsched, mod_removesched, mod_infosched
};
static int mod_infoexec(struct modlexec *, struct modlinkage *, int *);
static int mod_installexec(struct modlexec *, struct modlinkage *);
static int mod_removeexec(struct modlexec *, struct modlinkage *);
struct mod_ops mod_execops = {
mod_installexec, mod_removeexec, mod_infoexec
};
static int mod_infodacf(struct modldacf *, struct modlinkage *, int *);
static int mod_installdacf(struct modldacf *, struct modlinkage *);
static int mod_removedacf(struct modldacf *, struct modlinkage *);
struct mod_ops mod_dacfops = {
mod_installdacf, mod_removedacf, mod_infodacf
};
static int mod_installpcbe(struct modlpcbe *, struct modlinkage *);
static int mod_removepcbe(struct modlpcbe *, struct modlinkage *);
struct mod_ops mod_pcbeops = {
mod_installpcbe, mod_removepcbe, mod_infonull
};
static int mod_installbrand(struct modlbrand *, struct modlinkage *);
static int mod_removebrand(struct modlbrand *, struct modlinkage *);
struct mod_ops mod_brandops = {
mod_installbrand, mod_removebrand, mod_infonull
};
static int mod_installkiconv(struct modlkiconv *, struct modlinkage *);
static int mod_removekiconv(struct modlkiconv *, struct modlinkage *);
struct mod_ops mod_kiconvops = {
mod_installkiconv, mod_removekiconv, mod_infonull
};
static struct sysent *mod_getsysent(struct modlinkage *, struct sysent *);
static char uninstall_err[] = "Cannot uninstall %s; not installed";
#define DRV_DBG MODDEBUG_LOADMSG2
static void mod_dprintf(int flag, const char *format, ...) __KPRINTFLIKE(2);
static void
mod_dprintf(int flag, const char *format, ...)
{
va_list alist;
if ((moddebug & flag) != 0) {
va_start(alist, format);
(void) vprintf(format, alist);
va_end(alist);
}
}
int
mod_install(struct modlinkage *modlp)
{
int retval = -1;
struct modlmisc **linkpp;
struct modlmisc **linkpp1;
if (modlp->ml_rev != MODREV_1) {
printf("mod_install: modlinkage structure is not MODREV_1\n");
return (EINVAL);
}
linkpp = (struct modlmisc **)&modlp->ml_linkage[0];
while (*linkpp != NULL) {
if ((retval = MODL_INSTALL(*linkpp, modlp)) != 0) {
linkpp1 = (struct modlmisc **)&modlp->ml_linkage[0];
while (linkpp1 != linkpp) {
MODL_REMOVE(*linkpp1, modlp);
linkpp1++;
}
break;
}
linkpp++;
}
return (retval);
}
static char *reins_err =
"Could not reinstall %s\nReboot to correct the problem";
int
mod_remove(struct modlinkage *modlp)
{
int retval = 0;
struct modlmisc **linkpp, *last_linkp;
linkpp = (struct modlmisc **)&modlp->ml_linkage[0];
while (*linkpp != NULL) {
if ((retval = MODL_REMOVE(*linkpp, modlp)) != 0) {
last_linkp = *linkpp;
linkpp = (struct modlmisc **)&modlp->ml_linkage[0];
while (*linkpp != last_linkp) {
if (MODL_INSTALL(*linkpp, modlp) != 0) {
cmn_err(CE_WARN, reins_err,
(*linkpp)->misc_linkinfo);
break;
}
linkpp++;
}
break;
}
linkpp++;
}
return (retval);
}
int
mod_info(struct modlinkage *modlp, struct modinfo *modinfop)
{
int i;
int retval = 0;
struct modspecific_info *msip;
struct modlmisc **linkpp;
modinfop->mi_rev = modlp->ml_rev;
linkpp = (struct modlmisc **)modlp->ml_linkage;
msip = &modinfop->mi_msinfo[0];
for (i = 0; i < MODMAXLINK; i++) {
if (*linkpp == NULL) {
msip->msi_linkinfo[0] = '\0';
} else {
(void) strncpy(msip->msi_linkinfo,
(*linkpp)->misc_linkinfo, MODMAXLINKINFOLEN);
retval = MODL_INFO(*linkpp, modlp, &msip->msi_p0);
if (retval != 0)
break;
linkpp++;
}
msip++;
}
if (modinfop->mi_info == MI_INFO_LINKAGE) {
modinfop->mi_base = (void *)modlp;
}
if (retval == 0)
return (1);
return (0);
}
const char *
mod_modname(struct modlinkage *modlp)
{
struct modctl *mcp;
if ((mcp = mod_getctl(modlp)) == NULL)
return (NULL);
return (mcp->mod_modname);
}
static int
mod_null(struct modldrv *modl, struct modlinkage *modlp)
{
return (0);
}
static int
mod_infonull(void *modl, struct modlinkage *modlp, int *p0)
{
*p0 = -1;
return (0);
}
static int
mod_infodrv(struct modldrv *modl, struct modlinkage *modlp, int *p0)
{
struct modctl *mcp;
char *mod_name;
if ((mcp = mod_getctl(modlp)) == NULL) {
*p0 = -1;
return (0);
}
mod_name = mcp->mod_modname;
*p0 = ddi_name_to_major(mod_name);
return (0);
}
static int
mod_infodacf(struct modldacf *modl, struct modlinkage *modlp, int *p0)
{
if (mod_getctl(modlp) == NULL) {
*p0 = -1;
return (0);
}
*p0 = 0;
return (0);
}
static int
mod_installdacf(struct modldacf *modl, struct modlinkage *modlp)
{
struct modctl *mcp;
if ((mcp = mod_getctl(modlp)) == NULL)
return (EINVAL);
return (dacf_module_register(mcp->mod_modname, modl->dacf_dacfsw));
}
static int
mod_removedacf(struct modldacf *modl, struct modlinkage *modlp)
{
struct modctl *mcp;
if ((mcp = mod_getctl(modlp)) == NULL)
return (EINVAL);
return (dacf_module_unregister(mcp->mod_modname));
}
static int
mod_installpcbe(struct modlpcbe *modl, struct modlinkage *modlp)
{
if (modl->pcbe_ops->pcbe_ver != PCBE_VER_1) {
cmn_err(CE_WARN, "pcbe '%s' version mismatch",
modl->pcbe_linkinfo);
return (EINVAL);
}
kcpc_register_pcbe(modl->pcbe_ops);
return (0);
}
static int
mod_removepcbe(struct modlpcbe *modl, struct modlinkage *modlp)
{
return (EBUSY);
}
static int
mod_installbrand(struct modlbrand *modl, struct modlinkage *modlp)
{
return (brand_register(modl->brand_branddef));
}
static int
mod_removebrand(struct modlbrand *modl, struct modlinkage *modlp)
{
return (brand_unregister(modl->brand_branddef));
}
static int
mod_installdrv(struct modldrv *modl, struct modlinkage *modlp)
{
struct modctl *mcp;
struct dev_ops *ops;
char *modname;
major_t major;
struct dev_ops *dp;
struct devnames *dnp;
struct streamtab *str;
cdevsw_impl_t *cdp;
uint_t sqtype;
uint_t qflag;
uint_t flag;
int err = 0;
if ((mcp = mod_getctl(modlp)) == NULL) {
cmn_err(CE_WARN, "mod_install: bad module linkage data");
err = ENXIO;
goto done;
}
modname = mcp->mod_modname;
if ((major = ddi_name_to_major(modname)) == DDI_MAJOR_T_NONE) {
cmn_err(CE_WARN,
"mod_installdrv: no major number for %s", modname);
err = ENXIO;
goto done;
}
ops = modl->drv_dev_ops;
if (ops->devo_bus_ops == NULL && ops->devo_cb_ops != NULL &&
!(ops->devo_cb_ops->cb_flag & D_MP)) {
cmn_err(CE_WARN,
"mod_installdrv: MT-unsafe driver '%s' rejected", modname);
err = ENXIO;
goto done;
}
if (ops->devo_bus_ops != NULL &&
ops->devo_bus_ops->bus_map_fault != NULL &&
ops->devo_bus_ops->bus_map_fault != i_ddi_map_fault &&
ops->devo_bus_ops->busops_rev < BUSO_REV_8) {
cmn_err(CE_WARN,
"mod_installdrv: busops' revision of '%s' is too low"
" (must be at least 8)", modname);
err = ENXIO;
goto done;
}
dnp = &devnamesp[major];
LOCK_DEV_OPS(&dnp->dn_lock);
dp = devopsp[major];
if (dnp->dn_flags & (DN_DRIVER_REMOVED|DN_DRIVER_INACTIVE)) {
#ifdef DEBUG
cmn_err(CE_CONT,
"mod_installdrv: driver %s not installed", modname);
#endif
err = ENXIO;
goto unlock;
}
if (dp != &nodev_ops && dp != &mod_nodev_ops) {
cmn_err(CE_WARN,
"mod_installdrv: driver already installed %s", modname);
err = EALREADY;
goto unlock;
}
devopsp[major] = ops;
if ((str = STREAMSTAB(major)) != NULL) {
flag = CBFLAG(major);
if ((err = devflg_to_qflag(str, flag, &qflag, &sqtype)) != 0)
goto unlock;
cdp = &devimpl[major];
ASSERT(cdp->d_str == NULL);
cdp->d_str = str;
cdp->d_qflag = qflag | QISDRV;
cdp->d_sqtype = sqtype;
}
if (ops->devo_bus_ops == NULL)
dnp->dn_flags |= DN_LEAF_DRIVER;
unlock:
UNLOCK_DEV_OPS(&dnp->dn_lock);
done:
return (err);
}
static int
mod_removedrv(struct modldrv *modl, struct modlinkage *modlp)
{
struct modctl *mcp;
struct dev_ops *ops;
struct devnames *dnp;
struct dev_ops *dp;
major_t major;
char *modname;
extern kthread_id_t mod_aul_thread;
struct streamtab *str;
cdevsw_impl_t *cdp;
int err = 0;
if ((moddebug & MODDEBUG_NOAUL_DRV) && (mod_aul_thread == curthread)) {
err = EBUSY;
goto done;
}
mcp = mod_getctl(modlp);
ASSERT(mcp != NULL);
modname = mcp->mod_modname;
if ((major = ddi_name_to_major(modname)) == -1) {
cmn_err(CE_WARN, uninstall_err, modname);
err = EINVAL;
goto done;
}
ops = modl->drv_dev_ops;
dnp = &(devnamesp[major]);
LOCK_DEV_OPS(&(dnp->dn_lock));
dp = devopsp[major];
if (dp != ops) {
cmn_err(CE_NOTE, "mod_removedrv: mismatched driver for %s",
modname);
err = EBUSY;
goto unlock;
}
if (!DRV_UNLOADABLE(dp)) {
mod_dprintf(DRV_DBG, "Cannot unload device driver <%s>,"
" refcnt %d\n", modname, dp->devo_refcnt);
err = EBUSY;
goto unlock;
}
if ((str = STREAMSTAB(major)) != NULL) {
cdp = &devimpl[major];
ASSERT(cdp->d_str == str);
cdp->d_str = NULL;
if (cdp->d_dmp != NULL) {
rele_dm(cdp->d_dmp);
cdp->d_dmp = NULL;
}
}
devopsp[major] = &mod_nodev_ops;
dnp->dn_flags &= ~(DN_DRIVER_HELD|DN_NO_AUTODETACH);
unlock:
UNLOCK_DEV_OPS(&(dnp->dn_lock));
done:
return (err);
}
static int
mod_infosysnum(struct modlinkage *modlp, struct sysent table[])
{
struct sysent *sysp;
if ((sysp = mod_getsysent(modlp, table)) == NULL)
return (-1);
return ((int)(sysp - table));
}
static int
mod_installsys_sysent(
struct modlsys *modl,
struct modlinkage *modlp,
struct sysent table[])
{
struct sysent *sysp;
struct sysent *mp;
#ifdef DEBUG
switch (modl->sys_sysent->sy_flags & SE_RVAL_MASK) {
case SE_32RVAL1:
case SE_32RVAL1 | SE_32RVAL2:
case SE_64RVAL:
break;
default:
cmn_err(CE_WARN, "loadable syscall: %p: bad rval flags %x",
(void *)modl, modl->sys_sysent->sy_flags);
return (ENOSYS);
}
#endif
if ((sysp = mod_getsysent(modlp, table)) == NULL)
return (ENOSPC);
rw_enter(sysp->sy_lock, RW_WRITER);
mp = modl->sys_sysent;
sysp->sy_narg = mp->sy_narg;
sysp->sy_call = mp->sy_call;
sysp->sy_flags &= ~SE_ARGC;
sysp->sy_flags |= SE_LOADED |
(mp->sy_flags & (SE_ARGC | SE_NOUNLOAD | SE_RVAL_MASK));
if (mp->sy_flags & SE_NOUNLOAD) {
if (mp->sy_flags & SE_ARGC) {
sysp->sy_callc = (int64_t (*)())(uintptr_t)mp->sy_call;
} else {
sysp->sy_callc = syscall_ap;
}
sysp->sy_flags &= ~SE_LOADABLE;
}
rw_exit(sysp->sy_lock);
return (0);
}
static int
mod_removesys_sysent(
struct modlsys *modl,
struct modlinkage *modlp,
struct sysent table[])
{
struct sysent *sysp;
if ((sysp = mod_getsysent(modlp, table)) == NULL ||
(sysp->sy_flags & (SE_LOADABLE | SE_NOUNLOAD)) == 0 ||
sysp->sy_call != modl->sys_sysent->sy_call) {
struct modctl *mcp = mod_getctl(modlp);
char *modname = mcp->mod_modname;
cmn_err(CE_WARN, uninstall_err, modname);
return (EINVAL);
}
if (!(moddebug & MODDEBUG_NOAUL_SYS) &&
rw_tryenter(sysp->sy_lock, RW_WRITER)) {
if ((sysp->sy_flags & (SE_LOADED | SE_LOADABLE)) ==
(SE_LOADED | SE_LOADABLE)) {
sysp->sy_flags &= ~SE_LOADED;
sysp->sy_callc = loadable_syscall;
sysp->sy_call = nosys32;
rw_exit(sysp->sy_lock);
return (0);
}
rw_exit(sysp->sy_lock);
}
return (EBUSY);
}
static int
mod_infosys(struct modlsys *modl, struct modlinkage *modlp, int *p0)
{
*p0 = mod_infosysnum(modlp, sysent);
return (0);
}
static int
mod_installsys(struct modlsys *modl, struct modlinkage *modlp)
{
return (mod_installsys_sysent(modl, modlp, sysent));
}
static int
mod_removesys(struct modlsys *modl, struct modlinkage *modlp)
{
return (mod_removesys_sysent(modl, modlp, sysent));
}
#ifdef _SYSCALL32_IMPL
static int
mod_infosys32(struct modlsys *modl, struct modlinkage *modlp, int *p0)
{
*p0 = mod_infosysnum(modlp, sysent32);
return (0);
}
static int
mod_installsys32(struct modlsys *modl, struct modlinkage *modlp)
{
return (mod_installsys_sysent(modl, modlp, sysent32));
}
static int
mod_removesys32(struct modlsys *modl, struct modlinkage *modlp)
{
return (mod_removesys_sysent(modl, modlp, sysent32));
}
#endif
static int
mod_infofs(struct modlfs *modl, struct modlinkage *modlp, int *p0)
{
struct vfssw *vswp;
RLOCK_VFSSW();
if ((vswp = vfs_getvfsswbyname(modl->fs_vfsdef->name)) == NULL)
*p0 = -1;
else {
*p0 = vswp - vfssw;
vfs_unrefvfssw(vswp);
}
RUNLOCK_VFSSW();
return (0);
}
static int
mod_installfs(struct modlfs *modl, struct modlinkage *modlp)
{
struct vfssw *vswp;
struct modctl *mcp;
char *fsname;
char ksname[KSTAT_STRLEN + 1];
int fstype;
int allocated;
int err;
int vsw_stats_enabled;
extern int vopstats_enabled;
extern vopstats_t **vopstats_fstype;
extern kstat_t *new_vskstat(char *, vopstats_t *);
extern void initialize_vopstats(vopstats_t *);
if (modl->fs_vfsdef->def_version == VFSDEF_VERSION) {
fsname = modl->fs_vfsdef->name;
} else {
if ((modl->fs_vfsdef->def_version > 0) &&
(modl->fs_vfsdef->def_version < VFSDEF_VERSION)) {
fsname = modl->fs_vfsdef->name;
} else if ((mcp = mod_getctl(modlp)) != NULL) {
fsname = mcp->mod_modname;
} else {
fsname = "<unknown file system type>";
}
cmn_err(CE_WARN, "file system '%s' version mismatch", fsname);
return (ENXIO);
}
allocated = 0;
WLOCK_VFSSW();
if ((vswp = vfs_getvfsswbyname(fsname)) == NULL) {
if ((vswp = allocate_vfssw(fsname)) == NULL) {
WUNLOCK_VFSSW();
cmn_err(CE_WARN, "no room for '%s' in vfssw!", fsname);
return (ENXIO);
}
allocated = 1;
}
ASSERT(vswp != NULL);
fstype = vswp - vfssw;
vswp->vsw_flag = modl->fs_vfsdef->flags & ~(VSW_STATS);
if (modl->fs_vfsdef->flags & VSW_HASPROTO) {
vfs_mergeopttbl(&vfs_mntopts, modl->fs_vfsdef->optproto,
&vswp->vsw_optproto);
} else {
vfs_copyopttbl(&vfs_mntopts, &vswp->vsw_optproto);
}
if (modl->fs_vfsdef->flags & VSW_CANRWRO) {
vswp->vsw_flag |= VSW_CANREMOUNT;
}
if (vopstats_enabled && modl->fs_vfsdef->flags & VSW_STATS) {
vswp->vsw_flag |= VSW_STATS;
}
if (modl->fs_vfsdef->init == NULL)
err = EFAULT;
else
err = (*(modl->fs_vfsdef->init))(fstype, fsname);
if (err != 0) {
if (allocated) {
kmem_free(vswp->vsw_name, strlen(vswp->vsw_name)+1);
vswp->vsw_name = "";
}
vswp->vsw_flag = 0;
vswp->vsw_init = NULL;
}
vsw_stats_enabled = vswp->vsw_flag & VSW_STATS;
vfs_unrefvfssw(vswp);
WUNLOCK_VFSSW();
if (vsw_stats_enabled && vopstats_enabled &&
vopstats_fstype && vopstats_fstype[fstype] == NULL) {
(void) strlcpy(ksname, VOPSTATS_STR, sizeof (ksname));
(void) strlcat(ksname, vfssw[fstype].vsw_name, sizeof (ksname));
vopstats_fstype[fstype] =
kmem_alloc(sizeof (vopstats_t), KM_SLEEP);
initialize_vopstats(vopstats_fstype[fstype]);
(void) new_vskstat(ksname, vopstats_fstype[fstype]);
}
return (err);
}
static int
mod_removefs(struct modlfs *modl, struct modlinkage *modlp)
{
struct vfssw *vswp;
struct modctl *mcp;
char *modname;
if (moddebug & MODDEBUG_NOAUL_FS)
return (EBUSY);
WLOCK_VFSSW();
if ((vswp = vfs_getvfsswbyname(modl->fs_vfsdef->name)) == NULL) {
mcp = mod_getctl(modlp);
ASSERT(mcp != NULL);
modname = mcp->mod_modname;
WUNLOCK_VFSSW();
cmn_err(CE_WARN, uninstall_err, modname);
return (EINVAL);
}
if (vswp->vsw_count != 1) {
vfs_unrefvfssw(vswp);
WUNLOCK_VFSSW();
return (EBUSY);
}
if (vfs_opsinuse(&vswp->vsw_vfsops)) {
vfs_unrefvfssw(vswp);
WUNLOCK_VFSSW();
return (EBUSY);
}
vfs_freeopttbl(&vswp->vsw_optproto);
vswp->vsw_optproto.mo_count = 0;
vswp->vsw_flag = 0;
vswp->vsw_init = NULL;
vfs_unrefvfssw(vswp);
WUNLOCK_VFSSW();
return (0);
}
static int
mod_infostrmod(struct modlstrmod *modl, struct modlinkage *modlp, int *p0)
{
*p0 = -1;
return (0);
}
static int
mod_installstrmod(struct modlstrmod *modl, struct modlinkage *modlp)
{
struct fmodsw *fp = modl->strmod_fmodsw;
if (!(fp->f_flag & D_MP)) {
cmn_err(CE_WARN, "mod_install: MT-unsafe strmod '%s' rejected",
fp->f_name);
return (ENXIO);
}
return (fmodsw_register(fp->f_name, fp->f_str, fp->f_flag));
}
static int
mod_removestrmod(struct modlstrmod *modl, struct modlinkage *modlp)
{
if (moddebug & MODDEBUG_NOAUL_STR)
return (EBUSY);
return (fmodsw_unregister(modl->strmod_fmodsw->f_name));
}
static int
mod_infosockmod(struct modlsockmod *modl, struct modlinkage *modlp, int *p0)
{
*p0 = -1;
return (0);
}
static int
mod_installsockmod(struct modlsockmod *modl, struct modlinkage *modlp)
{
struct modctl *mcp;
char *mod_name;
mcp = mod_getctl(modlp);
ASSERT(mcp != NULL);
mod_name = mcp->mod_modname;
if (strcmp(mod_name, modl->sockmod_reg_info->smod_name) != 0) {
#ifdef DEBUG
cmn_err(CE_CONT, "mod_installsockmod: different names"
" %s != %s \n", mod_name,
modl->sockmod_reg_info->smod_name);
#endif
return (EINVAL);
}
return (smod_register(modl->sockmod_reg_info));
}
static int
mod_removesockmod(struct modlsockmod *modl, struct modlinkage *modlp)
{
return (smod_unregister(modl->sockmod_reg_info->smod_name));
}
static int
mod_infosched(struct modlsched *modl, struct modlinkage *modlp, int *p0)
{
int status;
auto id_t cid;
status = getcidbyname(modl->sched_class->cl_name, &cid);
if (status != 0)
*p0 = -1;
else
*p0 = cid;
return (0);
}
static int
mod_installsched(struct modlsched *modl, struct modlinkage *modlp)
{
sclass_t *clp;
int status;
id_t cid;
mutex_enter(&class_lock);
status = alloc_cid(modl->sched_class->cl_name, &cid);
mutex_exit(&class_lock);
ASSERT(status == 0);
clp = &sclass[cid];
rw_enter(clp->cl_lock, RW_WRITER);
if (SCHED_INSTALLED(clp)) {
printf("scheduling class %s is already installed\n",
modl->sched_class->cl_name);
rw_exit(clp->cl_lock);
return (EBUSY);
}
clp->cl_init = modl->sched_class->cl_init;
clp->cl_funcs = modl->sched_class->cl_funcs;
modl->sched_class = clp;
disp_add(clp);
loaded_classes++;
rw_exit(clp->cl_lock);
return (0);
}
static int
mod_removesched(struct modlsched *modl, struct modlinkage *modlp)
{
int status;
sclass_t *clp;
struct modctl *mcp;
char *modname;
id_t cid;
status = getcidbyname(modl->sched_class->cl_name, &cid);
if (status != 0) {
mcp = mod_getctl(modlp);
ASSERT(mcp != NULL);
modname = mcp->mod_modname;
cmn_err(CE_WARN, uninstall_err, modname);
return (EINVAL);
}
clp = &sclass[cid];
if (moddebug & MODDEBUG_NOAUL_SCHED ||
!rw_tryenter(clp->cl_lock, RW_WRITER))
return (EBUSY);
clp->cl_init = NULL;
clp->cl_funcs = NULL;
rw_exit(clp->cl_lock);
return (0);
}
static int
mod_infoexec(struct modlexec *modl, struct modlinkage *modlp, int *p0)
{
struct execsw *eswp;
if ((eswp = findexecsw(modl->exec_execsw->exec_magic)) == NULL)
*p0 = -1;
else
*p0 = eswp - execsw;
return (0);
}
static int
mod_installexec(struct modlexec *modl, struct modlinkage *modlp)
{
struct execsw *eswp;
struct modctl *mcp;
char *modname;
char *magic;
size_t magic_size;
if ((eswp = findexecsw(modl->exec_execsw->exec_magic)) == NULL) {
mcp = mod_getctl(modlp);
ASSERT(mcp != NULL);
modname = mcp->mod_modname;
magic = modl->exec_execsw->exec_magic;
magic_size = modl->exec_execsw->exec_maglen;
if ((eswp = allocate_execsw(modname, magic, magic_size)) ==
NULL) {
printf("no unused entries in 'execsw'\n");
return (ENOSPC);
}
}
if (eswp->exec_func != NULL) {
printf("exec type %x is already installed\n",
*eswp->exec_magic);
return (EBUSY);
}
rw_enter(eswp->exec_lock, RW_WRITER);
eswp->exec_func = modl->exec_execsw->exec_func;
eswp->exec_core = modl->exec_execsw->exec_core;
rw_exit(eswp->exec_lock);
return (0);
}
static int
mod_removeexec(struct modlexec *modl, struct modlinkage *modlp)
{
struct execsw *eswp;
struct modctl *mcp;
char *modname;
eswp = findexecsw(modl->exec_execsw->exec_magic);
if (eswp == NULL) {
mcp = mod_getctl(modlp);
ASSERT(mcp != NULL);
modname = mcp->mod_modname;
cmn_err(CE_WARN, uninstall_err, modname);
return (EINVAL);
}
if (moddebug & MODDEBUG_NOAUL_EXEC ||
!rw_tryenter(eswp->exec_lock, RW_WRITER))
return (EBUSY);
eswp->exec_func = NULL;
eswp->exec_core = NULL;
rw_exit(eswp->exec_lock);
return (0);
}
static struct sysent *
mod_getsysent(struct modlinkage *modlp, struct sysent *se)
{
int sysnum;
struct modctl *mcp;
char *mod_name;
if ((mcp = mod_getctl(modlp)) == NULL) {
return (NULL);
}
mod_name = mcp->mod_modname;
if ((sysnum = mod_getsysnum(mod_name)) == -1) {
cmn_err(CE_WARN, "system call missing from bind file");
return (NULL);
}
if (sysnum > 0 && sysnum < NSYSCALL &&
(se[sysnum].sy_flags & (SE_LOADABLE | SE_NOUNLOAD)))
return (se + sysnum);
cmn_err(CE_WARN, "system call entry %d is already in use", sysnum);
return (NULL);
}
static int
mod_infoipp(struct modlipp *modl, struct modlinkage *modlp, int *p0)
{
struct modctl *mcp = mod_getctl(modlp);
ipp_mod_id_t mid;
if (mcp == NULL) {
*p0 = -1;
return (0);
}
mid = ipp_mod_lookup(mcp->mod_modname);
*p0 = mid;
return (0);
}
static int
mod_installipp(struct modlipp *modl, struct modlinkage *modlp)
{
struct modctl *mcp = mod_getctl(modlp);
ASSERT(mcp != NULL);
return (ipp_mod_register(mcp->mod_modname, modl->ipp_ops));
}
static int
mod_removeipp(struct modlipp *modl, struct modlinkage *modlp)
{
struct modctl *mcp = mod_getctl(modlp);
extern kthread_id_t mod_aul_thread;
ipp_mod_id_t mid;
ASSERT(mcp != NULL);
if ((moddebug & MODDEBUG_NOAUL_IPP) && (mod_aul_thread == curthread))
return (EBUSY);
mid = ipp_mod_lookup(mcp->mod_modname);
ASSERT(mid != IPP_MOD_INVAL);
return (ipp_mod_unregister(mid));
}
static int
mod_installkiconv(struct modlkiconv *modl, struct modlinkage *modlp)
{
return (kiconv_register_module(modl->kiconv_moddef));
}
static int
mod_removekiconv(struct modlkiconv *modl, struct modlinkage *modlp)
{
return (kiconv_unregister_module(modl->kiconv_moddef));
}