diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2013-07-05 21:33:37 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2013-07-05 21:33:37 +0000 |
commit | 2c6c0cc6f9a1fa70088645c634c08484a7584ec0 (patch) | |
tree | e82af00f372b3baecc0e8ae3d58ea9bb3221a566 | |
parent | e76d867751be2b691abbb7c538b256d11f00fdbe (diff) |
More a.out files leave the party.
-rw-r--r-- | sbin/modload/a.out.c | 209 | ||||
-rw-r--r-- | usr.bin/gprof/aout.c | 220 | ||||
-rw-r--r-- | usr.sbin/config/exec_aout.c | 173 |
3 files changed, 0 insertions, 602 deletions
diff --git a/sbin/modload/a.out.c b/sbin/modload/a.out.c deleted file mode 100644 index 7fe3325c0c2..00000000000 --- a/sbin/modload/a.out.c +++ /dev/null @@ -1,209 +0,0 @@ -/* $OpenBSD: a.out.c,v 1.5 2006/04/02 00:48:35 deraadt Exp $ */ -/* $NetBSD: a.out.c,v 1.1 1999/06/13 12:54:40 mrg Exp $ */ - -/* - * Copyright (c) 1993 Terrence R. Lambert. - * 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 - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Terrence R. Lambert. - * 4. The name Terrence R. Lambert may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY TERRENCE R. LAMBERT ``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 TERRENCE R. LAMBERT 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. - */ - -#include <sys/param.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/ioctl.h> -#include <sys/lkm.h> - -#include <a.out.h> -#include <err.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <fcntl.h> - -#include "modload.h" - -/* - * Expected linker options: - * - * -A executable to link against - * -e entry point - * -o output file - * -T address to link to in hex (assumes it's a page boundry) - * <target> object file - */ - -#define LINKCMD "ld -A %s -e _%s -o %s -T %p %s" - -static struct exec sinfo_buf; /* buffer for loading */ -extern int devfd, modfd; -extern struct lmc_resrv resrv; -extern int symtab; - -void -a_out_linkcmd(char *buf, size_t len, const char *kernel, - const char *entry, const char *outfile, const void *address, - const char *object) -{ - ssize_t n; - - n = snprintf(buf, len, LINKCMD, kernel, entry, - outfile, address, object); - if (n < 0 || n >= len) - errx(1, "link command longer than %lu bytes", (u_long)len); -} - -static int -a_out_read_header(int fd, struct exec *info_buf) -{ - ssize_t n; - - n = read(fd, info_buf, sizeof(*info_buf)); - if (n < 0) - err(1, "failed reading %lu bytes", (u_long)sizeof(*info_buf)); - if (n != sizeof(*info_buf)) { - if (debug) - fprintf(stderr, "failed to read %lu bytes", - (u_long)sizeof(*info_buf)); - return -1; - } - - /* - * Magic number... - */ - if (N_BADMAG(*info_buf)) - errx(4, "not an a.out format file"); - return 0; -} - -int -a_out_mod_sizes(int fd, size_t *modsize, int *strtablen, - struct lmc_resrv *resrvp, struct stat *sp) -{ - struct exec info_buf; - - if (a_out_read_header(fd, &info_buf) < 0) - return -1; - - /* - * Calculate the size of the module - */ - *modsize = info_buf.a_text + info_buf.a_data + info_buf.a_bss; - - *strtablen = sp->st_size - N_STROFF(info_buf); - - if (symtab) { - /* - * XXX TODO: grovel through symbol table looking for - * just the symbol table stuff from the new module, - * and skip the stuff from the kernel. - */ - resrvp->sym_size = info_buf.a_syms + *strtablen; - resrvp->sym_symsize = info_buf.a_syms; - } else - resrvp->sym_size = resrvp->sym_symsize = 0; - - return (0); -} - -void * -a_out_mod_load(int fd) -{ - size_t b; - ssize_t n; - char buf[MODIOBUF]; - - /* - * Get the load module post load size... do this by reading the - * header and doing page counts. - */ - if (a_out_read_header(fd, &sinfo_buf) < 0) - return NULL; - - /* - * Seek to the text offset to start loading... - */ - if (lseek(fd, N_TXTOFF(sinfo_buf), SEEK_SET) == -1) - err(12, "lseek"); - - /* - * Transfer the relinked module to kernel memory in chunks of - * MODIOBUF size at a time. - */ - b = sinfo_buf.a_text + sinfo_buf.a_data; - while (b) { - n = read(fd, buf, MIN(b, sizeof(buf))); - if (n < 0) - err(1, "while reading from prelinked module"); - if (n == 0) - errx(1, "EOF while reading from prelinked module"); - - loadbuf(buf, n); - b -= n; - } - return (void*)sinfo_buf.a_entry; -} - -void -a_out_mod_symload(int strtablen) -{ - struct lmc_loadbuf ldbuf; - char buf[MODIOBUF]; - int bytesleft, sz; - - /* - * Seek to the symbol table to start loading it... - */ - if (lseek(modfd, N_SYMOFF(sinfo_buf), SEEK_SET) == -1) - err(12, "lseek"); - - /* - * we've fixed the symbol table entries, now load them - */ - for (bytesleft = sinfo_buf.a_syms; bytesleft > 0; bytesleft -= sz) { - sz = MIN(bytesleft, MODIOBUF); - if (read(modfd, buf, sz) != sz) - err(14, "read"); - ldbuf.cnt = sz; - ldbuf.data = buf; - if (ioctl(devfd, LMLOADSYMS, &ldbuf) == -1) - err(11, "error transferring sym buffer"); - } - - /* and now read the string table and load it. */ - for (bytesleft = strtablen; bytesleft > 0; bytesleft -= sz) { - sz = MIN(bytesleft, MODIOBUF); - if (read(modfd, buf, sz) != sz) - err(14, "read"); - ldbuf.cnt = sz; - ldbuf.data = buf; - if (ioctl(devfd, LMLOADSYMS, &ldbuf) == -1) - err(11, "error transferring stringtable buffer"); - } -} diff --git a/usr.bin/gprof/aout.c b/usr.bin/gprof/aout.c deleted file mode 100644 index 0b7deabe1b3..00000000000 --- a/usr.bin/gprof/aout.c +++ /dev/null @@ -1,220 +0,0 @@ -/*- - * Copyright (c) 1983, 1993 - * The Regents of the University of California. 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 - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. - */ - -#include <sys/types.h> -#include <a.out.h> - -#include "gprof.h" - -static void getstrtab(FILE *, const char *); -static void getsymtab(FILE *, const char *); -static void gettextspace(FILE *); -static bool funcsymbol(struct nlist *); - -static char *strtab; /* string table in core */ -static long ssiz; /* size of the string table */ -static struct exec xbuf; /* exec header of a.out */ - -/* Things which get -E excluded by default. */ -static char *excludes[] = { "mcount", "__mcleanup", NULL }; - -/* - * Set up string and symbol tables from a.out. - * and optionally the text space. - * On return symbol table is sorted by value. - * - * Returns 0 on success, -1 on failure. - */ -int -getnfile(const char *filename, char ***defaultEs) -{ - FILE *nfile; - - nfile = fopen( filename ,"r"); - if (nfile == NULL) - err(1, "fopen: %s", filename); - - fread(&xbuf, 1, sizeof(xbuf), nfile); - if (N_BADMAG(xbuf)) { - /* Bail out and let other binary formats try. */ - fclose(nfile); - return (-1); - } - getstrtab(nfile, filename); - getsymtab(nfile, filename); - gettextspace(nfile); - fclose(nfile); -#ifdef DEBUG - if (debug & AOUTDEBUG) { - int j; - - for (j = 0; j < nname; j++) { - printf("[getnfile] 0X%08lx\t%s\n", nl[j].value, - nl[j].name); - } - } -#endif - *defaultEs = excludes; - return (0); -} - -static void -getstrtab(FILE *nfile, const char *filename) -{ - fseek(nfile, (long)(N_SYMOFF(xbuf) + xbuf.a_syms), SEEK_SET); - if (fread(&ssiz, sizeof (ssiz), 1, nfile) == 0) - errx(1, "%s: no string table (old format?)" , filename ); - strtab = calloc(ssiz, 1); - if (strtab == NULL) - errx(1, "%s: no room for %d bytes of string table", filename, - ssiz); - if (fread(strtab + sizeof(ssiz), ssiz - sizeof(ssiz), 1, nfile) != 1) - errx(1, "%s: error reading string table", filename ); -} - -/* - * Read in symbol table - */ -static void -getsymtab(FILE *nfile, const char *filename) -{ - struct nlist nbuf; - int askfor; - long i; - - /* pass1 - count symbols */ - fseek(nfile, (long)N_SYMOFF(xbuf), SEEK_SET); - nname = 0; - for (i = xbuf.a_syms; i > 0; i -= sizeof(struct nlist)) { - fread(&nbuf, sizeof(nbuf), 1, nfile); - if (funcsymbol(&nbuf)) - nname++; - } - if (nname == 0) - errx(1, "%s: no symbols", filename); - - askfor = nname + 1; - nl = calloc(askfor , sizeof(nltype)); - if (nl == 0) - errx(1, "No room for %d bytes of symbol table", - askfor * sizeof(nltype)); - - /* pass2 - read symbols */ - fseek(nfile, (long)N_SYMOFF(xbuf), SEEK_SET); - npe = nl; - nname = 0; - for (i = xbuf.a_syms; i > 0; i -= sizeof(struct nlist)) { - fread(&nbuf, sizeof(nbuf), 1, nfile); - if (!funcsymbol(&nbuf)) { -#ifdef DEBUG - if (debug & AOUTDEBUG) { - printf("[getsymtab] rejecting: 0x%x %s\n", - nbuf.n_type, strtab + nbuf.n_un.n_strx); - } -#endif - continue; - } - npe->value = nbuf.n_value; - npe->name = strtab + nbuf.n_un.n_strx; -#ifdef DEBUG - if (debug & AOUTDEBUG) { - printf("[getsymtab] %d %s 0x%08lx\n", - nname, npe->name, npe->value); - } -#endif - npe++; - nname++; - } - npe->value = -1; -} - -/* - * read in the text space of an a.out file - */ -static void -gettextspace(FILE *nfile) -{ - if (cflag == 0) - return; - textspace = malloc(xbuf.a_text); - if (textspace == 0) { - warnx("ran out room for %d bytes of text space: can't do -c" , - xbuf.a_text); - return; - } - (void)fseek(nfile, N_TXTOFF(xbuf), SEEK_SET); - if (fread(textspace, 1, xbuf.a_text, nfile) != xbuf.a_text ) { - warnx("couldn't read text space: can't do -c"); - free(textspace); - textspace = 0; - return; - } -} - -static bool -funcsymbol(struct nlist *nlistp) -{ - char *name, c; - - /* - * must be a text symbol, - * and static text symbols don't qualify if aflag set. - */ - if (!((nlistp->n_type == (N_TEXT|N_EXT)) - || ((nlistp->n_type == N_TEXT) && (aflag == 0)))) - return FALSE; - - /* - * name must start with an underscore if uflag is set. - * can't have any `funny' characters in name, - * where `funny' means `.' (.o file names) - * need to make an exception for sparc .mul & co. - * perhaps we should just drop this code entirely... - */ - name = strtab + nlistp -> n_un.n_strx; -#ifdef sparc - if (nlistp -> n_value & 3) - return (FALSE); - if (*name == '.') { - char *p = name + 1; - if (*p == 'u') - p++; - if (strcmp(p, "mul") == 0 || strcmp(p, "div") == 0 || - strcmp(p, "rem") == 0 ) - return (TRUE); - } -#endif - while (c = *name++) { - if (c == '.') { - return (FALSE); - } - } - - return (TRUE); -} diff --git a/usr.sbin/config/exec_aout.c b/usr.sbin/config/exec_aout.c deleted file mode 100644 index 5641d0a6329..00000000000 --- a/usr.sbin/config/exec_aout.c +++ /dev/null @@ -1,173 +0,0 @@ -/* $OpenBSD: exec_aout.c,v 1.11 2011/10/02 22:20:49 edd Exp $ */ - -/* - * Copyright (c) 1999 Mats O Jansson. 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 - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. - */ - -#include <sys/types.h> -#include <sys/exec.h> - -#include <err.h> -#include <errno.h> -#include <fcntl.h> -#include <nlist.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> - -#include "config.h" -#include "ukc.h" - -caddr_t aout_p, aout_r; -unsigned long aout_psz = 0, aout_rsz = 0; -struct exec aout_ex; -unsigned long aout_adjvalue = 0; -unsigned long aout_datashift = 0; - -void -aout_computeadj(void) -{ - aout_adjvalue = (unsigned long)aout_p + - N_TXTOFF(aout_ex) - nl[P_KERNEL_TEXT].n_value; - - /* - * On m68k a.out ZMAGIC kernel, kernel_text begins _after_ the a.out - * header, so compensate for it. - */ - if (nl[P_KERNEL_TEXT].n_value & (__LDPGSZ - 1)) - aout_adjvalue += sizeof(aout_ex); - - /* - * On NMAGIC kernel, we need an extra relocation for the data area - */ - aout_datashift = (N_DATADDR(aout_ex) - N_TXTADDR(aout_ex)) - - aout_ex.a_text; -} - -/* ``kernel'' vaddr -> in-memory address */ -caddr_t -aout_adjust(caddr_t x) -{ - - if (aout_adjvalue == 0) - aout_computeadj(); - - if (aout_datashift != 0 && - (unsigned long)x >= N_DATADDR(aout_ex) - N_TXTADDR(aout_ex)) - x -= aout_datashift; - - return (x + aout_adjvalue); -} - -/* in-memory address -> ``kernel'' vaddr */ -caddr_t -aout_readjust(caddr_t x) -{ - caddr_t y; - -#if 0 /* unnecessary, aout_adjust() is always invoked first */ - if (aout_adjvalue == 0) - aout_computeadj(); -#endif - - y = x - aout_adjvalue; - if (aout_datashift != 0 && - (unsigned long)y >= N_TXTADDR(aout_ex) + aout_ex.a_text) - y += aout_datashift; - - return (y); -} - -int -aout_check(char *file) -{ - int fd, ret = 1; - - if ((fd = open(file, O_RDONLY | O_EXLOCK, 0)) < 0) - return (0); - if (read(fd, (char *)&aout_ex, sizeof(aout_ex)) != sizeof(aout_ex)) - ret = 0; - if (ret) { - if (N_BADMAG(aout_ex)) - ret = 0; - } - - close(fd); - return (ret); -} - -void -aout_loadkernel(char *file) -{ - int fd; - off_t cur, end; - - if ((fd = open(file, O_RDONLY | O_EXLOCK, 0)) < 0) - err(1, "%s", file); - - if (read(fd, (char *)&aout_ex, sizeof(aout_ex)) != sizeof(aout_ex)) - errx(1, "can't read a.out header"); - - if (N_BADMAG(aout_ex)) - errx(1, "bad a.out magic"); - - lseek(fd, (off_t)0, SEEK_SET); - - aout_psz = (int)(aout_ex.a_text + N_TXTOFF(aout_ex) + - aout_ex.a_data); - - aout_p = emalloc(aout_psz); - - if (read(fd, aout_p, aout_psz) != aout_psz) - errx(1, "can't read a.out text and data"); - - cur = lseek(fd, (off_t)0, SEEK_CUR); - end = lseek(fd, (off_t)0, SEEK_END); - (void)lseek(fd, cur, SEEK_SET); - - aout_rsz = (int)(end - cur); - - aout_r = emalloc(aout_rsz); - - if (read(fd, aout_r, aout_rsz) != aout_rsz) - errx(1, "can't read rest of file %s", file); - - close(fd); -} - -void -aout_savekernel(char *outfile) -{ - int fd; - - if ((fd = open(outfile, O_WRONLY | O_CREAT | O_TRUNC, 0755)) < 0) - err(1, "%s", outfile); - - if (write(fd, aout_p, aout_psz) != aout_psz) - errx(1, "can't write a.out text and data"); - - if (write(fd, aout_r, aout_rsz) != aout_rsz) - errx(1, "can't write rest of file %s", outfile); - - close(fd); -} |