From 269f667cb07a4e783d3043b3d08628fb35da4848 Mon Sep 17 00:00:00 2001 From: eeh Date: Sun, 6 Sep 1998 04:34:49 +0000 Subject: [PATCH] Copyout 32-bit args. --- sys/compat/netbsd32/netbsd32_exec.c | 48 +++++++++++++++++++++++++++-- sys/compat/sparc32/sparc32_exec.c | 48 +++++++++++++++++++++++++++-- 2 files changed, 92 insertions(+), 4 deletions(-) diff --git a/sys/compat/netbsd32/netbsd32_exec.c b/sys/compat/netbsd32/netbsd32_exec.c index 35315ec2831d..b9f435526b74 100644 --- a/sys/compat/netbsd32/netbsd32_exec.c +++ b/sys/compat/netbsd32/netbsd32_exec.c @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_exec.c,v 1.4 1998/08/30 15:32:19 eeh Exp $ */ +/* $NetBSD: netbsd32_exec.c,v 1.5 1998/09/06 04:34:49 eeh Exp $ */ /* from: NetBSD: exec_aout.c,v 1.15 1996/09/26 23:34:46 cgd Exp */ /* @@ -62,6 +62,7 @@ void sparc32_setregs __P((struct proc *, struct exec_package *, u_long)); static int sparc32_exec_aout_prep_zmagic __P((struct proc *, struct exec_package *)); static int sparc32_exec_aout_prep_nmagic __P((struct proc *, struct exec_package *)); static int sparc32_exec_aout_prep_omagic __P((struct proc *, struct exec_package *)); +void *sparc32_copyargs __P((struct exec_package *, struct ps_strings *, void *, void *)); struct emul emul_sparc32 = { "sparc32", @@ -76,7 +77,7 @@ struct emul emul_sparc32 = { NULL, #endif 0, - copyargs, + sparc32_copyargs, sparc32_setregs, /* XXX needs to be written?? */ sigcode, esigcode, @@ -485,3 +486,46 @@ sparc32_sendsig(catcher, sig, mask, code) #endif } +void * +sparc32_copyargs(pack, arginfo, stack, argp) + struct exec_package *pack; + struct ps_strings *arginfo; + void *stack; + void *argp; +{ + char **cpp = stack; + char *dp, *sp; + size_t len; + void *nullp = NULL; + int argc = arginfo->ps_nargvstr; + int envc = arginfo->ps_nenvstr; + + if (copyout(&argc, cpp++, sizeof(argc))) + return NULL; + + dp = (char *) (cpp + argc + envc + 2 + pack->ep_emul->e_arglen); + sp = argp; + + /* XXX don't copy them out, remap them! */ + arginfo->ps_argvstr = cpp; /* remember location of argv for later */ + + for (; --argc >= 0; sp += len, dp += len) + if (suword(cpp++, (long)dp) || + copyoutstr(sp, dp, ARG_MAX, &len)) + return NULL; + + if (suword(cpp++, 0)) + return NULL; + + arginfo->ps_envstr = cpp; /* remember location of envp for later */ + + for (; --envc >= 0; sp += len, dp += len) + if (suword(cpp++, (long)dp) || + copyoutstr(sp, dp, ARG_MAX, &len)) + return NULL; + + if (suword(cpp++, NULL)) + return NULL; + + return cpp; +} diff --git a/sys/compat/sparc32/sparc32_exec.c b/sys/compat/sparc32/sparc32_exec.c index 8ed0aa353b93..c0384ed8708d 100644 --- a/sys/compat/sparc32/sparc32_exec.c +++ b/sys/compat/sparc32/sparc32_exec.c @@ -1,4 +1,4 @@ -/* $NetBSD: sparc32_exec.c,v 1.4 1998/08/30 15:32:19 eeh Exp $ */ +/* $NetBSD: sparc32_exec.c,v 1.5 1998/09/06 04:34:49 eeh Exp $ */ /* from: NetBSD: exec_aout.c,v 1.15 1996/09/26 23:34:46 cgd Exp */ /* @@ -62,6 +62,7 @@ void sparc32_setregs __P((struct proc *, struct exec_package *, u_long)); static int sparc32_exec_aout_prep_zmagic __P((struct proc *, struct exec_package *)); static int sparc32_exec_aout_prep_nmagic __P((struct proc *, struct exec_package *)); static int sparc32_exec_aout_prep_omagic __P((struct proc *, struct exec_package *)); +void *sparc32_copyargs __P((struct exec_package *, struct ps_strings *, void *, void *)); struct emul emul_sparc32 = { "sparc32", @@ -76,7 +77,7 @@ struct emul emul_sparc32 = { NULL, #endif 0, - copyargs, + sparc32_copyargs, sparc32_setregs, /* XXX needs to be written?? */ sigcode, esigcode, @@ -485,3 +486,46 @@ sparc32_sendsig(catcher, sig, mask, code) #endif } +void * +sparc32_copyargs(pack, arginfo, stack, argp) + struct exec_package *pack; + struct ps_strings *arginfo; + void *stack; + void *argp; +{ + char **cpp = stack; + char *dp, *sp; + size_t len; + void *nullp = NULL; + int argc = arginfo->ps_nargvstr; + int envc = arginfo->ps_nenvstr; + + if (copyout(&argc, cpp++, sizeof(argc))) + return NULL; + + dp = (char *) (cpp + argc + envc + 2 + pack->ep_emul->e_arglen); + sp = argp; + + /* XXX don't copy them out, remap them! */ + arginfo->ps_argvstr = cpp; /* remember location of argv for later */ + + for (; --argc >= 0; sp += len, dp += len) + if (suword(cpp++, (long)dp) || + copyoutstr(sp, dp, ARG_MAX, &len)) + return NULL; + + if (suword(cpp++, 0)) + return NULL; + + arginfo->ps_envstr = cpp; /* remember location of envp for later */ + + for (; --envc >= 0; sp += len, dp += len) + if (suword(cpp++, (long)dp) || + copyoutstr(sp, dp, ARG_MAX, &len)) + return NULL; + + if (suword(cpp++, NULL)) + return NULL; + + return cpp; +}