From 783b1e025fdbca191115fb205b399f598cd9a727 Mon Sep 17 00:00:00 2001 From: Bahadir Balban Date: Tue, 25 Nov 2008 12:52:28 +0200 Subject: [PATCH] Added env and arg passing to execve --- tasks/mm0/include/exec.h | 6 ++++++ tasks/mm0/src/execve.c | 27 +++++++++++++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/tasks/mm0/include/exec.h b/tasks/mm0/include/exec.h index 8a66567..4ca1381 100644 --- a/tasks/mm0/include/exec.h +++ b/tasks/mm0/include/exec.h @@ -16,4 +16,10 @@ struct exec_file_desc { unsigned long bss_offset; /* File offset of bss section */ }; +struct args_struct { + int argc; + char **argv; + int size; /* Size of strings + string pointers */ +}; + #endif /* __EXEC_H__ */ diff --git a/tasks/mm0/src/execve.c b/tasks/mm0/src/execve.c index 634e121..b6ff116 100644 --- a/tasks/mm0/src/execve.c +++ b/tasks/mm0/src/execve.c @@ -82,7 +82,8 @@ int task_setup_from_executable(struct vm_file *vmfile, struct tcb *task, return elf_parse_executable(task, vmfile, efd); } -int do_execve(struct tcb *sender, char *filename) +int do_execve(struct tcb *sender, char *filename, struct args_struct *args, + struct args_struct *env) { unsigned long vnum, length; struct vm_file *vmfile; @@ -316,11 +317,6 @@ copy_user_ptrs(struct tcb *task, void *buf, char *user, return copy_user_buf(task, buf, user, maxlength, sizeof(unsigned long)); } -struct args_struct { - int argc; - char **argv; - int size; /* Size of strings + string pointers */ -}; int copy_user_args(struct tcb *task, struct args_struct *args, void *argv_user, int args_max) @@ -377,26 +373,33 @@ out: return count; } - int sys_execve(struct tcb *sender, char *pathname, char *argv[], char *envp[]) { int ret; char *path = kzalloc(PATH_MAX); struct args_struct args; + struct args_struct env; /* Copy the executable path string */ if ((ret = copy_user_string(sender, path, pathname, PATH_MAX)) < 0) return ret; printf("%s: Copied pathname: %s\n", __FUNCTION__, path); - /* Copy the env and args */ + /* Copy the args */ if ((ret = copy_user_args(sender, &args, argv, ARGS_MAX)) < 0) - return ret; + goto out1; - ret = do_execve(sender, path); + /* Copy the env */ + if ((ret = copy_user_args(sender, &env, envp, ARGS_MAX - args.size))) + goto out2; + + ret = do_execve(sender, path, &args, &env); + + kfree(env.argv); +out2: + kfree(args.argv); +out1: kfree(path); - return ret; } -