PERFORCE change 50016 for review
Peter Wemm
peter at FreeBSD.org
Tue Mar 30 15:15:47 PST 2004
http://perforce.freebsd.org/chv.cgi?CH=50016
Change 50016 by peter at peter_daintree on 2004/03/30 15:14:48
Dont waste a whole page for the elf header. There is
nothing in close proximity anymore that makes it worth
it anymore.
Affected files ...
.. //depot/projects/hammer/sys/kern/link_elf_obj.c#11 edit
Differences ...
==== //depot/projects/hammer/sys/kern/link_elf_obj.c#11 (text+ko) ====
@@ -143,9 +143,9 @@
static struct linker_class link_elf_class = {
#if ELF_TARG_CLASS == ELFCLASS32
- "elf32",
+ "elf32_obj",
#else
- "elf64",
+ "elf64_obj",
#endif
link_elf_methods, sizeof(struct elf_file)
};
@@ -165,18 +165,20 @@
linker_add_class(&link_elf_class);
}
-SYSINIT(link_elf, SI_SUB_KLD, SI_ORDER_SECOND, link_elf_init, 0);
+SYSINIT(link_elf_obj, SI_SUB_KLD, SI_ORDER_SECOND, link_elf_init, 0);
static int
link_elf_link_preload(linker_class_t cls, const char *filename,
linker_file_t *result)
{
+ /* preload not done this way */
return (EFTYPE);
}
static int
link_elf_link_preload_finish(linker_file_t lf)
{
+ /* preload not done this way */
return (EFTYPE);
}
@@ -187,7 +189,6 @@
struct nameidata nd;
struct thread *td = curthread; /* XXX */
Elf_Ehdr *hdr;
- caddr_t firstpage;
int nbytes, i;
caddr_t mapbase;
size_t mapsize;
@@ -207,6 +208,7 @@
shdr = NULL;
lf = NULL;
mapsize = 0;
+ hdr = NULL;
NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, filename, td);
flags = FREAD;
@@ -217,27 +219,22 @@
#ifdef MAC
error = mac_check_kld_load(curthread->td_ucred, nd.ni_vp);
if (error) {
- firstpage = NULL;
goto out;
}
#endif
- /*
- * Read the elf header from the file.
- */
- firstpage = malloc(PAGE_SIZE, M_LINKER, M_WAITOK);
- if (firstpage == NULL) {
+ /* Read the elf header from the file. */
+ hdr = malloc(sizeof(Elf_Ehdr *), M_LINKER, M_WAITOK);
+ if (hdr == NULL) {
error = ENOMEM;
goto out;
}
- hdr = (Elf_Ehdr *)firstpage;
- error = vn_rdwr(UIO_READ, nd.ni_vp, firstpage, PAGE_SIZE, 0,
+ error = vn_rdwr(UIO_READ, nd.ni_vp, hdr, PAGE_SIZE, 0,
UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
&resid, td);
- nbytes = PAGE_SIZE - resid;
if (error)
goto out;
- if (nbytes < sizeof(Elf_Ehdr)){
+ if (resid != 0){
error = ENOEXEC;
goto out;
}
@@ -523,8 +520,8 @@
linker_file_unload(lf);
if (shdr)
free(shdr, M_LINKER);
- if (firstpage)
- free(firstpage, M_LINKER);
+ if (hdr)
+ free(hdr, M_LINKER);
VOP_UNLOCK(nd.ni_vp, 0, td);
vn_close(nd.ni_vp, FREAD, td->td_ucred, td);
More information about the p4-projects
mailing list