Deleted Added
full compact
kern_linker.c (43185) kern_linker.c (43301)
1/*-
2 * Copyright (c) 1997 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 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 * $Id: kern_linker.c,v 1.22 1999/01/23 03:45:22 peter Exp $
26 * $Id: kern_linker.c,v 1.23 1999/01/25 08:42:24 dfr Exp $
27 */
28
29#include "opt_ddb.h"
30
31#include <sys/param.h>
32#include <sys/kernel.h>
33#include <sys/systm.h>
34#include <sys/malloc.h>

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

389 * Inform any modules associated with this file.
390 */
391 for (mod = TAILQ_FIRST(&file->modules); mod; mod = next) {
392 next = module_getfnext(mod);
393
394 /*
395 * Give the module a chance to veto the unload.
396 */
27 */
28
29#include "opt_ddb.h"
30
31#include <sys/param.h>
32#include <sys/kernel.h>
33#include <sys/systm.h>
34#include <sys/malloc.h>

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

389 * Inform any modules associated with this file.
390 */
391 for (mod = TAILQ_FIRST(&file->modules); mod; mod = next) {
392 next = module_getfnext(mod);
393
394 /*
395 * Give the module a chance to veto the unload.
396 */
397 if (error = module_unload(mod)) {
397 if ((error = module_unload(mod)) != 0) {
398 KLD_DPF(FILE, ("linker_file_unload: module %x vetoes unload\n",
399 mod));
400 lockmgr(&lock, LK_RELEASE, 0, curproc);
401 goto out;
402 }
403
404 module_release(mod);
405 }

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

634 linker_file_t lf;
635 int error = 0;
636
637 p->p_retval[0] = -1;
638
639 if (securelevel > 0)
640 return EPERM;
641
398 KLD_DPF(FILE, ("linker_file_unload: module %x vetoes unload\n",
399 mod));
400 lockmgr(&lock, LK_RELEASE, 0, curproc);
401 goto out;
402 }
403
404 module_release(mod);
405 }

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

634 linker_file_t lf;
635 int error = 0;
636
637 p->p_retval[0] = -1;
638
639 if (securelevel > 0)
640 return EPERM;
641
642 if (error = suser(p->p_ucred, &p->p_acflag))
642 if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
643 return error;
644
645 filename = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
643 return error;
644
645 filename = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
646 if (error = copyinstr(SCARG(uap, file), filename, MAXPATHLEN, NULL))
646 if ((error = copyinstr(SCARG(uap, file), filename, MAXPATHLEN, NULL)) != 0)
647 goto out;
648
649 /* Can't load more than one module with the same name */
650 modulename = rindex(filename, '/');
651 if (modulename == NULL)
652 modulename = filename;
653 if (linker_find_file_by_name(modulename)) {
654 error = EEXIST;
655 goto out;
656 }
657
647 goto out;
648
649 /* Can't load more than one module with the same name */
650 modulename = rindex(filename, '/');
651 if (modulename == NULL)
652 modulename = filename;
653 if (linker_find_file_by_name(modulename)) {
654 error = EEXIST;
655 goto out;
656 }
657
658 if (error = linker_load_file(filename, &lf))
658 if ((error = linker_load_file(filename, &lf)) != 0)
659 goto out;
660
661 lf->userrefs++;
662 p->p_retval[0] = lf->id;
663
664out:
665 if (filename)
666 free(filename, M_TEMP);

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

