Source-Changes-HG archive

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

[src/trunk]: src/sys Add a hook for freeing an ep_emul_arg. Add a wrapper ro...



details:   https://anonhg.NetBSD.org/src/rev/e6048e5a8458
branches:  trunk
changeset: 773490:e6048e5a8458
user:      matt <matt%NetBSD.org@localhost>
date:      Fri Feb 03 20:11:53 2012 +0000

description:
Add a hook for freeing an ep_emul_arg.  Add a wrapper routine
(exec_free_emul_arg) to call the hook and then clear the ep_emul_arg
and ep_emul_arg_free members in the exec_package.
Change users/accessors to use these routines.
Approved by releng.

diffstat:

 sys/compat/linux/arch/amd64/linux_exec_machdep.c   |  17 ++++++--------
 sys/compat/linux/arch/powerpc/linux_exec_powerpc.c |   8 ++----
 sys/compat/linux/common/linux_exec_elf32.c         |   7 ++---
 sys/compat/linux32/common/linux32_exec_elf32.c     |   8 ++----
 sys/compat/netbsd32/netbsd32_exec_elf32.c          |   8 ++----
 sys/compat/osf1/osf1_exec_ecoff.c                  |  25 ++++++++++++++-------
 sys/compat/svr4_32/svr4_32_exec_elf32.c            |  11 +++------
 sys/kern/exec_elf.c                                |  22 ++++++++++++++-----
 sys/kern/kern_exec.c                               |  21 ++++++++++++++---
 sys/sys/exec.h                                     |   7 +++++-
 10 files changed, 79 insertions(+), 55 deletions(-)

diffs (truncated from 470 to 300 lines):

diff -r b3b28b5644bf -r e6048e5a8458 sys/compat/linux/arch/amd64/linux_exec_machdep.c
--- a/sys/compat/linux/arch/amd64/linux_exec_machdep.c  Fri Feb 03 19:29:59 2012 +0000
+++ b/sys/compat/linux/arch/amd64/linux_exec_machdep.c  Fri Feb 03 20:11:53 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linux_exec_machdep.c,v 1.18 2010/07/07 01:30:33 chs Exp $ */
+/*     $NetBSD: linux_exec_machdep.c,v 1.19 2012/02/03 20:11:53 matt Exp $ */
 
 /*-
  * Copyright (c) 2005 Emmanuel Dreyfus, all rights reserved
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_exec_machdep.c,v 1.18 2010/07/07 01:30:33 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_exec_machdep.c,v 1.19 2012/02/03 20:11:53 matt Exp $");
 
 #define ELFSIZE 64
 
@@ -42,7 +42,7 @@
 #include <sys/resource.h>
 #include <sys/proc.h>
 #include <sys/conf.h>
-#include <sys/malloc.h>
+#include <sys/kmem.h>
 #include <sys/exec_elf.h>
 #include <sys/vnode.h>
 #include <sys/lwp.h>
@@ -154,7 +154,7 @@
         */
        if (ap == NULL) {
                phsize = eh->e_phnum * sizeof(Elf_Phdr);
-               ph = (Elf_Phdr *)malloc(phsize, M_TEMP, M_WAITOK);
+               ph = (Elf_Phdr *)kmem_alloc(phsize, KM_SLEEP);
                error = exec_read_from(l, pack->ep_vp, eh->e_phoff, ph, phsize);
                if (error != 0) {
                        for (i = 0; i < eh->e_phnum; i++) {
@@ -164,7 +164,7 @@
                                }
                        }
                }
-               free(ph, M_TEMP);
+               kmem_free(ph, phsize);
        }
 
 
@@ -235,11 +235,8 @@
                
        strcpy(esd.hw_platform, LINUX_PLATFORM); 
 
-       if (ap) {
-               free((char *)ap, M_TEMP);
-               pack->ep_emul_arg = NULL;
-       }
-       
+       exec_free_emul_arg(pack);
+
        /*
         * Copy out the ELF auxiliary table and hw platform name
         */
diff -r b3b28b5644bf -r e6048e5a8458 sys/compat/linux/arch/powerpc/linux_exec_powerpc.c
--- a/sys/compat/linux/arch/powerpc/linux_exec_powerpc.c        Fri Feb 03 19:29:59 2012 +0000
+++ b/sys/compat/linux/arch/powerpc/linux_exec_powerpc.c        Fri Feb 03 20:11:53 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: linux_exec_powerpc.c,v 1.22 2010/07/07 01:30:34 chs Exp $ */
+/* $NetBSD: linux_exec_powerpc.c,v 1.23 2012/02/03 20:11:53 matt Exp $ */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -41,14 +41,13 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_exec_powerpc.c,v 1.22 2010/07/07 01:30:34 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_exec_powerpc.c,v 1.23 2012/02/03 20:11:53 matt Exp $");
 
 #define ELFSIZE 32
 
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/kernel.h>
-#include <sys/malloc.h>
 #include <sys/proc.h>
 #include <sys/exec.h>
 #include <sys/exec_elf.h>
