kern_linker.c (193511) | kern_linker.c (195159) |
---|---|
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 193511 2009-06-05 14:55:22Z rwatson $"); | 28__FBSDID("$FreeBSD: head/sys/kern/kern_linker.c 195159 2009-06-29 16:03:18Z attilio $"); |
29 30#include "opt_ddb.h" 31#include "opt_hwpmc_hooks.h" 32 33#include <sys/param.h> 34#include <sys/kernel.h> 35#include <sys/systm.h> 36#include <sys/malloc.h> --- 1885 unchanged lines hidden (view full) --- 1922 if (filename == NULL) 1923 return path; 1924 if (filename[1]) 1925 filename++; 1926 return (filename); 1927} 1928 1929#ifdef HWPMC_HOOKS | 29 30#include "opt_ddb.h" 31#include "opt_hwpmc_hooks.h" 32 33#include <sys/param.h> 34#include <sys/kernel.h> 35#include <sys/systm.h> 36#include <sys/malloc.h> --- 1885 unchanged lines hidden (view full) --- 1922 if (filename == NULL) 1923 return path; 1924 if (filename[1]) 1925 filename++; 1926 return (filename); 1927} 1928 1929#ifdef HWPMC_HOOKS |
1930 1931struct hwpmc_context { 1932 int nobjects; 1933 int nmappings; 1934 struct pmckern_map_in *kobase; 1935}; 1936 1937static int 1938linker_hwpmc_list_object(linker_file_t lf, void *arg) 1939{ 1940 struct hwpmc_context *hc; 1941 1942 hc = arg; 1943 1944 /* If we run out of mappings, fail. */ 1945 if (hc->nobjects >= hc->nmappings) 1946 return (1); 1947 1948 /* Save the info for this linker file. */ 1949 hc->kobase[hc->nobjects].pm_file = lf->filename; 1950 hc->kobase[hc->nobjects].pm_address = (uintptr_t)lf->address; 1951 hc->nobjects++; 1952 return (0); 1953} 1954 | |
1955/* 1956 * Inform hwpmc about the set of kernel modules currently loaded. 1957 */ 1958void * 1959linker_hwpmc_list_objects(void) 1960{ | 1930/* 1931 * Inform hwpmc about the set of kernel modules currently loaded. 1932 */ 1933void * 1934linker_hwpmc_list_objects(void) 1935{ |
1961 struct hwpmc_context hc; | 1936 linker_file_t lf; 1937 struct pmckern_map_in *kobase; 1938 int i, nmappings; |
1962 | 1939 |
1963 hc.nmappings = 15; /* a reasonable default */ | 1940 nmappings = 0; 1941 KLD_LOCK(); 1942 TAILQ_FOREACH(lf, &linker_files, link) 1943 nmappings++; |
1964 | 1944 |
1965 retry: 1966 /* allocate nmappings+1 entries */ 1967 hc.kobase = malloc((hc.nmappings + 1) * sizeof(struct pmckern_map_in), | 1945 /* Allocate nmappings + 1 entries. */ 1946 kobase = malloc((nmappings + 1) * sizeof(struct pmckern_map_in), |
1968 M_LINKER, M_WAITOK | M_ZERO); | 1947 M_LINKER, M_WAITOK | M_ZERO); |
1948 i = 0; 1949 TAILQ_FOREACH(lf, &linker_files, link) { |
|
1969 | 1950 |
1970 hc.nobjects = 0; 1971 if (linker_file_foreach(linker_hwpmc_list_object, &hc) != 0) { 1972 hc.nmappings = hc.nobjects; 1973 free(hc.kobase, M_LINKER); 1974 goto retry; | 1951 /* Save the info for this linker file. */ 1952 kobase[i].pm_file = lf->filename; 1953 kobase[i].pm_address = (uintptr_t)lf->address; 1954 i++; |
1975 } | 1955 } |
1956 KLD_UNLOCK(); |
|
1976 | 1957 |
1977 KASSERT(hc.nobjects > 0, ("linker_hpwmc_list_objects: no kernel " 1978 "objects?")); | 1958 KASSERT(i > 0, ("linker_hpwmc_list_objects: no kernel objects?")); |
1979 1980 /* The last entry of the malloced area comprises of all zeros. */ | 1959 1960 /* The last entry of the malloced area comprises of all zeros. */ |
1981 KASSERT(hc.kobase[hc.nobjects].pm_file == NULL, | 1961 KASSERT(kobase[i].pm_file == NULL, |
1982 ("linker_hwpmc_list_objects: last object not NULL")); 1983 | 1962 ("linker_hwpmc_list_objects: last object not NULL")); 1963 |
1984 return ((void *)hc.kobase); | 1964 return ((void *)kobase); |
1985} 1986#endif 1987 1988/* 1989 * Find a file which contains given module and load it, if "parent" is not 1990 * NULL, register a reference to it. 1991 */ 1992static int --- 190 unchanged lines hidden --- | 1965} 1966#endif 1967 1968/* 1969 * Find a file which contains given module and load it, if "parent" is not 1970 * NULL, register a reference to it. 1971 */ 1972static int --- 190 unchanged lines hidden --- |