Date: Wed, 19 Apr 2006 12:35:11 GMT From: John Birrell <jb@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 95590 for review Message-ID: <200604191235.k3JCZBj5027319@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200604191235.k3JCZBj5027319>