Deleted Added
full compact
kern_linker.c (105337) kern_linker.c (107089)
1/*-
2 * Copyright (c) 1997-2000 Doug Rabson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 1997-2000 Doug Rabson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/kern/kern_linker.c 105337 2002-10-17 17:28:57Z sam $
26 * $FreeBSD: head/sys/kern/kern_linker.c 107089 2002-11-19 22:12:42Z rwatson $
27 */
28
29#include "opt_ddb.h"
27 */
28
29#include "opt_ddb.h"
30#include "opt_mac.h"
30
31#include <sys/param.h>
32#include <sys/kernel.h>
33#include <sys/systm.h>
34#include <sys/malloc.h>
35#include <sys/sysproto.h>
36#include <sys/sysent.h>
37#include <sys/proc.h>
38#include <sys/lock.h>
39#include <sys/mutex.h>
40#include <sys/sx.h>
31
32#include <sys/param.h>
33#include <sys/kernel.h>
34#include <sys/systm.h>
35#include <sys/malloc.h>
36#include <sys/sysproto.h>
37#include <sys/sysent.h>
38#include <sys/proc.h>
39#include <sys/lock.h>
40#include <sys/mutex.h>
41#include <sys/sx.h>
42#include <sys/mac.h>
41#include <sys/module.h>
42#include <sys/linker.h>
43#include <sys/fcntl.h>
44#include <sys/libkern.h>
45#include <sys/namei.h>
46#include <sys/vnode.h>
47#include <sys/sysctl.h>
48

--- 420 unchanged lines hidden (view full) ---

469 struct common_symbol *cp;
470 int error, i;
471
472 error = 0;
473
474 /* Refuse to unload modules if securelevel raised. */
475 if (securelevel > 0)
476 return (EPERM);
43#include <sys/module.h>
44#include <sys/linker.h>
45#include <sys/fcntl.h>
46#include <sys/libkern.h>
47#include <sys/namei.h>
48#include <sys/vnode.h>
49#include <sys/sysctl.h>
50

--- 420 unchanged lines hidden (view full) ---

