Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/modload ANSIfy, KNF, declare externs in headers only.



details:   https://anonhg.NetBSD.org/src/rev/3f4706c8806e
branches:  trunk
changeset: 537841:3f4706c8806e
user:      simonb <simonb%NetBSD.org@localhost>
date:      Sun Oct 06 13:23:00 2002 +0000

description:
ANSIfy, KNF, declare externs in headers only.

diffstat:

 sbin/modload/a.out.c   |   41 ++++------
 sbin/modload/elf.c     |  177 +++++++++++++++++++++++-------------------------
 sbin/modload/modload.c |   34 ++++----
 sbin/modload/modload.h |   47 ++++++------
 4 files changed, 145 insertions(+), 154 deletions(-)

diffs (truncated from 601 to 300 lines):

diff -r 8ca9c2566024 -r 3f4706c8806e sbin/modload/a.out.c
--- a/sbin/modload/a.out.c      Sun Oct 06 13:05:39 2002 +0000
+++ b/sbin/modload/a.out.c      Sun Oct 06 13:23:00 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: a.out.c,v 1.1 1999/06/13 12:54:40 mrg Exp $    */
+/*     $NetBSD: a.out.c,v 1.2 2002/10/06 13:23:00 simonb Exp $ */
 
 /*
  * Copyright (c) 1993 Terrence R. Lambert.
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: a.out.c,v 1.1 1999/06/13 12:54:40 mrg Exp $");
+__RCSID("$NetBSD: a.out.c,v 1.2 2002/10/06 13:23:00 simonb Exp $");
 
 #include <sys/param.h>
 #include <sys/ioctl.h>
@@ -64,15 +64,15 @@
 void
 a_out_linkcmd(char *buf,
              size_t len,
-             const char *kernel, 
-             const char *entry, 
-             const char *outfile, 
-             const void *address, 
+             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, 
+       n = snprintf(buf, len, LINKCMD, kernel, entry,
                     outfile, address, object);
        if (n >= len)
                errx(1, "link command longer than %lu bytes", (u_long)len);
@@ -88,7 +88,7 @@
                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", 
+                       fprintf(stderr, "failed to read %lu bytes",
                                (u_long)sizeof(*info_buf));
                return -1;
        }
@@ -101,15 +101,12 @@
        return 0;
 }
 
-extern int symtab;
-
 int
-a_out_mod_sizes(fd, modsize, strtablen, resrvp, sp)
-       int fd;
-       size_t *modsize;
-       int *strtablen;
-       struct lmc_resrv *resrvp;
-       struct stat *sp;
+a_out_mod_sizes(int fd,
+               size_t *modsize,
+               int *strtablen,
+               struct lmc_resrv *resrvp,
+               struct stat * sp)
 {
        struct exec info_buf;
 
@@ -151,7 +148,7 @@
         */
        if (a_out_read_header(fd, &info_buf) < 0)
                return NULL;
-       
+
        /*
         * Seek to the text offset to start loading...
         */
@@ -169,19 +166,15 @@
                        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;
 }
 
-extern int devfd, modfd;
-extern struct lmc_resrv resrv;
-
 void
