/*-
* Copyright (c) 2004 Ian Dowse <iedowse@freebsd.org>
* Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
* Copyright (c) 1998 Peter Wemm <peter@freebsd.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
__FBSDID("$FreeBSD$");
#include <inttypes.h>
#include <string.h>
#include <stand.h>
#define FREEBSD_ELF
#include <link.h>
#include "bootstrap.h"
#endif
typedef struct elf_file {
int fd;
} *elf_file_t;
elf_file_t ef);
/*
* Attempt to load the file (file) as an ELF module. It will be stored at
* (dest), and a pointer to a module structure describing the loaded object
* will be saved in (result).
*/
int
struct preloaded_file **result)
{
int err;
/*
* Open the image, read and validate the ELF header
*/
return(EFTYPE);
return(errno);
if (bytes_read != sizeof(*hdr)) {
goto oerr;
}
/* Is it ELF? */
goto oerr;
}
goto oerr;
}
goto oerr;
}
"_obj_loadfile: can't load module before kernel\n");
goto oerr;
}
else
/*
* Ok, we think we should handle this.
*/
fp = file_alloc();
"_obj_loadfile: cannot allocate module info\n");
goto out;
}
goto ioerr;
/* save exec header as metadata */
/* Load OK, return module pointer */
err = 0;
goto out;
oerr:
out:
return(err);
}
/*
* With the file (fd) open on the image, and (ehdr) containing
* the Elf header, load the image at (off)
*/
static int
{
ret = 0;
/* Read in the section headers. */
"_obj_loadimage: read section headers failed\n");
goto out;
}
/*
* Decide where to load everything, but don't read it yet.
* We store the load address as a non-zero sh_addr value.
*/
continue;
case SHT_PROGBITS:
case SHT_NOBITS:
break;
}
}
/* Symbols. */
nsym = 0;
case SHT_SYMTAB:
nsym++;
ef->symtabindex = i;
break;
}
}
if (nsym != 1) {
"_obj_loadimage: file has no valid symbol table\n");
goto out;
}
"_obj_loadimage: file has invalid symbol strings\n");
goto out;
}
/* Section names. */
"_obj_loadimage: file has no section names\n");
goto out;
}
/* Relocation tables. */
case SHT_REL:
case SHT_RELA:
break;
}
}
/* Clear the whole area, including bss regions. */
/* Figure section with the lowest file offset we haven't loaded yet. */
{
/*
* Find next section to load. The complexity of this loop is
* O(n^2), but with the number of sections being typically
* small, we do not care.
*/
continue;
/* Skip sections that were loaded already. */
continue;
/* Find section with smallest offset. */
}
break;
"_obj_loadimage: read failed\n");
goto out;
}
}
if (res != 0)
goto out;
out:
printf("\n");
return ret;
}
struct mod_metadata64 {
};
#endif
int
{
#endif
char *s;
&modcnt) != 0)
return 0;
modcnt = 0;
while (p < p_stop) {
COPYOUT(p, &v, sizeof(v));
if (error != 0)
return (error);
if (error != 0)
return (error);
#else
if (error != 0)
return (error);
#endif
p += sizeof(Elf_Addr);
case MDT_DEPEND:
return ENOMEM;
sizeof(*mdepend));
free(s);
mdepend);
break;
case MDT_VERSION:
free(s);
modcnt++;
break;
case MDT_MODULE:
case MDT_PNP_INFO:
break;
default:
break;
}
}
return 0;
}
static int
{
char *p;
int i;
continue;
continue;
free(p);
return (0);
}
free(p);
}
return (ESRCH);
}
/*
* Apply any intra-module relocations to the value. p is the load address
* the image in-place, because this is done by kern_linker later on.
*/
static int
{
(void)mp;
continue;
continue;
continue;
case SHT_RELA:
for (j = 0; j < nrela; j++) {
if (error != 0)
return (error);
}
break;
case SHT_REL:
for (j = 0; j < nrel; j++) {
if (error != 0)
return (error);
}
break;
}
}
return (0);
}
/* Look up the address of a specified symbol. */
static Elf_Addr
{
return (0);
return (0);
if (base == 0)
return (0);
}