1159720Syar/*-
2159720Syar * Copyright (c) 2006 The FreeBSD Project
3159720Syar * All rights reserved.
4159720Syar *
5159720Syar * Redistribution and use in source and binary forms, with or without
6159720Syar * modification, are permitted provided that the following conditions
7159720Syar * are met:
8159720Syar * 1. Redistributions of source code must retain the above copyright
9159720Syar *    notice, this list of conditions and the following disclaimer.
10159720Syar * 2. Redistributions in binary form must reproduce the above copyright
11159720Syar *    notice, this list of conditions and the following disclaimer in the
12159720Syar *    documentation and/or other materials provided with the distribution.
13159720Syar *
14159720Syar * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15159720Syar * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16159720Syar * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17159720Syar * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18159720Syar * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19159720Syar * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20159720Syar * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21159720Syar * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22159720Syar * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23159720Syar * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24159720Syar * SUCH DAMAGE.
25159720Syar */
26159720Syar
27159720Syar#include <sys/cdefs.h>
28159720Syar__FBSDID("$FreeBSD: releng/11.0/usr.sbin/asf/asf_kld.c 201387 2010-01-02 11:05:34Z ed $");
29159720Syar
30159720Syar#include <sys/param.h>
31159720Syar#include <sys/linker.h>
32159720Syar#include <err.h>
33159720Syar#include <string.h>
34159720Syar
35159720Syar#include "asf.h"
36159720Syar
37159720Syar/*
38159720Syar * Get the linker file list using the kld interface.
39159720Syar * Works with a live kernel only.
40159720Syar */
41159720Syarvoid
42201387Sedasf_kld(void)
43159720Syar{
44159720Syar	struct kld_file_stat kfs;
45159720Syar	int fid = 0;	/* indicates the beginning of the linker file list */
46159720Syar
47159720Syar	while ((fid = kldnext(fid)) != 0) {
48159720Syar		if (fid == -1)
49159720Syar			err(2, "kldnext");
50159720Syar		kfs.version = sizeof(kfs);	/* must be set for kldstat(2) */
51159720Syar		/* Get info on this linker file */
52159720Syar		if (kldstat(fid, &kfs) == -1)
53159720Syar			err(2, "kldstat");
54159720Syar		if (strcmp(kfs.name, KERNFILE) == 0)
55159720Syar			continue;
56159720Syar		/* Add to our list of linker files */
57159720Syar		kfile_add(kfs.name, kfs.address);
58159720Syar	}
59159720Syar}
60