Deleted Added
full compact
kern_linker.c (159796) kern_linker.c (159797)
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

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

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
27#include <sys/cdefs.h>
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

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

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
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/kern/kern_linker.c 159796 2006-06-20 20:18:42Z jhb $");
28__FBSDID("$FreeBSD: head/sys/kern/kern_linker.c 159797 2006-06-20 20:37:17Z jhb $");
29
30#include "opt_ddb.h"
31#include "opt_hwpmc_hooks.h"
32#include "opt_mac.h"
33
34#include <sys/param.h>
35#include <sys/kernel.h>
36#include <sys/systm.h>

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

444 mtx_lock(&kld_mtx);
445 TAILQ_FOREACH(lf, &linker_files, link)
446 if (lf->id == fileid)
447 break;
448 mtx_unlock(&kld_mtx);
449 return (lf);
450}
451
29
30#include "opt_ddb.h"
31#include "opt_hwpmc_hooks.h"
32#include "opt_mac.h"
33
34#include <sys/param.h>
35#include <sys/kernel.h>
36#include <sys/systm.h>

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

444 mtx_lock(&kld_mtx);
445 TAILQ_FOREACH(lf, &linker_files, link)
446 if (lf->id == fileid)
447 break;
448 mtx_unlock(&kld_mtx);
449 return (lf);
450}
451
452int
453linker_file_foreach(linker_predicate_t *predicate, void *context)
454{
455 linker_file_t lf;
456 int retval = 0;
457
458 mtx_lock(&Giant);
459 TAILQ_FOREACH(lf, &linker_files, link) {
460 retval = predicate(lf, context);
461 if (retval != 0)
462 break;
463 }
464 mtx_unlock(&Giant);
465 return (retval);
466}
467
452linker_file_t
453linker_make_file(const char *pathname, linker_class_t lc)
454{
455 linker_file_t lf;
456 const char *filename;
457
458 filename = linker_basename(pathname);
459

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

1664 return path;
1665 if (filename[1])
1666 filename++;
1667 return (filename);
1668}
1669
1670#ifdef HWPMC_HOOKS
1671
468linker_file_t
469linker_make_file(const char *pathname, linker_class_t lc)
470{
471 linker_file_t lf;
472 const char *filename;
473
474 filename = linker_basename(pathname);
475

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

1680 return path;
1681 if (filename[1])
1682 filename++;
1683 return (filename);
1684}
1685
1686#ifdef HWPMC_HOOKS
1687
1688struct hwpmc_context {
1689 int nobjects;
1690 int nmappings;
1691 struct pmckern_map_in *kobase;
1692};
1693
1694static int
1695linker_hwpmc_list_object(linker_file_t lf, void *arg)
1696{
1697 struct hwpmc_context *hc;
1698
1699 hc = arg;
1700
1701 /* If we run out of mappings, fail. */
1702 if (hc->nobjects >= hc->nmappings)
1703 return (1);
1704
1705 /* Save the info for this linker file. */
1706 hc->kobase[hc->nobjects].pm_file = lf->filename;
1707 hc->kobase[hc->nobjects].pm_address = (uintptr_t)lf->address;
1708 hc->nobjects++;
1709 return (0);
1710}
1711
1672/*
1673 * Inform hwpmc about the set of kernel modules currently loaded.
1674 */
1675void *
1676linker_hwpmc_list_objects(void)
1677{
1712/*
1713 * Inform hwpmc about the set of kernel modules currently loaded.
1714 */
1715void *
1716linker_hwpmc_list_objects(void)
1717{
1678 int nobjects, nmappings;
1679 linker_file_t lf;
1680 struct pmckern_map_in *ko, *kobase;
1718 struct hwpmc_context hc;
1681
1719
1682 nmappings = 15; /* a reasonable default */
1720 hc.nmappings = 15; /* a reasonable default */
1683
1684 retry:
1685 /* allocate nmappings+1 entries */
1721
1722 retry:
1723 /* allocate nmappings+1 entries */
1686 MALLOC(kobase, struct pmckern_map_in *,
1687 (nmappings + 1) * sizeof(struct pmckern_map_in), M_LINKER,
1724 MALLOC(hc.kobase, struct pmckern_map_in *,
1725 (hc.nmappings + 1) * sizeof(struct pmckern_map_in), M_LINKER,
1688 M_WAITOK | M_ZERO);
1689
1726 M_WAITOK | M_ZERO);
1727
1690 nobjects = 0;
1691 mtx_lock(&kld_mtx);
1692 TAILQ_FOREACH(lf, &linker_files, link)
1693 nobjects++;
1694
1695 KASSERT(nobjects > 0, ("linker_hpwmc_list_objects: no kernel "
1696 "objects?"));
1697
1698 if (nobjects > nmappings) {
1699 nmappings = nobjects;
1700 FREE(kobase, M_LINKER);
1701 mtx_unlock(&kld_mtx);
1728 hc.nobjects = 0;
1729 if (linker_file_foreach(linker_hwpmc_list_object, &hc) != 0) {
1730 hc.nmappings = hc.nobjects;
1731 FREE(hc.kobase, M_LINKER);
1702 goto retry;
1703 }
1704
1732 goto retry;
1733 }
1734
1705 ko = kobase;
1706 TAILQ_FOREACH(lf, &linker_files, link) {
1707 ko->pm_file = lf->filename;
1708 ko->pm_address = (uintptr_t) lf->address;
1709 ko++;
1710 }
1735 KASSERT(hc.nobjects > 0, ("linker_hpwmc_list_objects: no kernel "
1736 "objects?"));
1711
1712 /* The last entry of the malloced area comprises of all zeros. */
1737
1738 /* The last entry of the malloced area comprises of all zeros. */
1713 KASSERT(ko->pm_file == NULL,
1739 KASSERT(hc.kobase[hc.nobjects].pm_file == NULL,
1714 ("linker_hwpmc_list_objects: last object not NULL"));
1715
1740 ("linker_hwpmc_list_objects: last object not NULL"));
1741
1716 mtx_unlock(&kld_mtx);
1717
1718 return ((void *) kobase);
1742 return ((void *)hc.kobase);
1719}
1720#endif
1721
1722/*
1723 * Find a file which contains given module and load it, if "parent" is not
1724 * NULL, register a reference to it.
1725 */
1726static int

--- 188 unchanged lines hidden ---
1743}
1744#endif
1745
1746/*
1747 * Find a file which contains given module and load it, if "parent" is not
1748 * NULL, register a reference to it.
1749 */
1750static int

--- 188 unchanged lines hidden ---