From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1d9v4Z-0008LX-KQ for user-mode-linux-devel@lists.sourceforge.net; Sun, 14 May 2017 15:04:39 +0000 Received: from www17.your-server.de ([213.133.104.17]) by sog-mx-2.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1d9v4Y-0000jm-DO for user-mode-linux-devel@lists.sourceforge.net; Sun, 14 May 2017 15:04:39 +0000 Received: from [95.222.29.91] (helo=localhost.localdomain) by www17.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.85_2) (envelope-from ) id 1d9v4S-0003s2-Ag for user-mode-linux-devel@lists.sourceforge.net; Sun, 14 May 2017 17:04:32 +0200 Message-ID: <1494774234.13299.6.camel@m3y3r.de> From: Thomas Meyer Date: Sun, 14 May 2017 17:03:54 +0200 Mime-Version: 1.0 Subject: [uml-devel] [PATCH 3/3] um: Add kerneldoc for userspace_tramp() and start_userspace() List-Id: The user-mode Linux development list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============6477856367412019934==" Errors-To: user-mode-linux-devel-bounces@lists.sourceforge.net To: "user-mode-linux-devel@lists.sourceforge.net" --===============6477856367412019934== Content-Type: multipart/alternative; boundary="=-s+bYGRwGZxoUIFMYq70B" --=-s+bYGRwGZxoUIFMYq70B Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Also use correct function name spelling (stub_segv_handler) for better grepping Signed-off-by: Thomas Meyer ---  arch/um/os-Linux/skas/process.c | 31 ++++++++++++++++++++++++++++++-  1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os- Linux/skas/process.c index 03b3c4c..4530867 100644 --- a/arch/um/os-Linux/skas/process.c +++ b/arch/um/os-Linux/skas/process.c @@ -108,7 +108,7 @@ static void get_skas_faultinfo(int pid, struct faultinfo *fi)   wait_stub_done(pid);     /* -  * faultinfo is prepared by the stub-segv-handler at start of +  * faultinfo is prepared by the stub_segv_handler at start of    * the stub stack page. We just have to copy it.    */   memcpy(fi, (void *)current_stub_stack(), sizeof(*fi)); @@ -175,6 +175,21 @@ static void handle_trap(int pid, struct uml_pt_regs *regs,    extern char __syscall_stub_start[];   +/** + * userspace_tramp() - userspace trampoline + * @stack: pointer to the new userspace stack page, can be NULL, if? FIXME: + * + * The userspace trampoline is used to setup a new userspace process in start_userspace() after it was clone()'ed. + * This function will run on a temporary stack page. + * It ptrace()'es itself, then + * Two pages are mapped into the userspace address space: + * - STUB_CODE (with EXEC), which contains the skas stub code + * - STUB_DATA (with R/W), which contains a data page that is used to transfer certain data between the UML userspace process and the UML kernel. + * Also for the userspace process a SIGSEGV handler is installed to catch pagefaults in the userspace process. + * And last the process stops itself to give control to the UML kernel for this userspace process. + * + * Return: Always zero, otherwise the current userspace process is ended with non null exit() call + */  static int userspace_tramp(void *stack)  {   void *addr; @@ -236,12 +251,24 @@ static int userspace_tramp(void *stack)    int userspace_pid[NR_CPUS];   +/** + * start_userspace() - prepare a new userspace process + * @stub_stack: pointer to the stub stack. Can be NULL, if? FIXME: + * + * Setups a new temporary stack page that is used while userspace_tramp() runs + * Clones the kernel process into a new userspace process, with FDs only. + * + * Return: When positive: the process id of the new userspace process, + *         when negative: an error number. + * FIXME: can PIDs become negative?! + */  int start_userspace(unsigned long stub_stack)  {   void *stack;   unsigned long sp;   int pid, status, n, flags, err;   + /* setup a temporary stack page */   stack = mmap(NULL, UM_KERN_PAGE_SIZE,        PROT_READ | PROT_WRITE | PROT_EXEC,        MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); @@ -252,10 +279,12 @@ int start_userspace(unsigned long stub_stack)   return err;   }   + /* set stack pointer to the end of the stack page, so it can grow downwards */   sp = (unsigned long) stack + UM_KERN_PAGE_SIZE - sizeof(void *);     flags = CLONE_FILES | SIGCHLD;   + /* clone into new userspace process */   pid = clone(userspace_tramp, (void *) sp, flags, (void *) stub_stack);   if (pid < 0) {   err = -errno; --=-s+bYGRwGZxoUIFMYq70B Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable
Also use correct function name spelling (stub_segv_handler)= for better
grepping

