diff --git a/lib/libsys/kldfind.2 b/lib/libsys/kldfind.2 index a7e147af55f1..5ede0d1e1464 100644 --- a/lib/libsys/kldfind.2 +++ b/lib/libsys/kldfind.2 @@ -1,84 +1,83 @@ .\" .\" Copyright (c) 1999 Chris Costello .\" All rights reserved. .\" .\" 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 AUTHOR 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 AUTHOR 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 March 3, 1999 .Dt KLDFIND 2 .Os .Sh NAME .Nm kldfind .Nd returns the fileid of a kld file .Sh LIBRARY .Lb libc .Sh SYNOPSIS -.In sys/param.h .In sys/linker.h .Ft int .Fn kldfind "const char *file" .Sh DESCRIPTION The .Fn kldfind system call returns the fileid of the kld file referenced by .Fa file . .Sh RETURN VALUES The .Fn kldfind system call returns the fileid of the kld file referenced by .Fa file . Upon error, .Fn kldfind returns -1 and sets .Va errno to indicate the error. .Sh ERRORS .Va errno is set to the following if .Fn kldfind fails: .Bl -tag -width Er .It Bq Er EFAULT The data required for this operation could not be read from the kernel space. .It Bq Er ENOENT The file specified is not loaded in the kernel. .El .Sh SEE ALSO .Xr kldfirstmod 2 , .Xr kldload 2 , .Xr kldnext 2 , .Xr kldstat 2 , .Xr kldsym 2 , .Xr kldunload 2 , .Xr modfind 2 , .Xr modfnext 2 , .Xr modnext 2 , .Xr modstat 2 , .Xr kld 4 , .Xr kldstat 8 .Sh HISTORY The .Nm kld interface first appeared in .Fx 3.0 . diff --git a/lib/libsys/kldfirstmod.2 b/lib/libsys/kldfirstmod.2 index 8e69b366c8aa..b6dbab2c94b7 100644 --- a/lib/libsys/kldfirstmod.2 +++ b/lib/libsys/kldfirstmod.2 @@ -1,74 +1,73 @@ .\" .\" Copyright (c) 1999 Chris Costello .\" All rights reserved. .\" .\" 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 AUTHOR 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 AUTHOR 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 March 3, 1999 .Dt KLDFIRSTMOD 2 .Os .Sh NAME .Nm kldfirstmod .Nd "return first module id from the kld file specified" .Sh LIBRARY .Lb libc .Sh SYNOPSIS -.In sys/param.h .In sys/linker.h .Ft int .Fn kldfirstmod "int fileid" .Sh DESCRIPTION The .Fn kldfirstmod system call returns the module id pertaining to the first module referenced by .Fa fileid . .Sh RETURN VALUES The .Fn kldfirstmod will return the id of the first module referenced by .Fa fileid or 0 if there are no references. .Sh ERRORS .Bl -tag -width Er .It Bq Er ENOENT The kld file referenced by .Fa fileid was not found. .El .Sh SEE ALSO .Xr kldfind 2 , .Xr kldload 2 , .Xr kldnext 2 , .Xr kldstat 2 , .Xr kldsym 2 , .Xr kldunload 2 , .Xr modfind 2 , .Xr modfnext 2 , .Xr modnext 2 , .Xr modstat 2 , .Xr kld 4 , .Xr kldstat 8 .Sh HISTORY The .Nm kld interface first appeared in .Fx 3.0 . diff --git a/lib/libsys/kldload.2 b/lib/libsys/kldload.2 index 20bf3778c1ae..63a13c328d58 100644 --- a/lib/libsys/kldload.2 +++ b/lib/libsys/kldload.2 @@ -1,94 +1,93 @@ .\" .\" Copyright (c) 1999 Chris Costello .\" All rights reserved. .\" .\" 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 AUTHOR 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 AUTHOR 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 March 3, 1999 .Dt KLDLOAD 2 .Os .Sh NAME .Nm kldload .Nd load KLD files into the kernel .Sh LIBRARY .Lb libc .Sh SYNOPSIS -.In sys/param.h .In sys/linker.h .Ft int .Fn kldload "const char *file" .Sh DESCRIPTION The .Fn kldload system call loads a kld file into the kernel using the kernel linker. .Sh RETURN VALUES The .Fn kldload system call returns the fileid of the kld file which was loaded into the kernel. If an error occurs, .Fn kldload will return -1 and set .Va errno to indicate the error. .Sh ERRORS The named file is loaded unless: .Bl -tag -width Er .It Bq Er EPERM You do not have access to read the file or link it with the kernel. You should be the root user to be able to use the .Nm kld system calls. .It Bq Er EFAULT Bad address encountered when adding kld info into the kernel space. .It Bq Er ENOMEM There is no memory to load the file into the kernel. .It Bq Er ENOENT The file was not found. .It Bq Er ENOEXEC The file format of .Fa file was unrecognized. .It Bq Er EEXIST The supplied .Fa file has already been loaded. .El .Sh SEE ALSO .Xr kldfind 2 , .Xr kldfirstmod 2 , .Xr kldnext 2 , .Xr kldstat 2 , .Xr kldsym 2 , .Xr kldunload 2 , .Xr modfind 2 , .Xr modfnext 2 , .Xr modnext 2 , .Xr modstat 2 , .Xr kld 4 , .Xr kldload 8 .Sh HISTORY The .Nm kld interface first appeared in .Fx 3.0 . diff --git a/lib/libsys/kldnext.2 b/lib/libsys/kldnext.2 index 8d8102711494..28b14dfc3035 100644 --- a/lib/libsys/kldnext.2 +++ b/lib/libsys/kldnext.2 @@ -1,87 +1,86 @@ .\" .\" Copyright (c) 1999 Chris Costello .\" All rights reserved. .\" .\" 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 AUTHOR 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 AUTHOR 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 February 22, 2006 .Dt KLDNEXT 2 .Os .Sh NAME .Nm kldnext .Nd return the fileid of the next kld file .Sh LIBRARY .Lb libc .Sh SYNOPSIS -.In sys/param.h .In sys/linker.h .Ft int .Fn kldnext "int fileid" .Sh DESCRIPTION The .Fn kldnext system call returns the fileid of the next kld file (that is, the one after .Fa fileid ) or 0 if .Fa fileid is the last file loaded. To get the fileid of the first kld file, pass .Fa fileid of 0 to .Fn kldnext . .Sh RETURN VALUES The .Fn kldnext system call returns the fileid of the next kld file or 0 if successful. Otherwise .Fn kldnext returns the value \-1 and sets the global variable .Va errno to indicate the error. .Sh ERRORS The only error set by .Fn kldnext is .Er ENOENT , which is set when .Fa fileid refers to a kld file that does not exist (is not loaded). .Sh SEE ALSO .Xr kldfind 2 , .Xr kldfirstmod 2 , .Xr kldload 2 , .Xr kldstat 2 , .Xr kldsym 2 , .Xr kldunload 2 , .Xr modfind 2 , .Xr modfnext 2 , .Xr modnext 2 , .Xr modstat 2 , .Xr kld 4 , .Xr kldstat 8 .Sh HISTORY The .Nm kld interface first appeared in .Fx 3.0 . diff --git a/lib/libsys/kldstat.2 b/lib/libsys/kldstat.2 index f0ab26ac2608..111323a0da8d 100644 --- a/lib/libsys/kldstat.2 +++ b/lib/libsys/kldstat.2 @@ -1,131 +1,130 @@ .\" .\" Copyright (c) 1999 Chris Costello .\" All rights reserved. .\" .\" 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 AUTHOR 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 AUTHOR 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 March 28, 2012 .Dt KLDSTAT 2 .Os .Sh NAME .Nm kldstat .Nd get status of kld file .Sh LIBRARY .Lb libc .Sh SYNOPSIS -.In sys/param.h .In sys/linker.h .Ft int .Fn kldstat "int fileid" "struct kld_file_stat *stat" .Sh DESCRIPTION The .Fn kldstat system call writes the info for the file referred to by .Fa fileid into .Fa stat . .Bd -literal struct kld_file_stat { int version; /* set to sizeof(struct kld_file_stat) */ char name[MAXPATHLEN]; int refs; int id; caddr_t address; size_t size; char pathname[MAXPATHLEN]; }; .Ed .Bl -tag -width XXXaddress .It version This field is set to the size of the structure mentioned above by the code calling .Fn kldstat , and not .Fn kldstat itself. .It name The name of the file referred to by .Fa fileid . .It refs The number of modules referenced by .Fa fileid . .It id The id of the file specified in .Fa fileid . .It address The load address of the kld file. .It size The amount of memory in bytes allocated by the file. .It pathname The full name of the file referred to by .Fa fileid , including the path. .El .Sh RETURN VALUES .Rv -std kldstat .Sh ERRORS The information for the file referred to by .Fa fileid is filled into the structure pointed to by .Fa stat unless: .Bl -tag -width Er .It Bq Er ENOENT The file was not found (probably not loaded). .It Bq Er EINVAL The version specified in the .Fa version field of stat is not the proper version. You would need to rebuild world, the kernel, or your application, if this error occurs, given that you did properly fill in the .Fa version field. .It Bq Er EFAULT There was a problem copying one, some, or all of the fields into .Fa stat in the .Xr copyout 9 function. .El .Sh SEE ALSO .Xr kldfind 2 , .Xr kldfirstmod 2 , .Xr kldload 2 , .Xr kldnext 2 , .Xr kldsym 2 , .Xr kldunload 2 , .Xr modfind 2 , .Xr modfnext 2 , .Xr modnext 2 , .Xr modstat 2 , .Xr kld 4 , .Xr kldstat 8 .Sh HISTORY The .Nm kld interface first appeared in .Fx 3.0 . .Sh BUGS The pathname may not be accurate if the file system mounts have changed since the module was loaded, or if this function is called within a chrooted environment. diff --git a/lib/libsys/kldsym.2 b/lib/libsys/kldsym.2 index d3025ca536f8..641fc26c38ec 100644 --- a/lib/libsys/kldsym.2 +++ b/lib/libsys/kldsym.2 @@ -1,119 +1,118 @@ .\" Copyright (c) 2001 Chris Costello .\" All rights reserved. .\" .\" 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 AUTHOR 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 AUTHOR 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 17, 2016 .Dt KLDSYM 2 .Os .Sh NAME .Nm kldsym .Nd look up address by symbol name in a KLD .Sh LIBRARY .Lb libc .Sh SYNOPSIS -.In sys/param.h .In sys/linker.h .Ft int .Fn kldsym "int fileid" "int cmd" "void *data" .Sh DESCRIPTION The .Fn kldsym system call returns the address of the symbol specified in .Fa data in the module specified by .Fa fileid . If .Fa fileid is 0, all loaded modules are searched. Currently, the only .Fa cmd implemented is .Dv KLDSYM_LOOKUP . .Pp The .Fa data argument is of the following structure: .Bd -literal -offset indent struct kld_sym_lookup { int version; /* sizeof(struct kld_sym_lookup) */ char *symname; /* Symbol name we are looking up */ u_long symvalue; size_t symsize; }; .Ed .Pp The .Va version member is to be set by the code calling .Fn kldsym to .Fn sizeof "struct kld_sym_lookup" . The next two members, .Va version and .Va symname , are specified by the user. The last two, .Va symvalue and .Va symsize , are filled in by .Fn kldsym and contain the address associated with .Va symname and the size of the data it points to, respectively. .Sh RETURN VALUES .Rv -std kldsym .Sh ERRORS The .Fn kldsym system call will fail if: .Bl -tag -width Er .It Bq Er EINVAL Invalid value in .Fa data->version or .Fa cmd . .It Bq Er ENOENT The .Fa fileid argument is invalid, or the specified symbol could not be found. .El .Sh SEE ALSO .Xr kldfind 2 , .Xr kldfirstmod 2 , .Xr kldload 2 , .Xr kldnext 2 , .Xr kldunload 2 , .Xr modfind 2 , .Xr modnext 2 , .Xr modstat 2 , .Xr kld 4 .Sh HISTORY The .Fn kldsym system call first appeared in .Fx 3.0 . diff --git a/lib/libsys/kldunload.2 b/lib/libsys/kldunload.2 index 2d33aabb3f33..c89f869e9eeb 100644 --- a/lib/libsys/kldunload.2 +++ b/lib/libsys/kldunload.2 @@ -1,92 +1,91 @@ .\" .\" Copyright (c) 1999 Chris Costello .\" All rights reserved. .\" .\" 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 AUTHOR 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 AUTHOR 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 December 25, 2008 .Dt KLDUNLOAD 2 .Os .Sh NAME .Nm kldunload , kldunloadf .Nd unload kld files .Sh LIBRARY .Lb libc .Sh SYNOPSIS -.In sys/param.h .In sys/linker.h .Ft int .Fn kldunload "int fileid" .Ft int .Fn kldunloadf "int fileid" "int flags" .Sh DESCRIPTION The .Fn kldunload system call unloads a kld file from the kernel that was previously linked via .Xr kldload 2 . .Pp The .Fn kldunloadf system call accepts an additional flags argument, which may be one of .Dv LINKER_UNLOAD_NORMAL , giving the same behavior as .Fn kldunload , or .Dv LINKER_UNLOAD_FORCE , which causes the unload to ignore a failure to quiesce the module. .Sh RETURN VALUES .Rv -std .Sh ERRORS The file referred to by .Fa fileid is unloaded unless: .Bl -tag -width Er .It Bq Er EPERM You do not have access to unlink the file from the kernel. .It Bq Er ENOENT The file was not found. .It Bq Er EBUSY You attempted to unload a file linked by the kernel. .It Bq Er EINVAL The .Fn kldunloadf system call was passed invalid flags. .El .Sh SEE ALSO .Xr kldfind 2 , .Xr kldfirstmod 2 , .Xr kldload 2 , .Xr kldnext 2 , .Xr kldstat 2 , .Xr kldsym 2 , .Xr modfind 2 , .Xr modfnext 2 , .Xr modnext 2 , .Xr modstat 2 , .Xr kld 4 , .Xr kldunload 8 .Sh HISTORY The .Nm kld interface first appeared in .Fx 3.0 . diff --git a/sys/sys/linker.h b/sys/sys/linker.h index a316aa26d0eb..fbbc0ebc5de1 100644 --- a/sys/sys/linker.h +++ b/sys/sys/linker.h @@ -1,401 +1,403 @@ /*- * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 1997-2000 Doug Rabson * All rights reserved. * * 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 AUTHOR 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 AUTHOR 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. */ #ifndef _SYS_LINKER_H_ #define _SYS_LINKER_H_ +#include + #ifdef _KERNEL #include #include #ifdef MALLOC_DECLARE MALLOC_DECLARE(M_LINKER); #endif struct mod_depend; /* * Object representing a file which has been loaded by the linker. */ typedef struct linker_file* linker_file_t; typedef TAILQ_HEAD(, linker_file) linker_file_list_t; typedef caddr_t linker_sym_t; /* opaque symbol */ typedef c_caddr_t c_linker_sym_t; /* const opaque symbol */ typedef int (*linker_function_name_callback_t)(const char *, void *); /* * expanded out linker_sym_t */ typedef struct linker_symval { const char* name; caddr_t value; size_t size; } linker_symval_t; typedef int (*linker_function_nameval_callback_t)(linker_file_t, int, linker_symval_t *, void *); struct common_symbol { STAILQ_ENTRY(common_symbol) link; char* name; caddr_t address; }; struct linker_file { KOBJ_FIELDS; int refs; /* reference count */ int userrefs; /* kldload(2) count */ int flags; #define LINKER_FILE_LINKED 0x1 /* file has been fully linked */ #define LINKER_FILE_MODULES 0x2 /* file has >0 modules at preload */ TAILQ_ENTRY(linker_file) link; /* list of all loaded files */ char* filename; /* file which was loaded */ char* pathname; /* file name with full path */ int id; /* unique id */ caddr_t address; /* load address */ size_t size; /* size of file */ caddr_t ctors_addr; /* address of .ctors/.init_array */ size_t ctors_size; /* size of .ctors/.init_array */ enum { LF_NONE = 0, LF_CTORS, LF_DTORS, } ctors_invoked; /* have we run ctors yet? */ caddr_t dtors_addr; /* address of .dtors/.fini_array */ size_t dtors_size; /* size of .dtors/.fini_array */ int ndeps; /* number of dependencies */ linker_file_t* deps; /* list of dependencies */ STAILQ_HEAD(, common_symbol) common; /* list of common symbols */ TAILQ_HEAD(, module) modules; /* modules in this file */ TAILQ_ENTRY(linker_file) loaded; /* preload dependency support */ int loadcnt; /* load counter value */ /* * Function Boundary Tracing (FBT) or Statically Defined Tracing (SDT) * fields. */ int nenabled; /* number of enabled probes. */ int fbt_nentries; /* number of fbt entries created. */ #ifdef __arm__ caddr_t exidx_addr; /* Unwind data index table start */ size_t exidx_size; /* Unwind data index table size */ #endif }; /* * Object implementing a class of file (a.out, elf, etc.) */ typedef struct linker_class *linker_class_t; typedef TAILQ_HEAD(, linker_class) linker_class_list_t; struct linker_class { KOBJ_CLASS_FIELDS; TAILQ_ENTRY(linker_class) link; /* list of all file classes */ }; /* * Function type used when iterating over the list of linker files. */ typedef int linker_predicate_t(linker_file_t, void *); /* * The "file" for the kernel. */ extern linker_file_t linker_kernel_file; /* * Special symbol which will be replaced by a reference to the linker_file_t * of the module it is used in. */ extern linker_file_t __this_linker_file; /* * Obtain a reference to a module, loading it if required. */ int linker_reference_module(const char* _modname, struct mod_depend *_verinfo, linker_file_t* _result); /* * Release a reference to a module, unloading it if there are no more * references. Note that one should either provide a module name and * optional version info or a linker file, but not both. */ int linker_release_module(const char *_modname, struct mod_depend *_verinfo, linker_file_t _file); /* * Iterate over all of the currently loaded linker files calling the * predicate function while the function returns 0. Returns the value * returned by the last predicate function. */ int linker_file_foreach(linker_predicate_t *_predicate, void *_context); /* * Lookup a symbol in a file. If deps is TRUE, look in dependencies * if not found in file. */ caddr_t linker_file_lookup_symbol(linker_file_t _file, const char* _name, int _deps); /* * Lookup a linker set in a file. Return pointers to the first entry, * last + 1, and count of entries. Use: for (p = start; p < stop; p++) {} * void *start is really: "struct yoursetmember ***start;" */ int linker_file_lookup_set(linker_file_t _file, const char *_name, void *_start, void *_stop, int *_count); /* * List all functions in a file. */ int linker_file_function_listall(linker_file_t, linker_function_nameval_callback_t, void *); /* * Functions solely for use by the linker class handlers. */ int linker_add_class(linker_class_t _cls); int linker_file_unload(linker_file_t _file, int flags); int linker_load_dependencies(linker_file_t _lf); linker_file_t linker_make_file(const char* _filename, linker_class_t _cls); /* * DDB Helpers, tuned specifically for ddb/db_kld.c */ int linker_ddb_lookup(const char *_symstr, c_linker_sym_t *_sym); int linker_ddb_search_symbol(caddr_t _value, c_linker_sym_t *_sym, long *_diffp); int linker_ddb_symbol_values(c_linker_sym_t _sym, linker_symval_t *_symval); int linker_ddb_search_symbol_name(caddr_t value, char *buf, u_int buflen, long *offset); /* * stack(9) helper for situations where kernel locking is required. */ int linker_search_symbol_name_flags(caddr_t value, char *buf, u_int buflen, long *offset, int flags); int linker_search_symbol_name(caddr_t value, char *buf, u_int buflen, long *offset); /* HWPMC helper */ void *linker_hwpmc_list_objects(void); /* kldload/kldunload syscalls blocking */ #define LINKER_UB_UNLOCK 0x0001 /* busy: unlock kld_sx locked on return */ #define LINKER_UB_LOCKED 0x0002 /* busy/unbusy: kld_sx locked on entry */ #define LINKER_UB_PCATCH 0x0004 /* busy: sleep interruptible */ int linker_kldload_busy(int flags); void linker_kldload_unbusy(int flags); #endif /* _KERNEL */ /* * Module information subtypes */ #define MODINFO_END 0x0000 /* End of list */ #define MODINFO_NAME 0x0001 /* Name of module (string) */ #define MODINFO_TYPE 0x0002 /* Type of module (string) */ #define MODINFO_ADDR 0x0003 /* Loaded address */ #define MODINFO_SIZE 0x0004 /* Size of module */ #define MODINFO_EMPTY 0x0005 /* Has been deleted */ #define MODINFO_ARGS 0x0006 /* Parameters string */ #define MODINFO_METADATA 0x8000 /* Module-specfic */ #define MODINFOMD_AOUTEXEC 0x0001 /* a.out exec header */ #define MODINFOMD_ELFHDR 0x0002 /* ELF header */ #define MODINFOMD_SSYM 0x0003 /* start of symbols */ #define MODINFOMD_ESYM 0x0004 /* end of symbols */ #define MODINFOMD_DYNAMIC 0x0005 /* _DYNAMIC pointer */ #define MODINFOMD_MB2HDR 0x0006 /* MB2 header info */ /* These values are MD on PowerPC */ #if !defined(__powerpc__) #define MODINFOMD_ENVP 0x0006 /* envp[] */ #define MODINFOMD_HOWTO 0x0007 /* boothowto */ #define MODINFOMD_KERNEND 0x0008 /* kernend */ #endif #define MODINFOMD_SHDR 0x0009 /* section header table */ #define MODINFOMD_CTORS_ADDR 0x000a /* address of .ctors */ #define MODINFOMD_CTORS_SIZE 0x000b /* size of .ctors */ #define MODINFOMD_FW_HANDLE 0x000c /* Firmware dependent handle */ #define MODINFOMD_KEYBUF 0x000d /* Crypto key intake buffer */ #define MODINFOMD_FONT 0x000e /* Console font */ #define MODINFOMD_SPLASH 0x000f /* Console splash screen */ #define MODINFOMD_NOCOPY 0x8000 /* don't copy this metadata to the kernel */ #define MODINFOMD_DEPLIST (0x4001 | MODINFOMD_NOCOPY) /* depends on */ #ifdef _KERNEL #define MD_FETCH(mdp, info, type) ({ \ type *__p; \ __p = (type *)preload_search_info((mdp), MODINFO_METADATA | (info)); \ __p ? *__p : 0; \ }) #endif #define LINKER_HINTS_VERSION 1 /* linker.hints file version */ #define LINKER_HINTS_MAX (1 << 20) /* Allow at most 1MB for linker.hints */ #ifdef _KERNEL /* * Module lookup */ extern vm_offset_t preload_addr_relocate; extern caddr_t preload_metadata; extern void * preload_fetch_addr(caddr_t _mod); extern size_t preload_fetch_size(caddr_t _mod); extern caddr_t preload_search_by_name(const char *_name); extern caddr_t preload_search_by_type(const char *_type); extern caddr_t preload_search_next_name(caddr_t _base); extern caddr_t preload_search_info(caddr_t _mod, int _inf); extern void preload_delete_name(const char *_name); extern void preload_bootstrap_relocate(vm_offset_t _offset); extern void preload_dump(void); #ifdef KLD_DEBUG extern int kld_debug; #define KLD_DEBUG_FILE 1 /* file load/unload */ #define KLD_DEBUG_SYM 2 /* symbol lookup */ #define KLD_DPF(cat, args) \ do { \ if (kld_debug & KLD_DEBUG_##cat) printf args; \ } while (0) #else #define KLD_DPF(cat, args) #endif typedef int elf_lookup_fn(linker_file_t, Elf_Size, int, Elf_Addr *); /* Support functions */ bool elf_is_ifunc_reloc(Elf_Size r_info); int elf_reloc(linker_file_t _lf, Elf_Addr base, const void *_rel, int _type, elf_lookup_fn _lu); int elf_reloc_local(linker_file_t _lf, Elf_Addr base, const void *_rel, int _type, elf_lookup_fn _lu); Elf_Addr elf_relocaddr(linker_file_t _lf, Elf_Addr addr); const Elf_Sym *elf_get_sym(linker_file_t _lf, Elf_Size _symidx); const char *elf_get_symname(linker_file_t _lf, Elf_Size _symidx); void link_elf_ireloc(caddr_t kmdp); #if defined(__aarch64__) || defined(__amd64__) int elf_reloc_late(linker_file_t _lf, Elf_Addr base, const void *_rel, int _type, elf_lookup_fn _lu); void link_elf_late_ireloc(void); #endif typedef struct linker_ctf { const uint8_t *ctftab; /* Decompressed CTF data. */ int ctfcnt; /* Number of CTF data bytes. */ const Elf_Sym *symtab; /* Ptr to the symbol table. */ int nsym; /* Number of symbols. */ const char *strtab; /* Ptr to the string table. */ int strcnt; /* Number of string bytes. */ uint32_t **ctfoffp; /* Ptr to array of obj/fnc offsets. */ uint32_t **typoffp; /* Ptr to array of type offsets. */ long *typlenp; /* Ptr to number of type data entries. */ } linker_ctf_t; int linker_ctf_get(linker_file_t, linker_ctf_t *); int linker_ctf_lookup_sym_ddb(const char *symname, c_linker_sym_t *sym, linker_ctf_t *lc); int linker_ctf_lookup_typename_ddb(linker_ctf_t *lc, const char *typename); int elf_cpu_load_file(linker_file_t); int elf_cpu_unload_file(linker_file_t); int elf_cpu_parse_dynamic(caddr_t, Elf_Dyn *); /* values for type */ #define ELF_RELOC_REL 1 #define ELF_RELOC_RELA 2 /* * This is version 1 of the KLD file status structure. It is identified * by its _size_ in the version field. */ struct kld_file_stat_1 { int version; /* set to sizeof(struct kld_file_stat_1) */ char name[MAXPATHLEN]; int refs; int id; caddr_t address; /* load address */ size_t size; /* size in bytes */ }; #endif /* _KERNEL */ struct kld_file_stat { int version; /* set to sizeof(struct kld_file_stat) */ char name[MAXPATHLEN]; int refs; int id; caddr_t address; /* load address */ size_t size; /* size in bytes */ char pathname[MAXPATHLEN]; }; struct kld_sym_lookup { int version; /* set to sizeof(struct kld_sym_lookup) */ char *symname; /* Symbol name we are looking up */ u_long symvalue; size_t symsize; }; #define KLDSYM_LOOKUP 1 /* * Flags for kldunloadf() and linker_file_unload() */ #define LINKER_UNLOAD_NORMAL 0 #define LINKER_UNLOAD_FORCE 1 #ifndef _KERNEL #include __BEGIN_DECLS int kldload(const char* _file); int kldunload(int _fileid); int kldunloadf(int _fileid, int flags); int kldfind(const char* _file); int kldnext(int _fileid); int kldstat(int _fileid, struct kld_file_stat* _stat); int kldfirstmod(int _fileid); int kldsym(int _fileid, int _cmd, void *_data); __END_DECLS #endif #endif /* !_SYS_LINKER_H_ */