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

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

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
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 *
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

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

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
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 * $FreeBSD: head/sys/kern/kern_linker.c 83321 2001-09-11 01:09:24Z peter $
26 * $FreeBSD: head/sys/kern/kern_linker.c 83358 2001-09-12 00:50:23Z peter $
27 */
28
29#include "opt_ddb.h"
30
31#include <sys/param.h>
32#include <sys/kernel.h>
33#include <sys/systm.h>
34#include <sys/malloc.h>

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

1281 * If the module name is qualified in any way (contains path, etc.)
1282 * the we simply return a copy of it.
1283 *
1284 * The search path can be manipulated via sysctl. Note that we use the ';'
1285 * character as a separator to be consistent with the bootloader.
1286 */
1287
1288static char linker_hintfile[] = "linker.hints";
27 */
28
29#include "opt_ddb.h"
30
31#include <sys/param.h>
32#include <sys/kernel.h>
33#include <sys/systm.h>
34#include <sys/malloc.h>

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

1281 * If the module name is qualified in any way (contains path, etc.)
1282 * the we simply return a copy of it.
1283 *
1284 * The search path can be manipulated via sysctl. Note that we use the ';'
1285 * character as a separator to be consistent with the bootloader.
1286 */
1287
1288static char linker_hintfile[] = "linker.hints";
1289static char linker_path[MAXPATHLEN] = "/boot/kernel;/boot/modules/;/modules/";
1289static char linker_path[MAXPATHLEN] = "/boot/kernel;/boot/modules;/modules";
1290
1291SYSCTL_STRING(_kern, OID_AUTO, module_path, CTLFLAG_RW, linker_path,
1292 sizeof(linker_path), "module load search path");
1293
1294TUNABLE_STR("module_path", linker_path, sizeof(linker_path));
1295
1296static char *linker_ext_list[] = {
1297 "",

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

1305 * (probably should be generic for the rest of the kernel)
1306 */
1307static char *
1308linker_lookup_file(const char *path, int pathlen,
1309 const char *name, int namelen, struct vattr *vap)
1310{
1311 struct nameidata nd;
1312 struct proc *p = curproc; /* XXX */
1290
1291SYSCTL_STRING(_kern, OID_AUTO, module_path, CTLFLAG_RW, linker_path,
1292 sizeof(linker_path), "module load search path");
1293
1294TUNABLE_STR("module_path", linker_path, sizeof(linker_path));
1295
1296static char *linker_ext_list[] = {
1297 "",

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

1305 * (probably should be generic for the rest of the kernel)
1306 */
1307static char *
1308linker_lookup_file(const char *path, int pathlen,
1309 const char *name, int namelen, struct vattr *vap)
1310{
1311 struct nameidata nd;
1312 struct proc *p = curproc; /* XXX */
1313 char *result, **cpp;
1314 int error, len, extlen, flags;
1313 char *result, **cpp, *sep;
1314 int error, len, extlen, reclen, flags;
1315 enum vtype type;
1316
1317 extlen = 0;
1318 for (cpp = linker_ext_list; *cpp; cpp++) {
1319 len = strlen(*cpp);
1320 if (len > extlen)
1321 extlen = len;
1322 }
1323 extlen++; /* trailing '\0' */
1315 enum vtype type;
1316
1317 extlen = 0;
1318 for (cpp = linker_ext_list; *cpp; cpp++) {
1319 len = strlen(*cpp);
1320 if (len > extlen)
1321 extlen = len;
1322 }
1323 extlen++; /* trailing '\0' */
1324 sep = (path[pathlen - 1] != '/') ? "/" : "";
1324
1325
1325 result = malloc((pathlen + namelen + extlen), M_LINKER, M_WAITOK);
1326 reclen = pathlen + strlen(sep) + namelen + extlen + 1;
1327 result = malloc(reclen, M_LINKER, M_WAITOK);
1326 for (cpp = linker_ext_list; *cpp; cpp++) {
1328 for (cpp = linker_ext_list; *cpp; cpp++) {
1327 bcopy(path, result, pathlen);
1328 bcopy(name, result + pathlen, namelen);
1329 strcpy(result + namelen + pathlen, *cpp);
1329 snprintf(result, reclen, "%.*s%s%.*s%s", pathlen, path, sep,
1330 namelen, name, *cpp);
1330 /*
1331 * Attempt to open the file, and return the path if we succeed
1332 * and it's a regular file.
1333 */
1334 NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, result, p);
1335 flags = FREAD;
1336 error = vn_open(&nd, &flags, 0);
1337 if (error == 0) {

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

1362 const char *modname, int modnamelen,
1363 struct mod_depend *verinfo)
1364{
1365 struct proc *p = curproc;
1366 struct ucred *cred = p ? p->p_ucred : NULL;
1367 struct nameidata nd;
1368 struct vattr vattr, mattr;
1369 u_char *hints = NULL;
1331 /*
1332 * Attempt to open the file, and return the path if we succeed
1333 * and it's a regular file.
1334 */
1335 NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, result, p);
1336 flags = FREAD;
1337 error = vn_open(&nd, &flags, 0);
1338 if (error == 0) {

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

1363 const char *modname, int modnamelen,
1364 struct mod_depend *verinfo)
1365{
1366 struct proc *p = curproc;
1367 struct ucred *cred = p ? p->p_ucred : NULL;
1368 struct nameidata nd;
1369 struct vattr vattr, mattr;
1370 u_char *hints = NULL;
1370 u_char *cp, *recptr, *bufend, *result, *best, *pathbuf;
1371 u_char *cp, *recptr, *bufend, *result, *best, *pathbuf, *sep;
1371 int error, ival, bestver, *intp, reclen, found, flags, clen, blen;
1372
1373 result = NULL;
1374 bestver = found = 0;
1375
1372 int error, ival, bestver, *intp, reclen, found, flags, clen, blen;
1373
1374 result = NULL;
1375 bestver = found = 0;
1376
1376 reclen = imax(modnamelen, strlen(linker_hintfile)) + pathlen;
1377 sep = (path[pathlen - 1] != '/') ? "/" : "";
1378 reclen = imax(modnamelen, strlen(linker_hintfile)) + pathlen +
1379 strlen(sep) + 1;
1377 pathbuf = malloc(reclen, M_LINKER, M_WAITOK);
1380 pathbuf = malloc(reclen, M_LINKER, M_WAITOK);
1378 bcopy(path, pathbuf, pathlen);
1379 strcpy(pathbuf + pathlen, linker_hintfile);
1381 snprintf(pathbuf, reclen, "%.*s%s%s", pathlen, path, sep, linker_hintfile);
1380
1381 NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, pathbuf, p);
1382 flags = FREAD;
1383 error = vn_open(&nd, &flags, 0);
1384 if (error)
1385 goto bad;
1386 NDFREE(&nd, NDF_ONLY_PNBUF);
1387 VOP_UNLOCK(nd.ni_vp, 0, p);

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

1458 if (found)
1459 result = linker_lookup_file(path, pathlen, cp, clen, &mattr);
1460 else if (best)
1461 result = linker_lookup_file(path, pathlen, best, blen, &mattr);
1462 if (result && timespeccmp(&mattr.va_mtime, &vattr.va_mtime, >)) {
1463 /*
1464 * KLD is newer than hints file. What we should do now ?
1465 */
1382
1383 NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, pathbuf, p);
1384 flags = FREAD;
1385 error = vn_open(&nd, &flags, 0);
1386 if (error)
1387 goto bad;
1388 NDFREE(&nd, NDF_ONLY_PNBUF);
1389 VOP_UNLOCK(nd.ni_vp, 0, p);

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

1460 if (found)
1461 result = linker_lookup_file(path, pathlen, cp, clen, &mattr);
1462 else if (best)
1463 result = linker_lookup_file(path, pathlen, best, blen, &mattr);
1464 if (result && timespeccmp(&mattr.va_mtime, &vattr.va_mtime, >)) {
1465 /*
1466 * KLD is newer than hints file. What we should do now ?
1467 */
1466 printf("warning: KLD '%s' is newer than the linker.hints file\n", result);
1468 printf("warning: KLD '%s' is newer than the linker.hints file\n",
1469 result);
1467 }
1468bad:
1469 if (hints)
1470 free(hints, M_TEMP);
1471 if (nd.ni_vp != NULL)
1472 vn_close(nd.ni_vp, FREAD, cred, p);
1473 /*
1474 * If nothing found or hints is absent - fallback to the old way

--- 228 unchanged lines hidden ---
1470 }
1471bad:
1472 if (hints)
1473 free(hints, M_TEMP);
1474 if (nd.ni_vp != NULL)
1475 vn_close(nd.ni_vp, FREAD, cred, p);
1476 /*
1477 * If nothing found or hints is absent - fallback to the old way

--- 228 unchanged lines hidden ---