Signed-off-by: Thomas Meyer <thomas@= m3y3r.de>
---
 arch/um/os-Linux/skas/process.c | 31 +++++++++++++++++++++++++= +++++-
=  1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/arch/um/os-Linux/= skas/process.c b/arch/um/os-
Linux/skas/process= .c
inde= x 03b3c4c..4530867 100644
--- a/arch/um/os-Linux/skas/process.c
+++ b/arch/um/os-Linux/sk= as/process.c
@@ -108,7 +108,7 @@ static void get_skas_faultinfo(int pid, struct
faultinfo *fi= )
 = ; wait_stub= _done(pid);
 
  /*
-  * faul= tinfo is prepared by the stub-segv-handler at start of
+  * faultinfo is prepared by the= stub_segv_handler at start of
   * the stub stack page. We just have to copy it.
   */
  memcpy(fi, (vo= id *)current_stub_stack(), sizeof(*fi));
@@ -175,6 +175,21 @@ static void handle_t= rap(int pid, struct
uml_pt_regs *regs,
 
 extern char __syscall_stub_start[];
 
+/**
+ * userspace_tramp()= - userspace trampoline
+ * @stack: pointer to the new userspace stack page, can be
NULL, if? FIXME:
+ *
=
+ * The user= space trampoline is used to setup a new userspace process
in start_userspace() after i= t was clone()'ed.
+ * This function will run on a temporary stack page.
+ * It ptrace()'e= s itself, then
+ * Two pages are mapped into the userspace address space:
+ * - STUB_CODE= (with EXEC), which contains the skas stub code
+ * - STUB_DATA (with R/W), which = contains a data page that is used totransfer certain data between the UML userspace p= rocess and the UML
kernel.
+ * Also for the userspace process a SIGSEGV handler is installed = to
catch pa= gefaults in the userspace process.
+ * And last the process stops itself to give = control to the UML kernel
for this userspace process.
+ *
+ * Return: Always zero, otherwise the cur= rent userspace process is
ended with non null exit() call
+ */
 static int userspace_tramp(vo= id *stack)
 {
  void *addr;
@@ -236,12 +251,24 @@ static int userspace_tramp(void *stack)
 
 int user= space_pid[NR_CPUS];
 
+/**
+ * start_userspace() - prepare a new userspace process
+ * @stub_stack= : pointer t= o the stub stack. Can be NULL, if?
FIXME:
+ *
+ * Setups a new temporary stack page that is used whi= le
userspac= e_tramp() runs
+ * Clones the kernel process into a new userspace process, with FD= s
only.
+ *
<= div data-evo-paragraph=3D"" class=3D"" style=3D"width: 71ch;">+ * Return: W= hen positive: the process id of the new userspace process,
+ *   &n= bsp;     when negative: an error number.
+ * FIXME: can P= IDs become negative?!
+ */
 int start_userspace(unsigned long stub_stack)
 {
  void *stack;  unsigned long sp;<= /div>
 <= span class=3D"Apple-tab-span" style=3D"white-space:pre"> int pid, st= atus, n, flags, err;
 
+ /* setup a temporary stack page */
  stack =3D mmap(NULL, UM_KERN_PAGE_SIZE,
<= div data-evo-paragraph=3D"" class=3D"" style=3D"width: 71ch;">      &nb= sp;PROT_READ | PROT_WRITE | PROT_EXEC,
       MAP_PRIVATE | MAP_ANONYMOU= S, -1, 0);
@@ -252,10 +279,12 @@ int start_userspace(unsigned long stub_stack)
  return err;
  }
 
+ /* set stack pointer to the end of = the stack page, so it can
grow downwards */
  sp =3D (unsigned long) stack + UM_KERN_PAGE_SIZE - si= zeof(void
*= );
&nbs= p;
&nbs= p; flags = =3D CLONE_FILES | SIGCHLD;
 
+ /* clone into new userspace process */
  pid =3D clone(userspace_tramp, (void= *) sp, flags, (void *)
stub_stack);
  if (pid < 0) {
  err =3D -errno;
--=-s+bYGRwGZxoUIFMYq70B-- --===============6477856367412019934== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot --===============6477856367412019934== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ User-mode-linux-devel mailing list User-mode-linux-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel --===============6477856367412019934==--