summaryrefslogtreecommitdiff
path: root/sbin/modload
diff options
context:
space:
mode:
authorad <ad@NetBSD.org>2008-11-12 12:35:50 +0000
committerad <ad@NetBSD.org>2008-11-12 12:35:50 +0000
commit0efea177e37295fed654875d875160c47500d6bd (patch)
tree9d0589344a5d07b9a511a2e81ebbd701744d03b5 /sbin/modload
parent0f81d3e0a26c2833cd085c472a4a77c325486b75 (diff)
Remove LKMs and switch to the module framework, pass 1.
Proposed on tech-kern@.
Diffstat (limited to 'sbin/modload')
-rw-r--r--sbin/modload/Makefile19
-rw-r--r--sbin/modload/a.out.c244
-rw-r--r--sbin/modload/elf.c509
-rw-r--r--sbin/modload/main.c33
-rw-r--r--sbin/modload/modload.8122
-rw-r--r--sbin/modload/modload.c528
-rw-r--r--sbin/modload/modload.h74
-rw-r--r--sbin/modload/pathnames.h6
8 files changed, 52 insertions, 1483 deletions
diff --git a/sbin/modload/Makefile b/sbin/modload/Makefile
index 8808046e442..9899683d84a 100644
--- a/sbin/modload/Makefile
+++ b/sbin/modload/Makefile
@@ -1,27 +1,10 @@
-# $NetBSD: Makefile,v 1.13 2008/03/02 11:20:59 jmmv Exp $
+# $NetBSD: Makefile,v 1.14 2008/11/12 12:35:53 ad Exp $
.include <bsd.own.mk>
-.if ${MKMODULAR} != "no" # new module framework
-
PROG= modload
SRCS= main.c
MAN= modload.8
LDADD= -lprop
-.else # LKMS
-
-PROG= modload
-SRCS= modload.c
-MAN= modload.8
-
-.if (${OBJECT_FMT} == "ELF")
-SRCS+= elf.c
-.else
-SRCS+= a.out.c
-CFLAGS+=-DUSE_AOUT
-.endif
-
-.endif
-
.include <bsd.prog.mk>
diff --git a/sbin/modload/a.out.c b/sbin/modload/a.out.c
deleted file mode 100644
index f99d4be5b46..00000000000
--- a/sbin/modload/a.out.c
+++ /dev/null
@@ -1,244 +0,0 @@
-/* $NetBSD: a.out.c,v 1.6 2005/02/06 06:17:36 perry 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/cdefs.h>
-__RCSID("$NetBSD: a.out.c,v 1.6 2005/02/06 06:17:36 perry Exp $");
-
-#include <sys/param.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"
-
-void
-a_out_linkcmd(char **cmdp,
- const char *kernel,
- const char *entry,
- const char *outfile,
- const void *address,
- const char *object,
- const char *ldscript) /* XXX ignored on a.out */
-{
- asprintf(cmdp, LINKCMD, kernel, entry, outfile, address, object);
-}
-
-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)
-{
- struct exec info_buf;
- size_t b;
- ssize_t n;
- char buf[10 * BUFSIZ];
-
- /*
- * Get the load module post load size... do this by reading the
- * header and doing page counts.
- */
- if (a_out_read_header(fd, &info_buf) < 0)
- return NULL;
-
- /*
- * Seek to the text offset to start loading...
- */
- if (lseek(fd, N_TXTOFF(info_buf), 0) == -1)
- err(12, "lseek");
-
- /*
- * Transfer the relinked module to kernel memory in chunks of
- * MODIOBUF size at a time.
- */
- b = info_buf.a_text + info_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 *)info_buf.a_entry;
-}
-
-void
-a_out_mod_symload(int strtablen)
-{
- struct exec info_buf;
- struct lmc_loadbuf ldbuf;
- struct nlist *nlp;
- char buf[10 * BUFSIZ];
- char *symbuf;
- int bytesleft, sz;
- int numsyms; /* XXX unused? */
-
- if (a_out_read_header(modfd, &info_buf) < 0)
- return;
-
- /*
- * Seek to the symbol table to start loading it...
- */
- if (lseek(modfd, N_SYMOFF(info_buf), SEEK_SET) == -1)
- err(12, "lseek");
-
- /*
- * Transfer the symbol table entries. First, read them all in,
- * then adjust their string table pointers, then
- * copy in bulk. Then copy the string table itself.
- */
-
- symbuf = malloc(info_buf.a_syms);
- if (symbuf == 0)
- err(13, "malloc");
-
- if (read(modfd, symbuf, info_buf.a_syms) != info_buf.a_syms)
- err(14, "read");
- numsyms = info_buf.a_syms / sizeof(struct nlist);
-
- for (nlp = (struct nlist *)symbuf;
- (char *)nlp < symbuf + info_buf.a_syms; nlp++) {
- int strx;
-
- strx = nlp->n_un.n_strx;
- if (strx != 0) {
- /*
- * If a valid name, set the name ptr to point at the
- * loaded address for the string in the string table.
- */
- if (strx > strtablen)
- nlp->n_un.n_name = 0;
- else
- nlp->n_un.n_name = (char *)(strx +
- resrv.sym_addr + info_buf.a_syms);
- }
- }
- /*
- * we've fixed the symbol table entries, now load them
- */
- for (bytesleft = info_buf.a_syms; bytesleft > 0; bytesleft -= sz) {
- sz = MIN(bytesleft, MODIOBUF);
- ldbuf.cnt = sz;
- ldbuf.data = symbuf;
- if (ioctl(devfd, LMLOADSYMS, &ldbuf) == -1)
- err(11, "error transferring sym buffer");
- symbuf += sz;
- }
-
- free(symbuf - info_buf.a_syms);
- /* and now read the string table and load it. */
- for (bytesleft = strtablen; bytesleft > 0; bytesleft -= sz) {
- sz = MIN(bytesleft, MODIOBUF);
- read(modfd, buf, sz);
- ldbuf.cnt = sz;
- ldbuf.data = buf;
- if (ioctl(devfd, LMLOADSYMS, &ldbuf) == -1)
- err(11, "error transferring stringtable buffer");
- }
-}
diff --git a/sbin/modload/elf.c b/sbin/modload/elf.c
deleted file mode 100644
index 565cf7b84e4..00000000000
--- a/sbin/modload/elf.c
+++ /dev/null
@@ -1,509 +0,0 @@
-/* $NetBSD: elf.c,v 1.19 2006/07/08 05:49:01 ross Exp $ */
-
-/*
- * Copyright (c) 1998 Johan Danielsson <joda@pdc.kth.se>
- * 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. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * 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/cdefs.h>
-__RCSID("$NetBSD: elf.c,v 1.19 2006/07/08 05:49:01 ross Exp $");
-
-#include <sys/param.h>
-
-#if defined(__alpha__) || defined(__arch64__) || defined(__x86_64__)
-#ifndef _LP64
-#error Temporary sanity check failed. Tell ross@netbsd.org
-#endif
-#endif
-
-#ifdef _LP64
-#define ELFSIZE 64
-#else
-#define ELFSIZE 32
-#endif
-#include <sys/exec_elf.h>
-#ifndef ELF_HDR_SIZE
-#define ELF_HDR_SIZE sizeof(Elf_Ehdr)
-#endif
-#include <sys/lkm.h>
-
-#include <err.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-
-#include "modload.h"
-
-char *strtab;
-
-static void
-read_section_header(int fd, Elf_Ehdr *ehdr, int num, Elf_Shdr *shdr)
-{
-
- if (lseek(fd, ehdr->e_shoff + num * ehdr->e_shentsize, SEEK_SET) < 0)
- err(1, "lseek");
- if (read(fd, shdr, sizeof(*shdr)) != sizeof(*shdr))
- err(1, "read");
-}
-
-struct elf_section {
- char *name; /* name of section; points into string table */
- unsigned long type; /* type of section */
- void *addr; /* load address of section */
- off_t offset; /* offset in file */
- size_t size; /* size of section */
- size_t align;
- struct elf_section *next;
-};
-
-/* adds the section `s' at the correct (sorted by address) place in
- the list pointed to by head; *head may be NULL */
-static void
-add_section(struct elf_section **head, struct elf_section *s)
-{
- struct elf_section *p, **q;
- q = head;
- p = *head;
-
- while (1) {
- if (p == NULL || p->addr > s->addr) {
- s->next = p;
- *q = s;
- return;
- }
- q = &p->next;
- p = p->next;
- }
-}
-
-/* make a linked list of all sections containing ALLOCatable data */
-static void
-read_sections(int fd, Elf_Ehdr *ehdr, char *shstrtab, struct elf_section **head)
-{
- int i;
- Elf_Shdr shdr;
- *head = NULL;
- /* scan through section headers */
- for (i = 0; i < ehdr->e_shnum; i++) {
- struct elf_section *s;
- read_section_header(fd, ehdr, i, &shdr);
- if (shdr.sh_size == 0)
- continue;
- if (((shdr.sh_flags & SHF_ALLOC) == 0)
- && (shdr.sh_type != SHT_STRTAB)
- && (shdr.sh_type != SHT_SYMTAB)
- && (shdr.sh_type != SHT_DYNSYM)) {
- /* skip non-ALLOC sections */
- continue;
- }
- s = malloc(sizeof(*s));
- if (s == NULL)
- errx(1, "failed to allocate %lu bytes", (u_long)sizeof(*s));
- s->name = shstrtab + shdr.sh_name;
- s->type = shdr.sh_type;
- s->addr = (void *)shdr.sh_addr;
- s->offset = shdr.sh_offset;
- s->size = shdr.sh_size;
- s->align = shdr.sh_addralign;
- add_section(head, s);
- }
-}
-
-/* get the symbol table sections and free the rest of them */
-static void
-get_symtab(struct elf_section **symtb)
-{
- struct elf_section *head, *cur, *prev;
-
- head = NULL;
- prev = NULL;
- cur = *symtb;
- while (cur) {
- if ((cur->type == SHT_SYMTAB) || (cur->type == SHT_DYNSYM)) {
- if (head == NULL) {
- head = cur;
- }
- if (prev != NULL) {
- prev->next = cur;
- }
- prev = cur;
- cur = cur->next;
- } else {
- struct elf_section *p = cur;
- cur = cur->next;
- p->next = NULL;
- free(p);
- }
- }
- if (prev) {
- prev->next = NULL;
- }
- *symtb = head;
-}
-
-/* free a list of section headers */
-static void
-free_sections(struct elf_section *head)
-{
-
- while (head) {
- struct elf_section *p = head;
- head = head->next;
- free(p);
- }
-}
-
-/* read section header's string table */
-static char *
-read_shstring_table(int fd, Elf_Ehdr *ehdr)
-{
- Elf_Shdr shdr;
- char *shstrtab;
- read_section_header(fd, ehdr, ehdr->e_shstrndx, &shdr);
- shstrtab = malloc(shdr.sh_size);
- if (shstrtab == NULL)
- errx(1, "failed to allocate %lu bytes", (u_long)shdr.sh_size);
- if (lseek(fd, shdr.sh_offset, SEEK_SET) < 0)
- err(1, "lseek");
- if (read(fd, shstrtab, shdr.sh_size) != shdr.sh_size)
- err(1, "read");
- return shstrtab;
-}
-
-/* read string table */
-static char *
-read_string_table(int fd, struct elf_section *head, int *strtablen)
-{
- char *string_table=NULL;
-
- while (head) {
- if ((strcmp(head->name, ".strtab") == 0 )
- && (head->type == SHT_STRTAB)) {
- string_table = malloc(head->size);
- if (string_table == NULL)
- errx(1, "failed to allocate %lu bytes",
- (u_long)head->size);
- if (lseek(fd, head->offset, SEEK_SET) < 0)
- err(1, "lseek");
- if (read(fd, string_table, head->size) != head->size)
- err(1, "read");
- *strtablen = head->size;
- break;
- } else {
- head = head->next;
- }
- }
- return string_table;
-}
-
-static int
-read_elf_header(int fd, Elf_Ehdr *ehdr)
-{
- ssize_t n;
-
- n = read(fd, ehdr, sizeof(*ehdr));
- if (n < 0)
- err(1, "failed reading %lu bytes", (u_long)sizeof(*ehdr));
- if (n != sizeof(*ehdr)) {
- if (debug)
- warnx("failed to read %lu bytes", (u_long)sizeof(*ehdr));
- return -1;
- }
- if (memcmp(ehdr->e_ident, ELFMAG, SELFMAG) != 0 ||
- ehdr->e_ident[EI_CLASS] != ELFCLASS)
- errx(4, "not in ELF%u format", ELFSIZE);
- if (ehdr->e_ehsize != ELF_HDR_SIZE)
- errx(4, "file has ELF%u identity, but wrong header size",
- ELFSIZE);
-
- return 0;
-}
-
-/* offset of data segment; this is horrible, but keeps the size of the
- module to a minimum */
-static ssize_t data_offset;
-
-/* return size needed by the module */
-int
-elf_mod_sizes(int fd,
- size_t *modsize,
- int *strtablen,
- struct lmc_resrv *resrvp,
- struct stat *sp)
-{
- Elf_Ehdr ehdr;
- ssize_t off = 0;
- size_t data_hole = 0;
- char *shstrtab, *strtb;
- struct elf_section *head, *s;
-
- if (read_elf_header(fd, &ehdr) < 0)
- return -1;
- shstrtab = read_shstring_table(fd, &ehdr);
- read_sections(fd, &ehdr, shstrtab, &head);
-
- for (s = head; s; s = s->next) {
- if ((s->type == SHT_STRTAB) && (s->type == SHT_SYMTAB)
- && (s->type == SHT_DYNSYM)) {
- continue;
- }
- if (debug)
- fprintf(stderr,
- "%s: addr = %p size = %#lx align = %#lx\n",
- s->name, s->addr, (u_long)s->size, (u_long)s->align);
- /* XXX try to get rid of the hole before the data
- section that GNU-ld likes to put there */
- if (strcmp(s->name, ".data") == 0 && s->addr > (void *)off) {
-#define ROUND(V, S) (((V) + (S) - 1) & ~((S) - 1))
- data_offset = ROUND(off, s->align);
- if (debug)
- fprintf(stderr, ".data section forced to "
- "offset %p (was %p)\n",
- (void *)data_offset,
- s->addr);
- /* later remove size of compressed hole from off */
- data_hole = (ssize_t)s->addr - data_offset;
- }
- off = (ssize_t)s->addr + s->size;
- }
- off -= data_hole;
-
- /* XXX round to pagesize? */
- *modsize = ROUND(off, sysconf(_SC_PAGESIZE));
- free(shstrtab);
-
- /* get string table length */
- strtb = read_string_table(fd, head, strtablen);
- free(strtb);
-
- /* get symbol table sections */
- resrvp->sym_symsize = 0;
- if (symtab) {
- struct elf_section *st;
-
- get_symtab(&head);
- for(st = head; st; st = st->next)
- resrvp->sym_symsize += st->size;
- resrvp->sym_size = resrvp->sym_symsize + *strtablen;
- } else
- resrvp->sym_size = 0;
- free_sections(head);
-
- return (0);
-}
-
-/*
- * Expected linker options:
- *
- * -R executable to link against
- * -e entry point
- * -o output file
- * -Ttext address to link text segment to in hex (assumes it's
- * a page boundary)
- * -Tdata address to link data segment to in hex
- * <target> object file
- * -T ldscript linker script (on some archs)
- */
-
-#define LINKCMD "ld -R %s -e %s -o %s -Ttext %p %s"
-#define LINKCMD2 "ld -R %s -e %s -o %s -Ttext %p -Tdata %p %s"
-#define LINKSCRIPTCMD "ld -T %s -R %s -e %s -o %s -Ttext %p %s"
-#define LINKSCRIPTCMD2 "ld -T %s -R %s -e %s -o %s -Ttext %p -Tdata %p %s"
-
-/* make a link command; XXX if data_offset above is non-zero, force
- data address to be at start of text + offset */
-void
-elf_linkcmd(char **cmdp,
- const char *kernel,
- const char *entry,
- const char *outfile,
- const void *address,
- const char *object,
- const char *ldscript)
-{
- if (ldscript == NULL) {
- if (data_offset == 0)
- asprintf(cmdp, LINKCMD, kernel, entry,
- outfile, address, object);
- else
- asprintf(cmdp, LINKCMD2, kernel, entry,
- outfile, address,
- (const char *)address + data_offset,
- object);
- } else {
- if (data_offset == 0)
- asprintf(cmdp, LINKSCRIPTCMD, ldscript, kernel,
- entry, outfile, address, object);
- else
- asprintf(cmdp, LINKSCRIPTCMD2, ldscript, kernel,
- entry, outfile, address,
- (const char *)address + data_offset,
- object);
- }
-
- if (cmdp == NULL)
- err(1, "malloc");
-}
-
-/* load a pre-linked module; returns entry point */
-void *
-elf_mod_load(int fd)
-{
- Elf_Ehdr ehdr;
- size_t zero_size = 0;
- size_t b;
- ssize_t n;
- char *shstrtab;
- struct elf_section *head, *s;
- char buf[10 * BUFSIZ];
- void *addr = NULL;
-
- if (read_elf_header(fd, &ehdr) < 0)
- return NULL;
-
- shstrtab = read_shstring_table(fd, &ehdr);
- read_sections(fd, &ehdr, shstrtab, &head);
-
- for (s = head; s; s = s->next) {
- if ((s->type != SHT_STRTAB) && (s->type != SHT_SYMTAB)
- && (s->type != SHT_DYNSYM)) {
- if (debug)
- fprintf(stderr, "loading `%s': addr = %p, "
- "size = %#lx\n",
- s->name, s->addr, (u_long)s->size);
- if (s->type == SHT_NOBITS) {
- /* skip some space */
- zero_size += s->size;
- } else {
- if (addr != NULL) {
- /* if there is a gap in the prelinked
- module, transfer some empty
- space... */
- zero_size += (char *)s->addr
- - (char *)addr;
- }
- if (zero_size) {
- loadspace(zero_size);
- zero_size = 0;
- }
- b = s->size;
- if (lseek(fd, s->offset, SEEK_SET) == -1)
- err(1, "lseek");
- while (b) {
- n = read(fd, buf, MIN(b, sizeof(buf)));
- if (n == 0)
- errx(1, "unexpected EOF");
- if (n < 0)
- err(1, "read");
- loadbuf(buf, n);
- b -= n;
- }
- addr = (char *)s->addr + s->size;
- }
- }
- }
- if (zero_size)
- loadspace(zero_size);
-
- free_sections(head);
- free(shstrtab);
- return (void *)ehdr.e_entry;
-}
-
-void
-elf_mod_symload(int strtablen)
-{
- Elf_Ehdr ehdr;
- char *shstrtab;
- struct elf_section *head, *s;
- char *symbuf, *strbuf;
-
- /*
- * Seek to the text offset to start loading...
- */
- if (lseek(modfd, 0, SEEK_SET) == -1)
- err(12, "lseek");
- if (read_elf_header(modfd, &ehdr) < 0)
- return;
-
- shstrtab = read_shstring_table(modfd, &ehdr);
- read_sections(modfd, &ehdr, shstrtab, &head);
-
- for (s = head; s; s = s->next) {
- struct elf_section *p = s;
-
- if ((p->type == SHT_SYMTAB) || (p->type == SHT_DYNSYM)) {
- if (debug)
- fprintf(stderr, "loading `%s': addr = %p, "
- "size = %#lx\n",
- s->name, s->addr, (u_long)s->size);
- /*
- * Seek to the file offset to start loading it...
- */
- if (lseek(modfd, p->offset, SEEK_SET) == -1)
- err(12, "lseek");
- symbuf = malloc(p->size);
- if (symbuf == 0)
- err(13, "malloc");
- if (read(modfd, symbuf, p->size) != p->size)
- err(14, "read");
-
- loadsym(symbuf, p->size);
- free(symbuf);
- }
- }
-
- for (s = head; s; s = s->next) {
- struct elf_section *p = s;
-
- if ((p->type == SHT_STRTAB)
- && (strcmp(p->name, ".strtab") == 0 )) {
- if (debug)
- fprintf(stderr, "loading `%s': addr = %p, "
- "size = %#lx\n",
- s->name, s->addr, (u_long)s->size);
- /*
- * Seek to the file offset to start loading it...
- */
- if (lseek(modfd, p->offset, SEEK_SET) == -1)
- err(12, "lseek");
- strbuf = malloc(p->size);
- if (strbuf == 0)
- err(13, "malloc");
- if (read(modfd, strbuf, p->size) != p->size)
- err(14, "read");
-
- loadsym(strbuf, p->size);
- free(strbuf);
- }
- }
-
- free(shstrtab);
- free_sections(head);
- return;
-}
diff --git a/sbin/modload/main.c b/sbin/modload/main.c
index c058dbca78a..35cad41da0f 100644
--- a/sbin/modload/main.c
+++ b/sbin/modload/main.c
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.3 2008/04/28 20:23:09 martin Exp $ */
+/* $NetBSD: main.c,v 1.4 2008/11/12 12:35:53 ad Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: main.c,v 1.3 2008/04/28 20:23:09 martin Exp $");
+__RCSID("$NetBSD: main.c,v 1.4 2008/11/12 12:35:53 ad Exp $");
#endif /* !lint */
#include <sys/module.h>
@@ -45,13 +45,14 @@ __RCSID("$NetBSD: main.c,v 1.3 2008/04/28 20:23:09 martin Exp $");
int main(int, char **);
static void parse_bool_param(prop_dictionary_t, const char *,
- const char *);
+ const char *);
static void parse_int_param(prop_dictionary_t, const char *,
- const char *);
+ const char *);
static void parse_param(prop_dictionary_t, const char *,
- void (*)(prop_dictionary_t, const char *, const char *));
+ void (*)(prop_dictionary_t, const char *,
+ const char *));
static void parse_string_param(prop_dictionary_t, const char *,
- const char *);
+ const char *);
static void usage(void) __dead;
int
@@ -114,10 +115,9 @@ main(int argc, char **argv)
exit(EXIT_SUCCESS);
}
-static
-void
+static void
parse_bool_param(prop_dictionary_t props, const char *name,
- const char *value)
+ const char *value)
{
bool boolvalue;
@@ -138,10 +138,9 @@ parse_bool_param(prop_dictionary_t props, const char *name,
prop_dictionary_set(props, name, prop_bool_create(boolvalue));
}
-static
-void
+static void
parse_int_param(prop_dictionary_t props, const char *name,
- const char *value)
+ const char *value)
{
int64_t intvalue;
@@ -155,10 +154,9 @@ parse_int_param(prop_dictionary_t props, const char *name,
prop_number_create_integer(intvalue));
}
-static
-void
+static void
parse_param(prop_dictionary_t props, const char *origstr,
- void (*fmt_handler)(prop_dictionary_t, const char *, const char *))
+ void (*fmt_handler)(prop_dictionary_t, const char *, const char *))
{
char *name, *value;
@@ -176,10 +174,9 @@ parse_param(prop_dictionary_t props, const char *origstr,
free(name);
}
-static
-void
+static void
parse_string_param(prop_dictionary_t props, const char *name,
- const char *value)
+ const char *value)
{
assert(name != NULL);
diff --git a/sbin/modload/modload.8 b/sbin/modload/modload.8
index 1ed860b642c..5ae71fbf3a2 100644
--- a/sbin/modload/modload.8
+++ b/sbin/modload/modload.8
@@ -1,4 +1,4 @@
-.\" $NetBSD: modload.8,v 1.26 2006/03/24 00:38:23 reed Exp $
+.\" $NetBSD: modload.8,v 1.27 2008/11/12 12:35:53 ad Exp $
.\"
.\" Copyright (c) 1993 Christopher G. Demetriou
.\" All rights reserved.
@@ -32,7 +32,7 @@
.\"
.\" <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
.\"
-.Dd March 23, 2006
+.Dd November 12, 2008
.Dt MODLOAD 8
.Os
.Sh NAME
@@ -40,100 +40,58 @@
.Nd load a kernel module
.Sh SYNOPSIS
.Nm
-.Op Fl dfnsSv
-.Op Fl A Ar kernel
-.Op Fl e Ar entry
-.Op Fl p Ar postinstall
-.Op Fl o Ar output_file
-.Op Fl T Ar linker_script
-.Ar input_file
+.Op Fl b Ar name=val
+.Op Fl f
+.Op Fl i Ar name=val
+.Op Fl s Ar name=val
+.Ar module
.Sh DESCRIPTION
The
.Nm
-utility loads a loadable kernel module into a running system.
-The input file is an object file (.o file).
+utility loads a kernel module specified by the
+.Ar module
+paramamter into the running system.
+.Pp
+The current working directory is first searched for the module object file.
+If not found there, the default system module areas are searched.
.Pp
The options to
.Nm
are as follows:
.Bl -tag -width indent
-.It Fl d
-Debug.
-Used to debug
-.Nm
-itself.
+.It Fl b
+Pass the module a boolean property with the name
+.Ar name .
+.Ar val
+may be either
+.Dv true
+or
+.Dv false.
+.It Fl i
+Pass the module an integer property with the name
+.Ar name
+and integral value
+.Ar val .
.It Fl f
-This forces load of the module, even if it doesn't match the
-currently running kernel.
-When LKM is loaded, the kernel normally checks if the LKM is
-compatible with the running kernel.
-This option disables this check.
-.Em Note
-an incompatible LKM can cause system instability, including data
+When a module is loaded, the kernel checks if the module is compatible
+with the running kernel and will refuse to load modules that are
+potentially incompatible.
+This option disables compatibility checks.
+.Em Note :
+an incompatible module can cause system instability, including data
loss or corruption.
-Don't use this option unless you are sure what you are doing.
-.It Fl n
-Do everything, except calling the module entry point (and any
-post-install program).
-.It Fl v
-Print comments about the loading process.
.It Fl s
-Load the symbol table.
-.It Fl S
-Do not remove the temporary object file.
-By default, the
-.Xr ld 1
-output is removed after being loaded into the kernel.
-.It Fl A Ar kernel
-Specify the file that is passed to the linker
-to resolve module references to external symbols.
-The symbol file must be for the currently running
-kernel or the module is likely to crash the system.
-.It Fl e Ar entry
-Specify the module entry point.
-This is passed by
-.Nm
-to
-.Xr ld 1
-when the module is linked.
-The default module entry point name is `xxxinit'.
-If `xxxinit' cannot be found, an attempt to
-use `\*[Lt]module_name\*[Gt]_lkmentry' will be made, where
-\*[Lt]module_name\*[Gt] is the filename being loaded without the `.o'.
-.It Fl p Ar postinstall
-Specify the name of a shell script or program that will
-be executed if the module is successfully loaded.
-It is always passed the module id (in decimal) and module
-type (in hexadecimal) as the first two arguments.
-For loadable drivers, the third argument is the character major device number
-and the fourth argument is the block major device number.
-For a loadable system call, the third argument is the system call number.
-.It Fl o Ar output_file
-Specify the name of the output file that is produced by the linker.
-.It Fl T Ar linker_script
-Specify the name of the linker script use to link against the kernel.
-.El
-.Sh FILES
-.Bl -tag -width /usr/include/sys/lkm.h -compact
-.It Pa /netbsd
-default file passed to the linker to resolve external
-references in the module
-.It Pa /usr/include/sys/lkm.h
-file containing definitions of module types
-.\" .It Pa output file.
-.\" default output file name
+Pass the module a string property with the name
+.Ar name
+and string value
+.Ar val .
.El
.Sh DIAGNOSTICS
The
.Nm
utility exits with a status of 0 on success
and with a nonzero status if an error occurs.
-.Pp
-Mismatched LKM and kernel versions will be reported to the console
-and to the system message buffer.
.Sh SEE ALSO
-.Xr ld 1 ,
-.Xr lkm 4 ,
.Xr modstat 8 ,
.Xr modunload 8
.Sh HISTORY
@@ -142,11 +100,3 @@ The
command was designed to be similar in functionality
to the corresponding command in
.Tn "SunOS 4.1.3" .
-.Sh AUTHORS
-.An Terrence R. Lambert
-.Aq terry@cs.weber.edu .
-.Sh BUGS
-Loading the symbol table is expensive in terms of space:
-it presently duplicates all the kernel symbols for each lkm loaded
-with
-.Fl s .
diff --git a/sbin/modload/modload.c b/sbin/modload/modload.c
deleted file mode 100644
index b51a932c291..00000000000
--- a/sbin/modload/modload.c
+++ /dev/null
@@ -1,528 +0,0 @@
-/* $NetBSD: modload.c,v 1.51 2005/06/27 01:00:05 christos 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/cdefs.h>
-#ifndef lint
-__RCSID("$NetBSD: modload.c,v 1.51 2005/06/27 01:00:05 christos Exp $");
-#endif /* not lint */
-
-#include <sys/param.h>
-#include <sys/ioctl.h>
-#include <sys/conf.h>
-#include <sys/mount.h>
-#include <sys/lkm.h>
-#include <sys/stat.h>
-#include <sys/file.h>
-#include <sys/sysctl.h>
-#include <machine/cpu.h>
-#include <err.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <nlist.h>
-#include "pathnames.h"
-
-#include "modload.h"
-
-#ifndef DFLT_ENTRY
-#define DFLT_ENTRY "xxxinit"
-#endif /* !DFLT_ENTRY */
-#ifndef DFLT_ENTRYEXT
-#define DFLT_ENTRYEXT "_lkmentry"
-#endif /* !DFLT_ENTRYEXT */
-
-int debug = 0;
-int verbose = 0;
-u_long force = 0;
-char *out = NULL;
-int symtab = 0;
-int Sflag;
-
-static void cleanup(void);
-
-/* prelink the module */
-static int
-prelink(const char *kernel,
- const char *entry,
- const char *outfile,
- const void *address,
- const char *object,
- const char *ldscript)
-{
- char *cmd;
- int error = 0;
-
- linkcmd(&cmd, kernel, entry, outfile, address,
- object, ldscript);
-
- if (debug)
- fprintf(stderr, "%s\n", cmd);
-
- switch (system(cmd)) {
- case 0: /* SUCCESS! */
- break;
- case 1: /* uninformative error */
- /*
- * Someone needs to fix the return values from the NetBSD
- * ld program -- it's totally uninformative.
- *
- * No such file (4 on SunOS)
- * Can't write output (2 on SunOS)
- * Undefined symbol (1 on SunOS)
- * etc.
- */
- case 127: /* can't load shell */
- case 32512:
- default:
- error = 1;
- break;
- }
-
- free(cmd);
-
- return error;
-}
-
-static void
-usage(void)
-{
-
- fprintf(stderr, "usage:\n");
- fprintf(stderr, "modload [-dfnsSv] "
- "[-A <kernel>] [-e <entry>] [-p <postinstall>]\n");
- fprintf(stderr,
- " [-o <output file>] [-T <linker_script>] <input file>\n");
- exit(1);
-}
-
-int fileopen = 0;
-#define DEV_OPEN 0x01
-#define MOD_OPEN 0x02
-#define PART_RESRV 0x04
-#define OUTFILE_CREAT 0x08
-
-int devfd, modfd;
-struct lmc_resrv resrv;
-
-static void
-cleanup(void)
-{
-
- if (fileopen & PART_RESRV) {
- /*
- * Free up kernel memory
- */
- if (ioctl(devfd, LMUNRESRV, 0) == -1)
- warn("can't release slot 0x%08x memory", resrv.slot);
- }
-
- if (fileopen & DEV_OPEN)
- close(devfd);
-
- if (fileopen & MOD_OPEN)
- close(modfd);
-
- if (fileopen & OUTFILE_CREAT)
- unlink(out);
-}
-
-static int
-verify_entry(const char *entry, char *filename)
-{
- struct nlist names[2];
- int n;
- char *s;
-
- memset(names, 0, sizeof(names));
- asprintf(&s, "_%s", entry);
- if (!s)
- err(1, "malloc");
-#ifdef _AOUT_INCLUDE_
- names[0].n_un.n_name = s;
-#else
- names[0].n_name = s;
-#endif
-
- n = nlist(filename, names);
- if (n == -1)
- err(1, "nlist %s", filename);
- return n;
-}
-
-/*
- * Transfer data to kernel memory in chunks
- * of MODIOBUF size at a time.
- */
-void
-loadbuf(void *buf, size_t len)
-{
- struct lmc_loadbuf ldbuf;
- size_t n;
- char *p = buf;
-
- while(len) {
- n = MIN(len, MODIOBUF);
- ldbuf.cnt = n;
- ldbuf.data = p;
- if (ioctl(devfd, LMLOADBUF, &ldbuf) == -1)
- err(11, "error loading buffer");
- len -= n;
- p += n;
- }
-}
-
-/* Transfer some empty space. */
-void
-loadspace(size_t len)
-{
- char buf[MODIOBUF];
- size_t n;
- memset(buf, 0, sizeof(buf));
- while(len) {
- n = MIN(len, sizeof(buf));
- loadbuf(buf, n);
- len -= n;
- }
-}
-
-/*
- * Transfer symbol table to kernel memory in chunks
- * of MODIOBUF size at a time.
- */
-void
-loadsym(void *buf, size_t len)
-{
- struct lmc_loadbuf ldbuf;
- size_t n;
- char *p = buf;
-
- while(len) {
- n = MIN(len, MODIOBUF);
- ldbuf.cnt = n;
- ldbuf.data = p;
- if(ioctl(devfd, LMLOADSYMS, &ldbuf) == -1)
- err(11, "error loading buffer");
- len -= n;
- p += n;
- }
-}
-
-int
-main(int argc, char **argv)
-{
- int c;
- const char *kname = NULL;
- const char *entry = DFLT_ENTRY;
- char *post = NULL;
- const char *ldscript = NULL;
- char *modobj;
- char modout[MAXPATHLEN], *p;
- struct stat stb;
- int strtablen;
- size_t modsize; /* XXX */
- void *modentry; /* XXX */
- int noready = 0;
-
- while ((c = getopt(argc, argv, "dfnvse:p:o:A:ST:")) != -1) {
- switch (c) {
- case 'd':
- debug = 1;
- break; /* debug */
- case 'f':
- force = 1;
- break; /* force load */
- case 'v':
- verbose = 1;
- break; /* verbose */
- case 'A':
- kname = optarg;
- break; /* kernel */
- case 'e':
- entry = optarg;
- break; /* entry point */
- case 'p':
- post = optarg;
- break; /* postinstall */
- case 'o':
- out = optarg;
- break; /* output file */
- case 'T':
- ldscript = optarg;
- break; /* linker script */
- case 'n':
- noready = 1;
- break;
- case 's':
- symtab = 1;
- break;
- case 'S':
- Sflag = 1;
- break;
- case '?':
- usage();
- /* NOTREACHED */
- default:
- printf("default!\n");
- break;
- }
- }
- argc -= optind;
- argv += optind;
-
- if (argc != 1)
- usage();
-
- modobj = argv[0];
-
- atexit(cleanup);
-
- if (ldscript == NULL && access(_PATH_LDSCRIPT, R_OK) == 0)
- ldscript = _PATH_LDSCRIPT;
-
- /*
- * Open the virtual device device driver for exclusive use (needed
- * to write the new module to it as our means of getting it in the
- * kernel).
- */
- if ((devfd = open(_PATH_LKM, O_RDWR, 0)) == -1)
- err(3, _PATH_LKM);
- fileopen |= DEV_OPEN;
-
- if (strlcpy(modout, modobj, sizeof(modout)) >= sizeof(modout))
- errx(1, "program name is too big for buffer");
-
- p = strrchr(modout, '.');
- if (!p || strcmp(p, ".o"))
- errx(2, "module object must end in .o");
- *p = '\0';
- if (out == NULL)
- out = modout;
-
- /*
- * Verify that the entry point for the module exists.
- */
- if (verify_entry(entry, modobj)) {
- /*
- * Try <modobj>_init if entry is DFLT_ENTRY.
- */
- if (strcmp(entry, DFLT_ENTRY) == 0) {
- char *nentry;
- if ((p = strrchr(modout, '/')))
- p++;
- else
- p = modout;
- asprintf(&nentry, "%s%s", p, DFLT_ENTRYEXT);
- if (!nentry)
- err(1, "malloc");
- entry = nentry;
- if (verify_entry(entry, modobj))
- errx(1, "entry point _%s not found in %s",
- entry, modobj);
- } else
- errx(1, "entry point _%s not found in %s", entry,
- modobj);
- }
-
- /*
- * Check if /dev/ksyms can be used.
- */
- if (kname == NULL) {
- int fd = open(_PATH_KSYMS, O_RDONLY);
- if (fd < 0) {
- warn("%s", _PATH_KSYMS);
- } else {
- close(fd);
- kname = _PATH_KSYMS;
- }
- }
-
- /*
- * Determine name of kernel to use
- */
- if (kname == NULL) {
-#ifdef CPU_BOOTED_KERNEL
- /* 130 is 128 + '/' + '\0' */
- static char booted_kernel[130];
- int mib[2], rc;
- size_t len;
- struct stat st;
-
- mib[0] = CTL_MACHDEP;
- mib[1] = CPU_BOOTED_KERNEL;
- booted_kernel[0] = '/';
- booted_kernel[1] = '\0';
- len = sizeof(booted_kernel) - 2;
- rc = sysctl(&mib[0], 2, &booted_kernel[1], &len, NULL, 0);
- booted_kernel[sizeof(booted_kernel) - 1] = '\0';
- kname = (booted_kernel[1] == '/') ?
- &booted_kernel[1] : &booted_kernel[0];
- if (rc != -1)
- rc = stat(kname, &st);
- if (rc == -1 || !S_ISREG(st.st_mode))
-#endif /* CPU_BOOTED_KERNEL */
- kname = _PATH_UNIX;
- }
- /*
- * Prelink to get file size
- */
- if (prelink(kname, entry, out, 0, modobj, ldscript))
- errx(1, "can't prelink `%s' creating `%s'", modobj, out);
- if (Sflag == 0)
- fileopen |= OUTFILE_CREAT;
-
- /*
- * Pre-open the 0-linked module to get the size information
- */
- if ((modfd = open(out, O_RDONLY, 0)) == -1)
- err(4, "%s", out);
- fileopen |= MOD_OPEN;
-
- /*
- * stat for filesize to figure out string table size
- */
- if (fstat(modfd, &stb) == -1)
- err(3, "fstat `%s'", out);
-
- /*
- * work out various sizes and fill in resrv bits
- */
- if (mod_sizes(modfd, &modsize, &strtablen, &resrv, &stb) != 0)
- err(1, "can't get module sizes");
-
- /*
- * Close the dummy module -- we have our sizing information.
- */
- close(modfd);
- fileopen &= ~MOD_OPEN;
-
- /*
- * Reserve the required amount of kernel memory -- this may fail
- * to be successful.
- */
- resrv.size = modsize; /* size in bytes */
- resrv.name = modout; /* objname w/o ".o" */
- resrv.slot = -1; /* returned */
- resrv.addr = 0; /* returned */
-
- if (verbose)
- warnx("reserving %lu bytes of memory", (unsigned long)modsize);
- if (ioctl(devfd, LMRESERV, &resrv) == -1)
- err(9, "can't reserve memory");
-
- fileopen |= PART_RESRV;
-
- if (force) {
- if (ioctl(devfd, LMFORCE, &force) == -1)
- err(10, "can't force load");
-
- warnx("Forced load of LKM '%s'. MAY CAUSE SYSTEM INSTABILITY.",
- modout);
- }
-
- /*
- * Relink at kernel load address
- */
- if (prelink(kname, entry, out, (void *)resrv.addr, modobj, ldscript))
- errx(1, "can't link `%s' creating `%s' bound to %p",
- modobj, out, (void *)resrv.addr);
-
- /*
- * Open the relinked module to load it...
- */
- if ((modfd = open(out, O_RDONLY, 0)) == -1)
- err(4, "%s", out);
- fileopen |= MOD_OPEN;
-
- modentry = mod_load(modfd);
- if (debug)
- fprintf(stderr, "modentry = %p\n", modentry);
-
- if (symtab)
- mod_symload(strtablen);
-
- /*
- * Save ourselves before disaster (potentitally) strikes...
- */
- sync();
-
- if (noready)
- return 0;
-
- /*
- * Trigger the module as loaded by calling the entry procedure;
- * this will do all necessary table fixup to ensure that state
- * is maintained on success, or blow everything back to ground
- * zero on failure.
- */
- if (ioctl(devfd, LMREADY, &modentry) == -1)
- err(14, "error initializing module");
-
- /*
- * Success!
- */
- fileopen &= ~PART_RESRV; /* loaded */
- printf("Module loaded as ID %d\n", resrv.slot);
-
- /*
- * Execute the post-install program, if specified.
- */
- if (post) {
- struct lmc_stat sbuf;
- char id[16], type[16];
-
- sbuf.id = resrv.slot;
- if (ioctl(devfd, LMSTAT, &sbuf) == -1)
- err(15, "error fetching module stats for post-install");
- (void)snprintf(id, sizeof(id), "%d", sbuf.id);
- (void)snprintf(type, sizeof(type), "0x%x", sbuf.type);
- if (sbuf.type == LM_DEV) {
- char arg3[16], arg4[16];
- int bmajor = LKM_BLOCK_MAJOR(sbuf.offset);
- int cmajor = LKM_CHAR_MAJOR(sbuf.offset);
- (void)snprintf(arg3, sizeof(arg3), "%d", cmajor);
- (void)snprintf(arg4, sizeof(arg4), "%d", bmajor);
- execl(post, post, id, type, arg3, arg4, NULL);
- } else {
- char arg3[16];
- (void)snprintf(arg3, sizeof(arg3), "%ld",
- (long)sbuf.offset);
- execl(post, post, id, type, arg3, NULL);
- }
- err(16, "can't exec `%s'", post);
- }
-
- exit (0);
-}
diff --git a/sbin/modload/modload.h b/sbin/modload/modload.h
deleted file mode 100644
index f9056ce1546..00000000000
--- a/sbin/modload/modload.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/* $NetBSD: modload.h,v 1.6 2004/02/11 18:42:37 jdolecek 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.
- */
-
-#ifndef __modload_h__
-#define __modload_h__
-
-int elf_mod_sizes(int, size_t *, int *, struct lmc_resrv *, struct stat *);
-void *elf_mod_load(int);
-void elf_linkcmd(char **, const char *, const char *, const char *,
- const void *, const char *, const char *);
-void elf_mod_symload(int);
-
-int a_out_mod_sizes(int, size_t *, int *, struct lmc_resrv *,
- struct stat *);
-void *a_out_mod_load(int);
-void a_out_linkcmd(char **, const char *, const char *, const char *,
- const void *, const char *, const char *);
-void a_out_mod_symload(int);
-
-#ifndef USE_AOUT
-#define mod_sizes elf_mod_sizes
-#define mod_load elf_mod_load
-#define mod_symload elf_mod_symload
-#define linkcmd elf_linkcmd
-#else
-#define mod_sizes a_out_mod_sizes
-#define mod_load a_out_mod_load
-#define mod_symload a_out_mod_symload
-#define linkcmd a_out_linkcmd
-#endif
-
-void loadbuf(void *, size_t);
-void loadspace(size_t);
-void loadsym(void *, size_t);
-
-extern int debug;
-extern int devfd;
-extern int modfd;
-extern int symtab;
-extern int verbose;
-extern struct lmc_resrv resrv;
-
-#endif /* __modload_h__ */
diff --git a/sbin/modload/pathnames.h b/sbin/modload/pathnames.h
deleted file mode 100644
index bac00c6461c..00000000000
--- a/sbin/modload/pathnames.h
+++ /dev/null
@@ -1,6 +0,0 @@
-/* $NetBSD: pathnames.h,v 1.3 2002/10/10 01:57:10 simonb Exp $ */
-
-#include <paths.h>
-
-#define _PATH_LKM "/dev/lkm"
-#define _PATH_LDSCRIPT "/usr/lkm/ldscript"