@@ -166,8 +165,7 @@
                a->a_v = LINUX_ELF_HWCAP;
                a++;
 
-               free((char *)ap, M_TEMP);
-               pack->ep_emul_arg = NULL;
+               exec_free_emul_arg(pack);
        }
 
        a->a_type = AT_NULL;
diff -r b3b28b5644bf -r e6048e5a8458 sys/compat/linux/common/linux_exec_elf32.c
--- a/sys/compat/linux/common/linux_exec_elf32.c        Fri Feb 03 19:29:59 2012 +0000
+++ b/sys/compat/linux/common/linux_exec_elf32.c        Fri Feb 03 20:11:53 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linux_exec_elf32.c,v 1.84 2010/09/11 20:49:28 chs Exp $        */
+/*     $NetBSD: linux_exec_elf32.c,v 1.85 2012/02/03 20:11:53 matt Exp $       */
 
 /*-
  * Copyright (c) 1995, 1998, 2000, 2001 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_exec_elf32.c,v 1.84 2010/09/11 20:49:28 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_exec_elf32.c,v 1.85 2012/02/03 20:11:53 matt Exp $");
 
 #ifndef ELFSIZE
 /* XXX should die */
@@ -442,8 +442,7 @@
                a->a_v = ap->arg_entry;
                a++;
 
-               free(pack->ep_emul_arg, M_TEMP);
-               pack->ep_emul_arg = NULL;
+               exec_free_emul_arg(pack);
        }
 
        /* Linux-specific items */
diff -r b3b28b5644bf -r e6048e5a8458 sys/compat/linux32/common/linux32_exec_elf32.c
--- a/sys/compat/linux32/common/linux32_exec_elf32.c    Fri Feb 03 19:29:59 2012 +0000
+++ b/sys/compat/linux32/common/linux32_exec_elf32.c    Fri Feb 03 20:11:53 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linux32_exec_elf32.c,v 1.12 2010/09/11 20:49:28 chs Exp $ */
+/*     $NetBSD: linux32_exec_elf32.c,v 1.13 2012/02/03 20:11:54 matt Exp $ */
 
 /*-                     
  * Copyright (c) 1995, 1998, 2000, 2001,2006 The NetBSD Foundation, Inc.
@@ -31,14 +31,13 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux32_exec_elf32.c,v 1.12 2010/09/11 20:49:28 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_exec_elf32.c,v 1.13 2012/02/03 20:11:54 matt Exp $");
 
 #define        ELFSIZE         32
 
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/proc.h>
-#include <sys/malloc.h>
 #include <sys/vnode.h>
 #include <sys/exec.h>
 #include <sys/exec_elf.h>
@@ -153,8 +152,7 @@
                a->a_v = ap->arg_entry;
                a++;
 
-               free(ap, M_TEMP);
-               pack->ep_emul_arg = NULL;
+               exec_free_emul_arg(pack);
        }
 
        /* Linux-specific items */
