plain text document attachment (ckrm_utils_copy_args.patch)
Patch: ckrm_utils_copy_args.patch
Description:

Add a function that will copy the arguments of a task into a newly-allocated
chunk of kernel memory.

Signed-Off-By: Matt Helsley <[EMAIL PROTECTED]>

%patch
Index: linux-2.6.12-rc3/kernel/ckrm/ckrmutils.c
===================================================================
--- linux-2.6.12-rc3.orig/kernel/ckrm/ckrmutils.c       2005-05-10 
17:19:11.000000000 -0700
+++ linux-2.6.12-rc3/kernel/ckrm/ckrmutils.c    2005-05-10 17:19:21.000000000 
-0700
@@ -15,12 +15,69 @@
  */
 
 #include <linux/err.h>
 #include <linux/mount.h>
 #include <linux/module.h>
+#include <asm/uaccess.h> /* for strnlen_user and strncpy_from_user */
+#include <linux/vmalloc.h>
 #include <linux/ckrm_rc.h>
 
+/*
+ * Copy the first n arguments from the task into kernel memory and return
+ * it as an argv[] array -- an array of character pointers whose last pointer
+ * is NULL.
+ *
+ * Caller takes responsibility for freeing the memory with vfree()
+ * tsk must be current
+ *
+ *  returns NULL on error
+ */
+char** copy_task_args (struct task_struct *tsk, int n)
+{
+       char *uarg = NULL, *karg = NULL;
+       char **argv = NULL;
+       size_t len = 0;
+       struct mm_struct *mm = NULL;
+       int i;
+
+       mm = get_task_mm(tsk);
+       if (mm == NULL)
+               return NULL;
+
+       /* Get the size of the arguments */
+       i = n;
+       uarg = (char*)mm->arg_start;
+       for(; i && (len < (mm->arg_end - mm->arg_start)); i--){
+               size_t slen = strnlen_user(uarg, PAGE_SIZE - 1) + 1;
+               len += slen;
+               uarg += slen;
+       }
+
+       /* Allocate some space for the copy */
+       argv = vmalloc(len + (n + 1) * sizeof(char*));
+       if (argv == NULL)
+               goto return_result;
+       karg = (char*)argv;
+       karg += sizeof(char*) * (n + 1);
+
+       /* Make the copy */
+       uarg = (char*)mm->arg_start;
+       for (i = 0; i < n; i++){
+               size_t slen = strnlen_user(uarg, PAGE_SIZE - 1);
+               argv[i] = karg;
+               strncpy_from_user(karg, uarg, slen);
+               karg[slen] = '\0';
+               uarg += slen;
+               karg += slen;
+       }
+       argv[n] = NULL;
+return_result:
+       mmput(mm);
+       return argv;
+}
+
+
 /*
  * TODO:  Use sparce to enforce cnt_lock.
  *
  * must be called with cnt_lock of parres held
  * Caller is responsible for making sure that the new guarantee doesn't
@@ -148,8 +205,9 @@ set_shares(struct ckrm_shares *new, stru
        rc = 0;
 set_share_err:
        return rc;
 }
 
+EXPORT_SYMBOL(copy_task_args);
 EXPORT_SYMBOL_GPL(child_guarantee_changed);
 EXPORT_SYMBOL_GPL(child_maxlimit_changed);
 EXPORT_SYMBOL_GPL(set_shares);

--



-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
Search APIs Find out how you can build Yahoo! directly into your own
Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005
_______________________________________________
ckrm-tech mailing list
https://lists.sourceforge.net/lists/listinfo/ckrm-tech

Reply via email to