671kldunload(struct proc* p, struct kldunload_args* uap)
672{
673 linker_file_t lf;
674 int error = 0;
675
676 if (securelevel > 0)
677 return EPERM;
678
659 goto out;
660
661 lf->userrefs++;
662 p->p_retval[0] = lf->id;
663
664out:
665 if (filename)
666 free(filename, M_TEMP);

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

671kldunload(struct proc* p, struct kldunload_args* uap)
672{
673 linker_file_t lf;
674 int error = 0;
675
676 if (securelevel > 0)
677 return EPERM;
678
679 if (error = suser(p->p_ucred, &p->p_acflag))
679 if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
680 return error;
681
682 lf = linker_find_file_by_id(SCARG(uap, fileid));
683 if (lf) {
684 KLD_DPF(FILE, ("kldunload: lf->userrefs=%d\n", lf->userrefs));
685 if (lf->userrefs == 0) {
686 printf("linkerunload: attempt to unload file that was loaded by the kernel\n");
687 error = EBUSY;

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

703{
704 char* filename = NULL, *modulename;
705 linker_file_t lf;
706 int error = 0;
707
708 p->p_retval[0] = -1;
709
710 filename = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
680 return error;
681
682 lf = linker_find_file_by_id(SCARG(uap, fileid));
683 if (lf) {
684 KLD_DPF(FILE, ("kldunload: lf->userrefs=%d\n", lf->userrefs));
685 if (lf->userrefs == 0) {
686 printf("linkerunload: attempt to unload file that was loaded by the kernel\n");
687 error = EBUSY;

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

703{
704 char* filename = NULL, *modulename;
705 linker_file_t lf;
706 int error = 0;
707
708 p->p_retval[0] = -1;
709
710 filename = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
711 if (error = copyinstr(SCARG(uap, file), filename, MAXPATHLEN, NULL))
711 if ((error = copyinstr(SCARG(uap, file), filename, MAXPATHLEN, NULL)) != 0)
712 goto out;
713
714 modulename = rindex(filename, '/');
715 if (modulename == NULL)
716 modulename = filename;
717
718 lf = linker_find_file_by_name(modulename);
719 if (lf)

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

768 goto out;
769 }
770
771 stat = SCARG(uap, stat);
772
773 /*
774 * Check the version of the user's structure.
775 */
712 goto out;
713
714 modulename = rindex(filename, '/');
715 if (modulename == NULL)
716 modulename = filename;
717
718 lf = linker_find_file_by_name(modulename);
719 if (lf)

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

768 goto out;
769 }
770
771 stat = SCARG(uap, stat);
772
773 /*
774 * Check the version of the user's structure.
775 */
776 if (error = copyin(&stat->version, &version, sizeof(version)))
776 if ((error = copyin(&stat->version, &version, sizeof(version))) != 0)
777 goto out;
778 if (version != sizeof(struct kld_file_stat)) {
779 error = EINVAL;
780 goto out;
781 }
782
783 namelen = strlen(lf->filename) + 1;
784 if (namelen > MAXPATHLEN)
785 namelen = MAXPATHLEN;
777 goto out;
778 if (version != sizeof(struct kld_file_stat)) {
779 error = EINVAL;
780 goto out;
781 }
782
783 namelen = strlen(lf->filename) + 1;
784 if (namelen > MAXPATHLEN)
785 namelen = MAXPATHLEN;
786 if (error = copyout(lf->filename, &stat->name[0], namelen))
786 if ((error = copyout(lf->filename, &stat->name[0], namelen)) != 0)
787 goto out;
787 goto out;
788 if (error = copyout(&lf->refs, &stat->refs, sizeof(int)))
788 if ((error = copyout(&lf->refs, &stat->refs, sizeof(int))) != 0)
789 goto out;
789 goto out;
790 if (error = copyout(&lf->id, &stat->id, sizeof(int)))
790 if ((error = copyout(&lf->id, &stat->id, sizeof(int))) != 0)
791 goto out;
791 goto out;
792 if (error = copyout(&lf->address, &stat->address, sizeof(caddr_t)))
792 if ((error = copyout(&lf->address, &stat->address, sizeof(caddr_t))) != 0)
793 goto out;
793 goto out;
794 if (error = copyout(&lf->size, &stat->size, sizeof(size_t)))
794 if ((error = copyout(&lf->size, &stat->size, sizeof(size_t))) != 0)
795 goto out;
796
797 p->p_retval[0] = 0;
798
799out:
800 return error;
801}
802

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

823{
824 char *symstr = NULL;
825 linker_sym_t sym;
826 linker_symval_t symval;
827 linker_file_t lf;
828 struct kld_sym_lookup lookup;
829 int error = 0;
830
795 goto out;
796
797 p->p_retval[0] = 0;
798
799out:
800 return error;
801}
802

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

823{
824 char *symstr = NULL;
825 linker_sym_t sym;
826 linker_symval_t symval;
827 linker_file_t lf;
828 struct kld_sym_lookup lookup;
829 int error = 0;
830
831 if (error = copyin(SCARG(uap, data), &lookup, sizeof(lookup)))
831 if ((error = copyin(SCARG(uap, data), &lookup, sizeof(lookup))) != 0)
832 goto out;
833 if (lookup.version != sizeof(lookup) || SCARG(uap, cmd) != KLDSYM_LOOKUP) {
834 error = EINVAL;
835 goto out;
836 }
837
838 symstr = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
832 goto out;
833 if (lookup.version != sizeof(lookup) || SCARG(uap, cmd) != KLDSYM_LOOKUP) {
834 error = EINVAL;
835 goto out;
836 }
837
838 symstr = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
839 if (error = copyinstr(lookup.symname, symstr, MAXPATHLEN, NULL))
839 if ((error = copyinstr(lookup.symname, symstr, MAXPATHLEN, NULL)) != 0)
840 goto out;
841
842 if (SCARG(uap, fileid) != 0) {
843 lf = linker_find_file_by_id(SCARG(uap, fileid));
844 if (lf == NULL) {
845 error = ENOENT;
846 goto out;
847 }

--- 172 unchanged lines hidden ---
840 goto out;
841
842 if (SCARG(uap, fileid) != 0) {
843 lf = linker_find_file_by_id(SCARG(uap, fileid));
844 if (lf == NULL) {
845 error = ENOENT;
846 goto out;
847 }

--- 172 unchanged lines hidden ---