hook.c revision 381a2a9a387f449fab7d0c7e97c4184c26963abf
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/hook_impl.h>
/*
* This file provides kernel hook framework.
*/
&mod_miscops, /* drv_modops */
"Hooks Interface v1.0", /* drv_linkinfo */
};
static struct modlinkage modlinkage = {
MODREV_1, /* ml_rev */
&modlmisc, /* ml_linkage */
};
/*
* Hook internal functions
*/
static void hook_init(void);
/*
* Module entry points.
*/
int
_init(void)
{
hook_init();
return (mod_install(&modlinkage));
}
int
_fini(void)
{
return (mod_remove(&modlinkage));
}
int
{
}
/*
* Function: hook_init
* Returns: None
* Parameters: None
*
* Initialize hooks
*/
static void
hook_init(void)
{
}
/*
* Function: hook_run
* Returns: int - return value according to callback func
* Parameters: token(I) - event pointer
* info(I) - message
*
* Run hooks for specific provider. The hooks registered are stepped through
* until either the end of the list is reached or a hook function returns a
* non-zero value. If a non-zero value is returned from a hook function, we
* return that value back to our caller. By design, a hook function can be
* called more than once, simultaneously.
*/
int
{
hook_int_t *hi;
int rval = 0;
hook_data_t, info);
/* Hold global read lock to ensure event will not be deleted */
/* Hold event read lock to ensure hook will not be changed */
hook_int_t *, hi);
hook_int_t *, hi,
int, rval);
if (rval != 0)
break;
}
hook_int_t *, hi);
return (rval);
}
/*
* Function: hook_family_add
* Returns: internal family pointer - NULL = Fail
* Parameters: hf(I) - family pointer
*
* Add new family to family list
*/
{
return (NULL);
/* search family list */
return (NULL);
}
/* Add to family list head */
return (new);
}
/*
* Function: hook_family_remove
* Returns: int - 0 = Succ, Else = Fail
* Parameters: hfi(I) - internal family pointer
*
* Remove family from family list
*/
int
{
/* Check if there are events */
return (EBUSY);
}
/* Remove from family list */
return (0);
}
/*
* Function: hook_family_copy
* Returns: internal family pointer - NULL = Failed
* Parameters: src(I) - family pointer
*
* Allocate internal family block and duplicate incoming family
* No locks should be held across this function as it may sleep.
*/
static hook_family_int_t *
{
/* Copy body */
/* Copy name */
return (new);
}
/*
* Function: hook_family_find
* Returns: internal family pointer - NULL = Not match
* Parameters: family(I) - family name string
*
* Search family list with family name
* A lock on familylock must be held when called.
*/
static hook_family_int_t *
hook_family_find(char *family)
{
break;
}
return (hfi);
}
/*
* Function: hook_family_free
* Returns: None
* Parameters: hfi(I) - internal family pointer
*
* Free alloc memory for family
*/
static void
{
/* Free name space */
}
/* Free container */
}
/*
* Function: hook_event_add
* Returns: internal event pointer - NULL = Fail
* Parameters: hfi(I) - internal family pointer
* he(I) - event pointer
*
* Add new event to event list on specific family.
* This function can fail to return successfully if (1) it cannot allocate
* enough memory for its own internal data structures, (2) the event has
* already been registered (for any hook family.)
*/
{
return (NULL);
/* Check whether this event pointer is already registered */
return (NULL);
}
/* Add to event list head */
return (new);
}
/*
* Function: hook_event_remove
* Returns: int - 0 = Succ, Else = Fail
* Parameters: hfi(I) - internal family pointer
* he(I) - event pointer
*
* Remove event from event list on specific family
*/
int
{
return (ENXIO);
}
/* Check if there are registered hooks for this event */
return (EBUSY);
}
/* Remove from event list */
return (0);
}
/*
* Function: hook_event_checkdup
* Returns: internal event pointer - NULL = Not match
* Parameters: he(I) - event pointer
*
* Search whole list with event pointer
* A lock on familylock must be held when called.
*/
static hook_event_int_t *
{
return (hei);
}
}
return (NULL);
}
/*
* Function: hook_event_copy
* Returns: internal event pointer - NULL = Failed
* Parameters: src(I) - event pointer
*
* Allocate internal event block and duplicate incoming event
* No locks should be held across this function as it may sleep.
*/
static hook_event_int_t *
{
/* Copy body */
return (new);
}
/*
* Function: hook_event_find
* Returns: internal event pointer - NULL = Not match
* Parameters: hfi(I) - internal family pointer
* event(I) - event name string
*
* Search event list with event name
* A lock on familylock must be held when called.
*/
static hook_event_int_t *
{
break;
}
return (hei);
}
/*
* Function: hook_event_free
* Returns: None
* Parameters: hei(I) - internal event pointer
*
* Free alloc memory for event
*/
static void
{
/* Free container */
}
/*
* Function: hook_register
* Returns: int- 0 = Succ, Else = Fail
* Parameters: hfi(I) - internal family pointer
* event(I) - event name string
* h(I) - hook pointer
*
* Add new hook to hook list on spefic family, event
*/
int
{
/* Alloc hook_int_t and copy hook */
return (ENOMEM);
/*
* to hold global family write lock. Just get read lock here to
* ensure event will not be removed when doing hooks operation
*/
return (ENXIO);
}
/* Multiple hooks are only allowed for read-only events. */
return (EEXIST);
}
return (EEXIST);
}
/* Add to hook list head */
return (0);
}
/*
* Function: hook_unregister
* Returns: int - 0 = Succ, Else = Fail
* Parameters: hfi(I) - internal family pointer
* event(I) - event name string
* h(I) - hook pointer
*
* Remove hook from hook list on specific family, event
*/
int
{
hook_int_t *hi;
return (ENXIO);
}
/* Hold write lock for event */
return (ENXIO);
}
/* Remove from hook list */
}
return (0);
}
/*
* Function: hook_find
* Returns: internal hook pointer - NULL = Not match
* Parameters: hei(I) - internal event pointer
* h(I) - hook pointer
*
* Search hook list
* A lock on familylock must be held when called.
*/
static hook_int_t *
{
hook_int_t *hi;
break;
}
return (hi);
}
/*
* Function: hook_copy
* Returns: internal hook pointer - NULL = Failed
* Parameters: src(I) - hook pointer
*
* Allocate internal hook block and duplicate incoming hook.
* No locks should be held across this function as it may sleep.
*/
static hook_int_t *
{
/* Copy body */
/* Copy name */
return (new);
}
/*
* Function: hook_free
* Returns: None
* Parameters: hi(I) - internal hook pointer
*
* Free alloc memory for hook
*/
static void
{
/* Free name space */
}
/* Free container */
}