-a_out_mod_symload(strtablen)
-       int strtablen;
+a_out_mod_symload(int strtablen)
 {
        struct exec info_buf;
        struct lmc_loadbuf ldbuf;
@@ -214,7 +207,7 @@
                err(14, "read");
        numsyms = info_buf.a_syms / sizeof(struct nlist);
 
-       for (nlp = (struct nlist *)symbuf; 
+       for (nlp = (struct nlist *)symbuf;
            (char *)nlp < symbuf + info_buf.a_syms; nlp++) {
                register int strx;
 
diff -r 8ca9c2566024 -r 3f4706c8806e sbin/modload/elf.c
--- a/sbin/modload/elf.c        Sun Oct 06 13:05:39 2002 +0000
+++ b/sbin/modload/elf.c        Sun Oct 06 13:23:00 2002 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: elf.c,v 1.10 2002/07/24 14:14:10 joda Exp $    */
+/*     $NetBSD: elf.c,v 1.11 2002/10/06 13:23:00 simonb Exp $  */
 
 /*
- * Copyright (c) 1998 Johan Danielsson <joda%pdc.kth.se@localhost> 
+ * Copyright (c) 1998 Johan Danielsson <joda%pdc.kth.se@localhost>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -29,18 +29,18 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: elf.c,v 1.10 2002/07/24 14:14:10 joda Exp $");
+__RCSID("$NetBSD: elf.c,v 1.11 2002/10/06 13:23:00 simonb Exp $");
 
 #include <sys/param.h>
 
 #if defined(__alpha__) || defined(__arch64__) || defined(__x86_64__)
-#define ELFSIZE 64
+#define        ELFSIZE 64
 #else
-#define ELFSIZE 32
+#define        ELFSIZE 32
 #endif
 #include <sys/exec_elf.h>
 #ifndef ELF_HDR_SIZE
-#define ELF_HDR_SIZE sizeof(Elf_Ehdr)
+#define        ELF_HDR_SIZE sizeof(Elf_Ehdr)
 #endif
 #include <sys/lkm.h>
 
@@ -230,7 +230,7 @@
            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", 
+               errx(4, "file has ELF%u identity, but wrong header size",
                    ELFSIZE);
 
        return 0;
@@ -242,38 +242,36 @@
 
 /* return size needed by the module */
 int
-elf_mod_sizes(fd, modsize, strtablen, resrvp, sp)
-       int fd;
-       size_t *modsize;
-       int *strtablen;
-       struct lmc_resrv *resrvp;
-       struct stat *sp;
+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, *strtab;
        struct elf_section *head, *s;
-       extern int symtab;
-       
+
        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)) {
+               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", 
+                       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 */
+                  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))
+#define        ROUND(V, S) (((V) + (S) - 1) & ~((S) - 1))
                        data_offset = ROUND(off, s->align);
                        if (debug)
                                fprintf(stderr, ".data section forced to "
@@ -286,7 +284,7 @@
                off = (ssize_t)s->addr + s->size;
        }
        off -= data_hole;
-       
+
        /* XXX round to pagesize? */
        *modsize = ROUND(off, sysconf(_SC_PAGESIZE));
        free(shstrtab);
@@ -317,7 +315,7 @@
  * -R          executable to link against
  * -e          entry point
  * -o          output file
- * -Ttext      address to link text segment to in hex (assumes it's 
+ * -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 */
@@ -330,20 +328,20 @@
 void
 elf_linkcmd(char *buf,
            size_t len,
-           const char *kernel, 
-           const char *entry, 
-           const char *outfile, 
-           const void *address, 
+           const char *kernel,
+           const char *entry,
+           const char *outfile,
+           const void *address,
            const char *object)
 {
        ssize_t n;
 
        if (data_offset == NULL)
-               n = snprintf(buf, len, LINKCMD, kernel, entry, 
+               n = snprintf(buf, len, LINKCMD, kernel, entry,
                             outfile, address, object);
        else
-               n = snprintf(buf, len, LINKCMD2, kernel, entry, 
-                            outfile, address, 
+               n = snprintf(buf, len, LINKCMD2, kernel, entry,
+                            outfile, address,
                             (const char*)address + data_offset, object);
        if (n >= len)
                errx(1, "link command longer than %lu bytes", (u_long)len);
@@ -361,19 +359,19 @@
        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", 
+                                       "size = %#lx\n",
                                        s->name, s->addr, (u_long)s->size);
                        if (s->type == SHT_NOBITS) {
                                /* skip some space */
@@ -381,8 +379,8 @@
                        } else {
                                if (addr != NULL) {
                                        /* if there is a gap in the prelinked
-                                       module, transfer some empty
-                                       space... */
+                                       module, transfer some empty
+                                       space... */
                                        zero_size += (char*)s->addr
                                                        - (char*)addr;
                                }
@@ -408,84 +406,81 @@
        }
        if (zero_size)
                loadspace(zero_size);
-       
+
        free_sections(head);
        free(shstrtab);
        return (void*)ehdr.e_entry;
 }
 
-extern int devfd, modfd;
-
 void
-elf_mod_symload(strtablen)



Home | Main Index | Thread Index | Old Index