Source-Changes-HG archive

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

[src/trunk]: src/sys Maitain a chainedlist of already loaded Mach-O objects, ...



details:   https://anonhg.NetBSD.org/src/rev/22bcb106d698
branches:  trunk
changeset: 539907:22bcb106d698
user:      manu <manu%NetBSD.org@localhost>
date:      Fri Nov 29 11:31:11 2002 +0000

description:
Maitain a chainedlist of already loaded Mach-O objects, to avoid loading
the same file multiple times because of recursive loading (ie: libx require
liby and libz and liby require libz, so libz would be loaded twice)

This is probably suboptimal, but it enable /bin/sh to load on the PowerPC,
so it's a good interim solution until we figure precisely how things should
work.

I'm not sure whether this makes the excessive recursive check useless or not.

diffstat:

 sys/kern/exec_macho.c |  30 ++++++++++++++++++++++++++++--
 sys/sys/exec_macho.h  |   9 +++++++--
 2 files changed, 35 insertions(+), 4 deletions(-)

diffs (112 lines):

diff -r c4d0b4b65752 -r 22bcb106d698 sys/kern/exec_macho.c
--- a/sys/kern/exec_macho.c     Fri Nov 29 08:31:06 2002 +0000
+++ b/sys/kern/exec_macho.c     Fri Nov 29 11:31:11 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: exec_macho.c,v 1.19 2002/11/24 21:59:44 manu Exp $     */
+/*     $NetBSD: exec_macho.c,v 1.20 2002/11/29 11:31:11 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.19 2002/11/24 21:59:44 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: exec_macho.c,v 1.20 2002/11/29 11:31:11 manu Exp $");
 
 #include <sys/param.h>
 #include <sys/proc.h>
@@ -50,6 +50,7 @@
 #include <sys/signalvar.h>
 #include <sys/resourcevar.h>
 #include <sys/mount.h>
+#include <sys/queue.h>
 #include <sys/stat.h>
 
 #include <uvm/uvm.h>
@@ -322,12 +323,30 @@
        struct vnode *vp;
        struct vattr attr;
        struct exec_macho_fat_header fat;
+       struct exec_macho_emul_arg *emea;
+       struct exec_macho_loaded_file *loaded_file;
 
        /*
         * Check for excessive rercursive loading
         */
        if (depth++ > 6)
                return E2BIG;
+       
+       /* Check that this file has not been already loaded */
+       emea = (struct exec_macho_emul_arg *)epp->ep_emul_arg;
+       LIST_FOREACH(loaded_file, &emea->loaded_files, file_list)
+               if (strncmp(path, loaded_file->filename, MAXPATHLEN) == 0)
+                       break;
+       if (loaded_file != NULL) {
+               DPRINTF(("%s already loaded, skipping\n", path));
+               return 0;
+       }
+
+       /* This is a new file, enter it in the loaded file list */
+       loaded_file = (struct exec_macho_loaded_file *)
+           malloc(sizeof(struct exec_macho_loaded_file), M_EXEC, M_WAITOK);
+       strncpy(loaded_file->filename, path, sizeof(loaded_file->filename));
+       LIST_INSERT_HEAD(&emea->loaded_files, loaded_file, file_list);
 
        /*
         * 1. open file
@@ -569,6 +588,7 @@
 {
        struct exec_macho_fat_header *fat = epp->ep_hdr;
        struct exec_macho_emul_arg *emea;
+       struct exec_macho_loaded_file *loaded_file;
        int error;
 
        if (epp->ep_hdrvalid < sizeof(*fat))
@@ -590,6 +610,7 @@
                return (error);
 
        emea = malloc(sizeof(struct exec_macho_emul_arg), M_EXEC, M_WAITOK);
+       LIST_INIT(&emea->loaded_files);
        epp->ep_emul_arg = (void *)emea;
 
        if (!epp->ep_esch->u.mach_probe_func)
@@ -618,6 +639,11 @@
 bad:
        kill_vmcmds(&epp->ep_vmcmds);
 bad2:
+       while (LIST_EMPTY(&emea->loaded_files) == 0) {
+               loaded_file = LIST_FIRST(&emea->loaded_files);
+               LIST_REMOVE(loaded_file, file_list);
+               free(loaded_file, M_EXEC);
+       }
        free(emea, M_EXEC);
        return error;
 }
diff -r c4d0b4b65752 -r 22bcb106d698 sys/sys/exec_macho.h
--- a/sys/sys/exec_macho.h      Fri Nov 29 08:31:06 2002 +0000
+++ b/sys/sys/exec_macho.h      Fri Nov 29 11:31:11 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: exec_macho.h,v 1.8 2002/11/24 21:59:43 manu Exp $      */
+/*     $NetBSD: exec_macho.h,v 1.9 2002/11/29 11:31:11 manu Exp $      */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -242,11 +242,16 @@
        u_long  count;
 };
 
-#define EXEC_MACHO_MAXLOADCOUNT 1024  /* maximum loading recursion allowed */
+struct exec_macho_loaded_file {
+       char filename[MAXPATHLEN];
+       LIST_ENTRY(exec_macho_loaded_file) file_list;
+};
+
 struct exec_macho_emul_arg {
        char *path;
        char filename[MAXPATHLEN];
        struct exec_macho_object_header *macho_hdr;
+       LIST_HEAD(loaded_files, exec_macho_loaded_file) loaded_files;
 };
 
 #ifndef _LKM



Home | Main Index | Thread Index | Old Index