kern_linker.c (aaf3170501aafa623b84036cc3eac491f60dc176) | kern_linker.c (932151064a84d545812047bb5b01c34a08cfd03a) |
---|---|
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 --- 435 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 | 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 --- 435 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 --- |