diff -r b3b28b5644bf -r e6048e5a8458 sys/compat/netbsd32/netbsd32_exec_elf32.c
--- a/sys/compat/netbsd32/netbsd32_exec_elf32.c Fri Feb 03 19:29:59 2012 +0000
+++ b/sys/compat/netbsd32/netbsd32_exec_elf32.c Fri Feb 03 20:11:53 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netbsd32_exec_elf32.c,v 1.34 2012/02/03 03:54:35 christos Exp $        */
+/*     $NetBSD: netbsd32_exec_elf32.c,v 1.35 2012/02/03 20:11:54 matt Exp $    */
 /*     from: NetBSD: exec_aout.c,v 1.15 1996/09/26 23:34:46 cgd Exp */
 
 /*
@@ -57,14 +57,13 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_exec_elf32.c,v 1.34 2012/02/03 03:54:35 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_exec_elf32.c,v 1.35 2012/02/03 20:11:54 matt Exp $");
 
 #define        ELFSIZE         32
 
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/proc.h>
-#include <sys/malloc.h>
 #include <sys/vnode.h>
 #include <sys/exec.h>
 #include <sys/exec_elf.h>
@@ -196,8 +195,7 @@
                a->a_v = kauth_cred_getgid(l->l_cred);
                a++;
 
-               kmem_free(ap, sizeof(*ap));
-               pack->ep_emul_arg = NULL;
+               exec_free_emul_arg(pack);
        }
 
        a->a_type = AT_NULL;
diff -r b3b28b5644bf -r e6048e5a8458 sys/compat/osf1/osf1_exec_ecoff.c
--- a/sys/compat/osf1/osf1_exec_ecoff.c Fri Feb 03 19:29:59 2012 +0000
+++ b/sys/compat/osf1/osf1_exec_ecoff.c Fri Feb 03 20:11:53 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: osf1_exec_ecoff.c,v 1.23 2010/06/24 13:03:07 hannken Exp $ */
+/* $NetBSD: osf1_exec_ecoff.c,v 1.24 2012/02/03 20:11:54 matt Exp $ */
 
 /*
  * Copyright (c) 1999 Christopher G. Demetriou.  All rights reserved.
@@ -31,12 +31,12 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: osf1_exec_ecoff.c,v 1.23 2010/06/24 13:03:07 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: osf1_exec_ecoff.c,v 1.24 2012/02/03 20:11:54 matt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/proc.h>
-#include <sys/malloc.h>
+#include <sys/kmem.h>
 #include <sys/namei.h>
 #include <sys/vnode.h>
 #include <sys/exec.h>
@@ -56,6 +56,7 @@
 };
 
 static int osf1_exec_ecoff_dynamic(struct lwp *l, struct exec_package *epp);
+static void osf1_free_emul_arg(void *);
 
 int
 osf1_exec_ecoff_probe(struct lwp *l, struct exec_package *epp)
@@ -69,8 +70,9 @@
                return ENOEXEC;
 
        /* set up the exec package emul arg as appropriate */
-       emul_arg = malloc(sizeof *emul_arg, M_TEMP, M_WAITOK);
+       emul_arg = kmem_alloc(sizeof(*emul_arg), KM_SLEEP);
        epp->ep_emul_arg = emul_arg;
+       epp->ep_emul_arg_free = osf1_free_emul_arg;
 
        emul_arg->flags = 0;
        /* this cannot overflow because both are size PATH_MAX */
@@ -97,8 +99,7 @@
        }
 
        if (error) {
-               free(epp->ep_emul_arg, M_TEMP);
-               epp->ep_emul_arg = NULL;
+               exec_free_emul_arg(epp);
                kill_vmcmds(&epp->ep_vmcmds);           /* if any */
        }
 
@@ -166,8 +167,7 @@
        *stackp += len;
 
 out:
-       free(pack->ep_emul_arg, M_TEMP);
-       pack->ep_emul_arg = NULL;
+       exec_free_emul_arg(pack);
        return error;
 }
 
@@ -294,3 +294,12 @@
        vrele(ldr_vp);
        return (error);
 }
+
+void
+osf1_free_emul_arg(void *arg)
+{
+       struct osf1_exec_emul_arg *emul_arg = arg;
+       KASSERT(emul_arg != NULL);
+
+       kmem_free(emul_arg, sizeof(*emul_arg));
+}
diff -r b3b28b5644bf -r e6048e5a8458 sys/compat/svr4_32/svr4_32_exec_elf32.c
--- a/sys/compat/svr4_32/svr4_32_exec_elf32.c   Fri Feb 03 19:29:59 2012 +0000
+++ b/sys/compat/svr4_32/svr4_32_exec_elf32.c   Fri Feb 03 20:11:53 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: svr4_32_exec_elf32.c,v 1.21 2010/05/02 05:30:20 dholland Exp $  */
+/*     $NetBSD: svr4_32_exec_elf32.c,v 1.22 2012/02/03 20:11:54 matt Exp $      */
 
 /*-
  * Copyright (c) 1994 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: svr4_32_exec_elf32.c,v 1.21 2010/05/02 05:30:20 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: svr4_32_exec_elf32.c,v 1.22 2012/02/03 20:11:54 matt Exp $");
 
 #define        ELFSIZE         32                              /* XXX should die */
 
@@ -38,7 +38,6 @@
 #include <sys/systm.h>
 #include <sys/kernel.h>
 #include <sys/proc.h>
-#include <sys/malloc.h>
 #include <sys/namei.h>
 #include <sys/vnode.h>
 #include <sys/exec_elf.h>
@@ -149,8 +148,7 @@
                        a++;
                }
 
-               free((char *)ap, M_TEMP);
-               pack->ep_emul_arg = NULL;



Home | Main Index | Thread Index | Old Index