Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

.\"	$NetBSD: kfilter_register.9,v 1.11 2020/10/31 16:03:01 christos Exp $
.\"
.\" Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This documentation is derived from text contributed by
.\" Luke Mewburn.
.\"
.\" 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.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
.\"
.Dd October 31, 2020
.Dt KFILTER_REGISTER 9
.Os
.Sh NAME
.Nm kfilter_register ,
.Nm kfilter_unregister
.Nd add or remove kernel event filters
.Sh SYNOPSIS
.In sys/event.h
.Ft int
.Fn kfilter_register "const char *name" "struct filterops *filtops" "int *retfilter"
.Ft int
.Fn kfilter_unregister "const char *name"
.Sh DESCRIPTION
The
.Fn kfilter_register
function adds a new kernel event filter (kfilter) to the system,
for use by callers of
.Xr kqueue 2
and
.Xr kevent 2 .
.Fa name
is the name of the new filter (which must not already exist), and
.Fa filtops
is a pointer to a
.Va filterops
structure which describes the filter operations.
Both
.Fa name
and
.Fa filtops
will be copied to an internal data structure, and a new filter number
will be allocated.
If
.Fa retfilter
is not
.Dv NULL ,
then the new filter number will be returned in the address pointed at by
.Fa retfilter .
.Pp
The
.Fn kfilter_unregister
function removes a kfilter named
.Fa name
that was previously registered with
.Fn kfilter_register .
If a filter with the same
.Fa name
is later reregistered with
.Fn kfilter_register ,
it will get a different filter number
(i.e., filter numbers are not recycled).
It is not possible to unregister the system filters
(i.e., those that start with
.Dq EVFILT_
and are documented in
.Xr kqueue 2 ) .
.Pp
The
.Va filterops
structure is defined as follows:
.Bd -literal -offset indent
struct filterops {
	int	f_isfd;		/* true if ident == filedescriptor */
	int	(*f_attach)(struct knote *kn);
				/* called when knote is ADDed */
	void	(*f_detach)(struct knote *kn);
				/* called when knote is DELETEd */
	int	(*f_event)(struct knote *kn, long hint);
				/* called when event is triggered */
	void	(*f_touch)(struct knote *kn, struct kevent *kev, long hint);
				/* called during registration and event 
				 * processing to provide custom handling 
				 * of event fflags and data
				 */
};
.Ed
.Pp
If the filter operation is for a file descriptor,
.Va f_isfd
should be non-zero, otherwise it should be zero.
This controls where the
.Xr kqueue 2
system stores the knotes for an object.
.Sh RETURN VALUES
.Fn kfilter_register
returns 0 on success,
.Er EINVAL
if there's an invalid argument, or
.Er EEXIST
if the filter already exists,
.Pp
.Fn kfilter_unregister
returns 0 on success,
.Er EINVAL
if there's an invalid argument, or
.Er ENOENT
if the filter doesn't exist.
.Sh SEE ALSO
.Xr kqueue 2 ,
.Xr free 9 ,
.Xr knote 9 ,
.Xr malloc 9
.Sh HISTORY
The
.Fn kfilter_register
and
.Fn kfilter_unregister
functions first appeared in
.Nx 2.0 .
.Sh AUTHORS
The
.Fn kfilter_register
and
.Fn kfilter_unregister
functions were implemented by
.An Luke Mewburn
.Aq lukem@NetBSD.org .