Source-Changes-HG archive

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

[src/trunk]: src/sys/kern If the magic number is 0xfeedface instead of 0xcafe...



details:   https://anonhg.NetBSD.org/src/rev/a49ca55b8384
branches:  trunk
changeset: 538782:a49ca55b8384
user:      manu <manu%NetBSD.org@localhost>
date:      Tue Oct 29 19:28:19 2002 +0000

description:
If the magic number is 0xfeedface instead of 0xcafebabe, this means that
the executable is not fat. The binary starts with an object header instead
of a mach fat header.

diffstat:

 sys/kern/exec_macho.c |  53 +++++++++++++++++++++++++++++++-------------------
 1 files changed, 33 insertions(+), 20 deletions(-)

diffs (90 lines):

diff -r b5e755a6fd83 -r a49ca55b8384 sys/kern/exec_macho.c
--- a/sys/kern/exec_macho.c     Tue Oct 29 17:54:40 2002 +0000
+++ b/sys/kern/exec_macho.c     Tue Oct 29 19:28:19 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: exec_macho.c,v 1.8 2002/10/05 22:34:05 chs Exp $       */
+/*     $NetBSD: exec_macho.c,v 1.9 2002/10/29 19:28:19 manu Exp $      */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: exec_macho.c,v 1.8 2002/10/05 22:34:05 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: exec_macho.c,v 1.9 2002/10/29 19:28:19 manu Exp $");
 
 #include <sys/param.h>
 #include <sys/proc.h>
@@ -98,9 +98,9 @@
 exec_macho_print_fat_arch(struct exec_macho_fat_arch *arch) {
        printf("arch.cputype %x\n", be32toh(arch->cputype));
        printf("arch.cpusubtype %d\n", be32toh(arch->cpusubtype));
-       printf("arch.offset 0x%x\n", be32toh(arch->offset));
-       printf("arch.size %d\n", be32toh(arch->size));
-       printf("arch.align 0x%x\n", be32toh(arch->align));
+       printf("arch.offset 0x%lx\n", be32toh(arch->offset));
+       printf("arch.size %ld\n", be32toh(arch->size));
+       printf("arch.align 0x%lx\n", be32toh(arch->align));
 }
 
 static void
@@ -352,30 +352,43 @@
        size_t size;
        void *buf = &lc;
 
-       if (be32toh(fat->magic) != MACHO_FAT_MAGIC) {
-               DPRINTF(("bad exec_macho fat magic %x\n", fat->magic));
-               goto bad;
-       }
-
 #ifdef DEBUG_MACHO
        exec_macho_print_fat_header(fat);
 #endif
 
-       for (i = 0; i < be32toh(fat->nfat_arch); i++, arch) {
-               if ((error = exec_read_from(p, vp, sizeof(*fat) +
-                   sizeof(arch) * i, &arch, sizeof(arch))) != 0)
-                       goto bad;
+       switch(be32toh(fat->magic)){
+       case MACHO_FAT_MAGIC:           
+               for (i = 0; i < be32toh(fat->nfat_arch); i++, arch) {
+                       if ((error = exec_read_from(p, vp, sizeof(*fat) +
+                           sizeof(arch) * i, &arch, sizeof(arch))) != 0)
+                               goto bad;
 #ifdef DEBUG_MACHO
-               exec_macho_print_fat_arch(&arch);
+                       exec_macho_print_fat_arch(&arch);
 #endif
-               switch (be32toh(arch.cputype)) {
-               MACHO_MACHDEP_CASES
+                       switch (be32toh(arch.cputype)) {
+                       MACHO_MACHDEP_CASES
+                       }
                }
+
+               DPRINTF(("This MACH-O binary does not support your cpu"));
+               goto bad;
+done:
+               break;
+
+       case MACHO_MOH_MAGIC:
+               /* 
+                * This is not a FAT Mach-O binary, the file starts
+                * with the object header.
+                */
+               arch.offset = 0;
+               break;
+
+       default:
+               DPRINTF(("bad exec_macho magic %x\n", fat->magic));
+               goto bad;
+               break;
        }
-       DPRINTF(("This MACH-O binary does not support your cpu"));
-       goto bad;
 
-done:
        if ((error = exec_read_from(p, vp, be32toh(arch.offset), &hdr,
            sizeof(hdr))) != 0)
                goto bad;



Home | Main Index | Thread Index | Old Index