471 struct common_symbol *cp;
472 int error, i;
473
474 error = 0;
475
476 /* Refuse to unload modules if securelevel raised. */
477 if (securelevel > 0)
478 return (EPERM);
479#ifdef MAC
480 error = mac_check_kld_unload(curthread->td_ucred);
481 if (error)
482 return (error);
483#endif
477
478 KLD_DPF(FILE, ("linker_file_unload: lf->refs=%d\n", file->refs));
479 if (file->refs == 1) {
480 KLD_DPF(FILE, ("linker_file_unload: file is unloading,"
481 " informing modules\n"));
482
483 /*
484 * Inform any modules associated with this file.

--- 334 unchanged lines hidden (view full) ---

819int
820kldfind(struct thread *td, struct kldfind_args *uap)
821{
822 char *pathname;
823 const char *filename;
824 linker_file_t lf;
825 int error = 0;
826
484
485 KLD_DPF(FILE, ("linker_file_unload: lf->refs=%d\n", file->refs));
486 if (file->refs == 1) {
487 KLD_DPF(FILE, ("linker_file_unload: file is unloading,"
488 " informing modules\n"));
489
490 /*
491 * Inform any modules associated with this file.

--- 334 unchanged lines hidden (view full) ---

826int
827kldfind(struct thread *td, struct kldfind_args *uap)
828{
829 char *pathname;
830 const char *filename;
831 linker_file_t lf;
832 int error = 0;
833
834#ifdef MAC
835 error = mac_check_kld_stat(td->td_ucred);
836 if (error)
837 return (error);
838#endif
839
827 mtx_lock(&Giant);
828 td->td_retval[0] = -1;
829
830 pathname = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
831 if ((error = copyinstr(SCARG(uap, file), pathname, MAXPATHLEN,
832 NULL)) != 0)
833 goto out;
834

--- 14 unchanged lines hidden (view full) ---

849 * MPSAFE
850 */
851int
852kldnext(struct thread *td, struct kldnext_args *uap)
853{
854 linker_file_t lf;
855 int error = 0;
856
840 mtx_lock(&Giant);
841 td->td_retval[0] = -1;
842
843 pathname = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
844 if ((error = copyinstr(SCARG(uap, file), pathname, MAXPATHLEN,
845 NULL)) != 0)
846 goto out;
847

--- 14 unchanged lines hidden (view full) ---

862 * MPSAFE
863 */
864int
865kldnext(struct thread *td, struct kldnext_args *uap)
866{
867 linker_file_t lf;
868 int error = 0;
869
870#ifdef MAC
871 error = mac_check_kld_stat(td->td_ucred);
872 if (error)
873 return (error);
874#endif
875
857 mtx_lock(&Giant);
858
859 if (SCARG(uap, fileid) == 0) {
860 mtx_lock(&kld_mtx);
861 if (TAILQ_FIRST(&linker_files))
862 td->td_retval[0] = TAILQ_FIRST(&linker_files)->id;
863 else
864 td->td_retval[0] = 0;

--- 19 unchanged lines hidden (view full) ---

884int
885kldstat(struct thread *td, struct kldstat_args *uap)
886{
887 linker_file_t lf;
888 int error = 0;
889 int namelen, version;
890 struct kld_file_stat *stat;
891
876 mtx_lock(&Giant);
877
878 if (SCARG(uap, fileid) == 0) {
879 mtx_lock(&kld_mtx);
880 if (TAILQ_FIRST(&linker_files))
881 td->td_retval[0] = TAILQ_FIRST(&linker_files)->id;
882 else
883 td->td_retval[0] = 0;

--- 19 unchanged lines hidden (view full) ---

903int
904kldstat(struct thread *td, struct kldstat_args *uap)
905{
906 linker_file_t lf;
907 int error = 0;
908 int namelen, version;
909 struct kld_file_stat *stat;
910
911#ifdef MAC
912 error = mac_check_kld_stat(td->td_ucred);
913 if (error)
914 return (error);
915#endif
916
892 mtx_lock(&Giant);
893
894 lf = linker_find_file_by_id(SCARG(uap, fileid));
895 if (lf == NULL) {
896 error = ENOENT;
897 goto out;
898 }
899 stat = SCARG(uap, stat);

--- 33 unchanged lines hidden (view full) ---

933 */
934int
935kldfirstmod(struct thread *td, struct kldfirstmod_args *uap)
936{
937 linker_file_t lf;
938 module_t mp;
939 int error = 0;
940
917 mtx_lock(&Giant);
918
919 lf = linker_find_file_by_id(SCARG(uap, fileid));
920 if (lf == NULL) {
921 error = ENOENT;
922 goto out;
923 }
924 stat = SCARG(uap, stat);

--- 33 unchanged lines hidden (view full) ---

958 */
959int
960kldfirstmod(struct thread *td, struct kldfirstmod_args *uap)
961{
962 linker_file_t lf;
963 module_t mp;
964 int error = 0;
965
966#ifdef MAC
967 error = mac_check_kld_stat(td->td_ucred);
968 if (error)
969 return (error);
970#endif
971
941 mtx_lock(&Giant);
942 lf = linker_find_file_by_id(SCARG(uap, fileid));
943 if (lf) {
944 MOD_SLOCK;
945 mp = TAILQ_FIRST(&lf->modules);
946 if (mp != NULL)
947 td->td_retval[0] = module_getid(mp);
948 else

--- 13 unchanged lines hidden (view full) ---

962{
963 char *symstr = NULL;
964 c_linker_sym_t sym;
965 linker_symval_t symval;
966 linker_file_t lf;
967 struct kld_sym_lookup lookup;
968 int error = 0;
969
972 mtx_lock(&Giant);
973 lf = linker_find_file_by_id(SCARG(uap, fileid));
974 if (lf) {
975 MOD_SLOCK;
976 mp = TAILQ_FIRST(&lf->modules);
977 if (mp != NULL)
978 td->td_retval[0] = module_getid(mp);
979 else

--- 13 unchanged lines hidden (view full) ---

993{
994 char *symstr = NULL;
995 c_linker_sym_t sym;
996 linker_symval_t symval;
997 linker_file_t lf;
998 struct kld_sym_lookup lookup;
999 int error = 0;
1000
1001#ifdef MAC
1002 error = mac_check_kld_stat(td->td_ucred);
1003 if (error)
1004 return (error);
1005#endif
1006
970 mtx_lock(&Giant);
971
972 if ((error = copyin(SCARG(uap, data), &lookup, sizeof(lookup))) != 0)
973 goto out;
974 if (lookup.version != sizeof(lookup) ||
975 SCARG(uap, cmd) != KLDSYM_LOOKUP) {
976 error = EINVAL;
977 goto out;

--- 817 unchanged lines hidden (view full) ---

1795 * in the kernel.
1796 */
1797static int
1798sysctl_kern_function_list(SYSCTL_HANDLER_ARGS)
1799{
1800 linker_file_t lf;
1801 int error;
1802
1007 mtx_lock(&Giant);
1008
1009 if ((error = copyin(SCARG(uap, data), &lookup, sizeof(lookup))) != 0)
1010 goto out;
1011 if (lookup.version != sizeof(lookup) ||
1012 SCARG(uap, cmd) != KLDSYM_LOOKUP) {
1013 error = EINVAL;
1014 goto out;

--- 817 unchanged lines hidden (view full) ---

1832 * in the kernel.
1833 */
1834static int
1835sysctl_kern_function_list(SYSCTL_HANDLER_ARGS)
1836{
1837 linker_file_t lf;
1838 int error;
1839
1840#ifdef MAC
1841 error = mac_check_kld_stat(req->td->td_ucred);
1842 if (error)
1843 return (error);
1844#endif
1803 sysctl_wire_old_buffer(req, 0);
1804 mtx_lock(&kld_mtx);
1805 TAILQ_FOREACH(lf, &linker_files, link) {
1806 error = LINKER_EACH_FUNCTION_NAME(lf,
1807 sysctl_kern_function_list_iterate, req);
1808 if (error) {
1809 mtx_unlock(&kld_mtx);
1810 return (error);
1811 }
1812 }
1813 mtx_unlock(&kld_mtx);
1814 return (SYSCTL_OUT(req, "", 1));
1815}
1816
1817SYSCTL_PROC(_kern, OID_AUTO, function_list, CTLFLAG_RD,
1818 NULL, 0, sysctl_kern_function_list, "", "kernel function list");
1845 sysctl_wire_old_buffer(req, 0);
1846 mtx_lock(&kld_mtx);
1847 TAILQ_FOREACH(lf, &linker_files, link) {
1848 error = LINKER_EACH_FUNCTION_NAME(lf,
1849 sysctl_kern_function_list_iterate, req);
1850 if (error) {
1851 mtx_unlock(&kld_mtx);
1852 return (error);
1853 }
1854 }
1855 mtx_unlock(&kld_mtx);
1856 return (SYSCTL_OUT(req, "", 1));
1857}
1858
1859SYSCTL_PROC(_kern, OID_AUTO, function_list, CTLFLAG_RD,
1860 NULL, 0, sysctl_kern_function_list, "", "kernel function list");