From owner-p4-projects@FreeBSD.ORG Wed Apr 19 12:35:12 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 0FFC616A40A; Wed, 19 Apr 2006 12:35:12 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A96E316A408 for ; Wed, 19 Apr 2006 12:35:11 +0000 (UTC) (envelope-from jb@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6B24F43D46 for ; Wed, 19 Apr 2006 12:35:11 +0000 (GMT) (envelope-from jb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id k3JCZBlU027322 for ; Wed, 19 Apr 2006 12:35:11 GMT (envelope-from jb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id k3JCZBj5027319 for perforce@freebsd.org; Wed, 19 Apr 2006 12:35:11 GMT (envelope-from jb@freebsd.org) Date: Wed, 19 Apr 2006 12:35:11 GMT Message-Id: <200604191235.k3JCZBj5027319@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jb@freebsd.org using -f From: John Birrell To: Perforce Change Reviews Cc: Subject: PERFORCE change 95590 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Apr 2006 12:35:12 -0000 http://perforce.freebsd.org/chv.cgi?CH=95590 Change 95590 by jb@jb_freebsd2 on 2006/04/19 12:35:07 When creating a linker file object, remember the full path name to the file so that it can be listed via kldstat. This change makes a new version (identified by the kld_file_stat structure size) which is backward compatible with the first version of the structure. Our policy is that kernels are backward compatible and that an old 'world' should work on a new kernel. The reverse is not true. This change is needed because dtrace(1) needs to know *exactly* which file was used to load each module. I also think it's poor form to just list the base module file name in kldstat(1) when we could, and some of us do, load modules from all over the place, not just from the /boot/kernel directory. Affected files ... .. //depot/projects/dtrace/src/sys/kern/kern_linker.c#2 edit .. //depot/projects/dtrace/src/sys/sys/linker.h#2 edit Differences ... ==== //depot/projects/dtrace/src/sys/kern/kern_linker.c#2 (text+ko) ==== @@ -459,7 +459,7 @@ lf = NULL; filename = linker_basename(pathname); - KLD_DPF(FILE, ("linker_make_file: new file, filename=%s\n", filename)); + KLD_DPF(FILE, ("linker_make_file: new file, filename='%s' for pathname='%s'\n", filename, pathname)); lf = (linker_file_t)kobj_create((kobj_class_t)lc, M_LINKER, M_WAITOK); if (lf == NULL) goto out; @@ -467,6 +467,7 @@ lf->userrefs = 0; lf->flags = 0; lf->filename = linker_strdup(filename); + lf->pathname = linker_strdup(pathname); LINKER_GET_NEXT_FILE_ID(lf->id); lf->ndeps = 0; lf->deps = NULL; @@ -565,6 +566,10 @@ free(file->filename, M_LINKER); file->filename = NULL; } + if (file->pathname) { + free(file->pathname, M_LINKER); + file->pathname = NULL; + } kobj_delete((kobj_t) file, M_LINKER); out: return (error); @@ -969,6 +974,7 @@ linker_file_t lf; int error = 0; int namelen, version; + int version_num = 1; struct kld_file_stat *stat; #ifdef MAC @@ -991,10 +997,16 @@ */ if ((error = copyin(&stat->version, &version, sizeof(version))) != 0) goto out; - if (version != sizeof(struct kld_file_stat)) { + if (version == sizeof(struct kld_file_stat_1)) + version_num = 1; + else if (version == sizeof(struct kld_file_stat)) + version_num = 2; + else { error = EINVAL; goto out; } + + /* Version 1 fields: */ namelen = strlen(lf->filename) + 1; if (namelen > MAXPATHLEN) namelen = MAXPATHLEN; @@ -1009,7 +1021,17 @@ goto out; if ((error = copyout(&lf->size, &stat->size, sizeof(size_t))) != 0) goto out; + if (version_num < 2) + goto done; + /* Version 2 fields: */ + namelen = strlen(lf->pathname) + 1; + if (namelen > MAXPATHLEN) + namelen = MAXPATHLEN; + if ((error = copyout(lf->pathname, &stat->pathname[0], namelen)) != 0) + goto out; + +done: td->td_retval[0] = 0; out: mtx_unlock(&Giant); ==== //depot/projects/dtrace/src/sys/sys/linker.h#2 (text+ko) ==== @@ -73,6 +73,7 @@ #define LINKER_FILE_LINKED 0x1 /* file has been fully linked */ TAILQ_ENTRY(linker_file) link; /* list of all loaded files */ char* filename; /* file which was loaded */ + char* pathname; /* file name with full path */ int id; /* unique id */ caddr_t address; /* load address */ size_t size; /* size of file */ @@ -260,6 +261,18 @@ #define ELF_RELOC_REL 1 #define ELF_RELOC_RELA 2 +/* + * This is version 1 of the KLD file status structure. It is identified + * by it's _size_ in the version field. + */ +struct kld_file_stat_1 { + int version; /* set to sizeof(linker_file_stat) */ + char name[MAXPATHLEN]; + int refs; + int id; + caddr_t address; /* load address */ + size_t size; /* size in bytes */ +}; #endif /* _KERNEL */ struct kld_file_stat { @@ -269,6 +282,7 @@ int id; caddr_t address; /* load address */ size_t size; /* size in bytes */ + char pathname[MAXPATHLEN]; }; struct kld_sym_lookup {