2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2002, 2003 Greg Lehey
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * This software is provided by the author ``as is'' and any express
17 * or implied warranties, including, but not limited to, the implied
18 * warranties of merchantability and fitness for a particular purpose
19 * are disclaimed. In no event shall the author be liable for any
20 * direct, indirect, incidental, special, exemplary, or consequential
21 * damages (including, but not limited to, procurement of substitute
22 * goods or services; loss of use, data, or profits; or business
23 * interruption) however caused and on any theory of liability,
24 * whether in contract, strict liability, or tort (including
25 * negligence or otherwise) arising in any way out of the use of this
26 * software, even if advised of the possibility of such damage.
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/types.h>
42 * Get the linker file list from kldstat(8) output.
43 * The "run" flag tells if kldstat(8) should run now.
44 * Of course, kldstat(1) can run in a live system only, but its output
45 * can be saved beforehand and fed to this function later via stdin.
51 char *token[MAXTOKEN];
58 if ((kldstat = popen("kldstat", "r")) == NULL)
59 err(2, "can't start kldstat");
63 while (fgets(buf, sizeof(buf), kldstat)) {
64 /* Skip header line and main kernel file */
65 if (buf[0] == 'I' || strstr(buf, KERNFILE))
67 tokens = tokenize(buf, token, MAXTOKEN);
70 base = (caddr_t)(uintptr_t)strtoumax(token[2], &endp, 16);
71 if (endp == NULL || *endp != '\0')
73 kfile_add(token[4], base);