kern_linker.c (109605) | kern_linker.c (109623) |
---|---|
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 109605 2003-01-21 02:42:44Z jake $ | 26 * $FreeBSD: head/sys/kern/kern_linker.c 109623 2003-01-21 08:56:16Z alfred $ |
27 */ 28 29#include "opt_ddb.h" 30#include "opt_mac.h" 31 32#include <sys/param.h> 33#include <sys/kernel.h> 34#include <sys/systm.h> --- 70 unchanged lines hidden (view full) --- 105static modlist_t modlist_lookup2(const char *name, 106 struct mod_depend *verinfo); 107 108static char * 109linker_strdup(const char *str) 110{ 111 char *result; 112 | 27 */ 28 29#include "opt_ddb.h" 30#include "opt_mac.h" 31 32#include <sys/param.h> 33#include <sys/kernel.h> 34#include <sys/systm.h> --- 70 unchanged lines hidden (view full) --- 105static modlist_t modlist_lookup2(const char *name, 106 struct mod_depend *verinfo); 107 108static char * 109linker_strdup(const char *str) 110{ 111 char *result; 112 |
113 if ((result = malloc((strlen(str) + 1), M_LINKER, M_WAITOK)) != NULL) | 113 if ((result = malloc((strlen(str) + 1), M_LINKER, 0)) != NULL) |
114 strcpy(result, str); 115 return (result); 116} 117 118static void 119linker_init(void *arg) 120{ 121 --- 275 unchanged lines hidden (view full) --- 397} 398 399linker_file_t 400linker_find_file_by_name(const char *filename) 401{ 402 linker_file_t lf = 0; 403 char *koname; 404 | 114 strcpy(result, str); 115 return (result); 116} 117 118static void 119linker_init(void *arg) 120{ 121 --- 275 unchanged lines hidden (view full) --- 397} 398 399linker_file_t 400linker_find_file_by_name(const char *filename) 401{ 402 linker_file_t lf = 0; 403 char *koname; 404 |
405 koname = malloc(strlen(filename) + 4, M_LINKER, M_WAITOK); | 405 koname = malloc(strlen(filename) + 4, M_LINKER, 0); |
406 if (koname == NULL) 407 goto out; 408 sprintf(koname, "%s.ko", filename); 409 410 mtx_lock(&kld_mtx); 411 TAILQ_FOREACH(lf, &linker_files, link) { 412 if (strcmp(lf->filename, koname) == 0) 413 break; --- 25 unchanged lines hidden (view full) --- 439{ 440 linker_file_t lf; 441 const char *filename; 442 443 lf = NULL; 444 filename = linker_basename(pathname); 445 446 KLD_DPF(FILE, ("linker_make_file: new file, filename=%s\n", filename)); | 406 if (koname == NULL) 407 goto out; 408 sprintf(koname, "%s.ko", filename); 409 410 mtx_lock(&kld_mtx); 411 TAILQ_FOREACH(lf, &linker_files, link) { 412 if (strcmp(lf->filename, koname) == 0) 413 break; --- 25 unchanged lines hidden (view full) --- 439{ 440 linker_file_t lf; 441 const char *filename; 442 443 lf = NULL; 444 filename = linker_basename(pathname); 445 446 KLD_DPF(FILE, ("linker_make_file: new file, filename=%s\n", filename)); |
447 lf = (linker_file_t)kobj_create((kobj_class_t)lc, M_LINKER, M_WAITOK); | 447 lf = (linker_file_t)kobj_create((kobj_class_t)lc, M_LINKER, 0); |
448 if (lf == NULL) 449 goto out; 450 lf->refs = 1; 451 lf->userrefs = 0; 452 lf->flags = 0; 453 lf->filename = linker_strdup(filename); 454 LINKER_GET_NEXT_FILE_ID(lf->id); 455 lf->ndeps = 0; --- 97 unchanged lines hidden (view full) --- 553} 554 555int 556linker_file_add_dependency(linker_file_t file, linker_file_t dep) 557{ 558 linker_file_t *newdeps; 559 560 newdeps = malloc((file->ndeps + 1) * sizeof(linker_file_t *), | 448 if (lf == NULL) 449 goto out; 450 lf->refs = 1; 451 lf->userrefs = 0; 452 lf->flags = 0; 453 lf->filename = linker_strdup(filename); 454 LINKER_GET_NEXT_FILE_ID(lf->id); 455 lf->ndeps = 0; --- 97 unchanged lines hidden (view full) --- 553} 554 555int 556linker_file_add_dependency(linker_file_t file, linker_file_t dep) 557{ 558 linker_file_t *newdeps; 559 560 newdeps = malloc((file->ndeps + 1) * sizeof(linker_file_t *), |
561 M_LINKER, M_WAITOK | M_ZERO); | 561 M_LINKER, M_ZERO); |
562 if (newdeps == NULL) 563 return (ENOMEM); 564 565 if (file->deps) { 566 bcopy(file->deps, newdeps, 567 file->ndeps * sizeof(linker_file_t *)); 568 free(file->deps, M_LINKER); 569 } --- 69 unchanged lines hidden (view full) --- 639 } 640 } 641 /* 642 * Round the symbol size up to align. 643 */ 644 common_size = (common_size + sizeof(int) - 1) & -sizeof(int); 645 cp = malloc(sizeof(struct common_symbol) 646 + common_size + strlen(name) + 1, M_LINKER, | 562 if (newdeps == NULL) 563 return (ENOMEM); 564 565 if (file->deps) { 566 bcopy(file->deps, newdeps, 567 file->ndeps * sizeof(linker_file_t *)); 568 free(file->deps, M_LINKER); 569 } --- 69 unchanged lines hidden (view full) --- 639 } 640 } 641 /* 642 * Round the symbol size up to align. 643 */ 644 common_size = (common_size + sizeof(int) - 1) & -sizeof(int); 645 cp = malloc(sizeof(struct common_symbol) 646 + common_size + strlen(name) + 1, M_LINKER, |
647 M_WAITOK | M_ZERO); | 647 M_ZERO); |
648 if (cp == NULL) { 649 KLD_DPF(SYM, ("linker_file_lookup_symbol: nomem\n")); 650 return (0); 651 } 652 cp->address = (caddr_t)(cp + 1); 653 cp->name = cp->address + common_size; 654 strcpy(cp->name, name); 655 bzero(cp->address, common_size); --- 92 unchanged lines hidden (view full) --- 748 mtx_lock(&Giant); 749 750 if ((error = securelevel_gt(td->td_ucred, 0)) != 0) 751 goto out; 752 753 if ((error = suser(td)) != 0) 754 goto out; 755 | 648 if (cp == NULL) { 649 KLD_DPF(SYM, ("linker_file_lookup_symbol: nomem\n")); 650 return (0); 651 } 652 cp->address = (caddr_t)(cp + 1); 653 cp->name = cp->address + common_size; 654 strcpy(cp->name, name); 655 bzero(cp->address, common_size); --- 92 unchanged lines hidden (view full) --- 748 mtx_lock(&Giant); 749 750 if ((error = securelevel_gt(td->td_ucred, 0)) != 0) 751 goto out; 752 753 if ((error = suser(td)) != 0) 754 goto out; 755 |
756 pathname = malloc(MAXPATHLEN, M_TEMP, M_WAITOK); | 756 pathname = malloc(MAXPATHLEN, M_TEMP, 0); |
757 if ((error = copyinstr(uap->file, pathname, MAXPATHLEN, NULL)) != 0) 758 goto out; 759 760 /* 761 * If path do not contain qualified name or any dot in it 762 * (kldname.ko, or kldname.ver.ko) treat it as interface 763 * name. 764 */ --- 69 unchanged lines hidden (view full) --- 834 error = mac_check_kld_stat(td->td_ucred); 835 if (error) 836 return (error); 837#endif 838 839 mtx_lock(&Giant); 840 td->td_retval[0] = -1; 841 | 757 if ((error = copyinstr(uap->file, pathname, MAXPATHLEN, NULL)) != 0) 758 goto out; 759 760 /* 761 * If path do not contain qualified name or any dot in it 762 * (kldname.ko, or kldname.ver.ko) treat it as interface 763 * name. 764 */ --- 69 unchanged lines hidden (view full) --- 834 error = mac_check_kld_stat(td->td_ucred); 835 if (error) 836 return (error); 837#endif 838 839 mtx_lock(&Giant); 840 td->td_retval[0] = -1; 841 |
842 pathname = malloc(MAXPATHLEN, M_TEMP, M_WAITOK); | 842 pathname = malloc(MAXPATHLEN, M_TEMP, 0); |
843 if ((error = copyinstr(uap->file, pathname, MAXPATHLEN, NULL)) != 0) 844 goto out; 845 846 filename = linker_basename(pathname); 847 lf = linker_find_file_by_name(filename); 848 if (lf) 849 td->td_retval[0] = lf->id; 850 else --- 155 unchanged lines hidden (view full) --- 1006 1007 if ((error = copyin(uap->data, &lookup, sizeof(lookup))) != 0) 1008 goto out; 1009 if (lookup.version != sizeof(lookup) || 1010 uap->cmd != KLDSYM_LOOKUP) { 1011 error = EINVAL; 1012 goto out; 1013 } | 843 if ((error = copyinstr(uap->file, pathname, MAXPATHLEN, NULL)) != 0) 844 goto out; 845 846 filename = linker_basename(pathname); 847 lf = linker_find_file_by_name(filename); 848 if (lf) 849 td->td_retval[0] = lf->id; 850 else --- 155 unchanged lines hidden (view full) --- 1006 1007 if ((error = copyin(uap->data, &lookup, sizeof(lookup))) != 0) 1008 goto out; 1009 if (lookup.version != sizeof(lookup) || 1010 uap->cmd != KLDSYM_LOOKUP) { 1011 error = EINVAL; 1012 goto out; 1013 } |
1014 symstr = malloc(MAXPATHLEN, M_TEMP, M_WAITOK); | 1014 symstr = malloc(MAXPATHLEN, M_TEMP, 0); |
1015 if ((error = copyinstr(lookup.symname, symstr, MAXPATHLEN, NULL)) != 0) 1016 goto out; 1017 if (uap->fileid != 0) { 1018 lf = linker_find_file_by_id(uap->fileid); 1019 if (lf == NULL) { 1020 error = ENOENT; 1021 goto out; 1022 } --- 353 unchanged lines hidden (view full) --- 1376 len = strlen(*cpp); 1377 if (len > extlen) 1378 extlen = len; 1379 } 1380 extlen++; /* trailing '\0' */ 1381 sep = (path[pathlen - 1] != '/') ? "/" : ""; 1382 1383 reclen = pathlen + strlen(sep) + namelen + extlen + 1; | 1015 if ((error = copyinstr(lookup.symname, symstr, MAXPATHLEN, NULL)) != 0) 1016 goto out; 1017 if (uap->fileid != 0) { 1018 lf = linker_find_file_by_id(uap->fileid); 1019 if (lf == NULL) { 1020 error = ENOENT; 1021 goto out; 1022 } --- 353 unchanged lines hidden (view full) --- 1376 len = strlen(*cpp); 1377 if (len > extlen) 1378 extlen = len; 1379 } 1380 extlen++; /* trailing '\0' */ 1381 sep = (path[pathlen - 1] != '/') ? "/" : ""; 1382 1383 reclen = pathlen + strlen(sep) + namelen + extlen + 1; |
1384 result = malloc(reclen, M_LINKER, M_WAITOK); | 1384 result = malloc(reclen, M_LINKER, 0); |
1385 for (cpp = linker_ext_list; *cpp; cpp++) { 1386 snprintf(result, reclen, "%.*s%s%.*s%s", pathlen, path, sep, 1387 namelen, name, *cpp); 1388 /* 1389 * Attempt to open the file, and return the path if 1390 * we succeed and it's a regular file. 1391 */ 1392 NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, result, td); --- 35 unchanged lines hidden (view full) --- 1428 int error, ival, bestver, *intp, reclen, found, flags, clen, blen; 1429 1430 result = NULL; 1431 bestver = found = 0; 1432 1433 sep = (path[pathlen - 1] != '/') ? "/" : ""; 1434 reclen = imax(modnamelen, strlen(linker_hintfile)) + pathlen + 1435 strlen(sep) + 1; | 1385 for (cpp = linker_ext_list; *cpp; cpp++) { 1386 snprintf(result, reclen, "%.*s%s%.*s%s", pathlen, path, sep, 1387 namelen, name, *cpp); 1388 /* 1389 * Attempt to open the file, and return the path if 1390 * we succeed and it's a regular file. 1391 */ 1392 NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, result, td); --- 35 unchanged lines hidden (view full) --- 1428 int error, ival, bestver, *intp, reclen, found, flags, clen, blen; 1429 1430 result = NULL; 1431 bestver = found = 0; 1432 1433 sep = (path[pathlen - 1] != '/') ? "/" : ""; 1434 reclen = imax(modnamelen, strlen(linker_hintfile)) + pathlen + 1435 strlen(sep) + 1; |
1436 pathbuf = malloc(reclen, M_LINKER, M_WAITOK); | 1436 pathbuf = malloc(reclen, M_LINKER, 0); |
1437 snprintf(pathbuf, reclen, "%.*s%s%s", pathlen, path, sep, 1438 linker_hintfile); 1439 1440 NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, pathbuf, td); 1441 flags = FREAD; 1442 error = vn_open(&nd, &flags, 0); 1443 if (error) 1444 goto bad; --- 6 unchanged lines hidden (view full) --- 1451 goto bad; 1452 /* 1453 * XXX: we need to limit this number to some reasonable value 1454 */ 1455 if (vattr.va_size > 100 * 1024) { 1456 printf("hints file too large %ld\n", (long)vattr.va_size); 1457 goto bad; 1458 } | 1437 snprintf(pathbuf, reclen, "%.*s%s%s", pathlen, path, sep, 1438 linker_hintfile); 1439 1440 NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, pathbuf, td); 1441 flags = FREAD; 1442 error = vn_open(&nd, &flags, 0); 1443 if (error) 1444 goto bad; --- 6 unchanged lines hidden (view full) --- 1451 goto bad; 1452 /* 1453 * XXX: we need to limit this number to some reasonable value 1454 */ 1455 if (vattr.va_size > 100 * 1024) { 1456 printf("hints file too large %ld\n", (long)vattr.va_size); 1457 goto bad; 1458 } |
1459 hints = malloc(vattr.va_size, M_TEMP, M_WAITOK); | 1459 hints = malloc(vattr.va_size, M_TEMP, 0); |
1460 if (hints == NULL) 1461 goto bad; 1462 error = vn_rdwr(UIO_READ, nd.ni_vp, (caddr_t)hints, vattr.va_size, 0, 1463 UIO_SYSSPACE, IO_NODELOCKED, cred, NOCRED, &reclen, td); 1464 if (error) 1465 goto bad; 1466 VOP_UNLOCK(nd.ni_vp, 0, td); 1467 vn_close(nd.ni_vp, FREAD, cred, td); --- 346 unchanged lines hidden --- | 1460 if (hints == NULL) 1461 goto bad; 1462 error = vn_rdwr(UIO_READ, nd.ni_vp, (caddr_t)hints, vattr.va_size, 0, 1463 UIO_SYSSPACE, IO_NODELOCKED, cred, NOCRED, &reclen, td); 1464 if (error) 1465 goto bad; 1466 VOP_UNLOCK(nd.ni_vp, 0, td); 1467 vn_close(nd.ni_vp, FREAD, cred, td); --- 346 unchanged lines hidden --- |