Linux Container Development
 help / color / mirror / Atom feed
From: Oren Laadan <orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
To: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
Cc: Louis Rilling
	<Louis.Rilling-aw0BnHfMbSpBDgjK7y7TUQ@public.gmane.org>,
	Alexey Dobriyan
	<adobriyan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Dave Hansen
	<dave-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Subject: Re: [PATCH] user-cr: eclone x86-64 wrapper
Date: Sun, 06 Dec 2009 15:35:36 -0500	[thread overview]
Message-ID: <4B1C1598.1020200@cs.columbia.edu> (raw)
In-Reply-To: <1260131469-2917-3-git-send-email-orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>


To test this, you need to update the kernel headers for user-cr
	$ scripts/extract_headers -s PATH_TO_CR_KERNEL

Oren.

Oren Laadan wrote:
> Signed-off-by: Oren Laadan <orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
> ---
>  clone_x86_64.c |   88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 88 insertions(+), 0 deletions(-)
>  create mode 100644 clone_x86_64.c
> 
> diff --git a/clone_x86_64.c b/clone_x86_64.c
> new file mode 100644
> index 0000000..d6d7e6f
> --- /dev/null
> +++ b/clone_x86_64.c
> @@ -0,0 +1,88 @@
> +/*
> + *  clone_x86_64.c: support for eclone() on x86_64
> + *
> + *  Copyright (C) Oren Laadan <orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
> + *  Copyright (C) Dave Hansen <daveh-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
> + *
> + *  This file is subject to the terms and conditions of the GNU General Public
> + *  License.  See the file COPYING in the main directory of the Linux
> + *  distribution for more details.
> + */
> +
> +#define _GNU_SOURCE
> +
> +#include <unistd.h>
> +#include <errno.h>
> +#include <sys/types.h>
> +#include <sys/syscall.h>
> +#include <asm/unistd.h>
> +
> +/*
> + * libc doesn't support eclone() yet...
> + * below is arch-dependent code to use the syscall
> + */
> +#include <linux/checkpoint.h>
> +
> +#include "eclone.h"
> +
> +#ifndef __NR_eclone
> +#define __NR_eclone 299
> +#endif
> +
> +int eclone(int (*fn)(void *), void *fn_arg, int clone_flags_low,
> +	   struct clone_args *clone_args, pid_t *pids)
> +{
> +	struct clone_args my_args;
> +	long retval;
> +	void **newstack;
> +
> +	if (clone_args->child_stack) {
> +		/*
> +		 * Set up the stack for child:
> +		 *  - fn_arg will be the argument for the child function
> +		 *  - the fn pointer will be loaded into ebx after the clone
> +		 */
> +		newstack = (void **)(unsigned long)(clone_args->child_stack +
> +					    clone_args->child_stack_size);
> +		*--newstack = fn_arg;
> +		*--newstack = fn;
> +	} else
> +		newstack = (void **)0;
> +
> +	my_args = *clone_args;
> +	my_args.child_stack = (unsigned long)newstack;
> +	my_args.child_stack_size = 0;
> +
> +        __asm__  __volatile__(
> +		"movq %6, %%r10\n\t"	/* pids in r10*/
> +		"syscall\n\t"		/* Linux/x86_64 system call */
> +		"testq %0,%0\n\t"	/* check return value */
> +		"jne 1f\n\t"		/* jump if parent */
> +		"popq %%rax\n\t"	/* get subthread function */
> +		"popq %%rdi\n\t"	/* get the subthread function arg */
> +		"call *%%rax\n\t"	/* start subthread function */
> +		"movq %2,%0\n\t"
> +		"syscall\n"		/* exit system call: exit subthread */
> +		"1:\n\t"
> +		:"=a" (retval)
> +		:"0" (__NR_eclone), "i" (__NR_exit),
> +		 "D" (clone_flags_low),	/* rdi */
> +		 "S" (&my_args),	/* rsi */
> +		 "d" (sizeof(my_args)),	/* rdx */
> +		 "m" (pids)		/* gets moved to r10 */
> +		:"rcx", "r10", "r11", "cc"
> +		);
> +				        /*
> +         * glibc lists 'cc' as clobbered, so we might as
> +	 * well do it too.  'r11' and 'rcx' are clobbered
> +	 * by the 'syscall' instruction itself.  'r8' and
> +	 * 'r9' are clobbered by the clone, but that
> +	 * thread will exit before getting back out to C.
> +         */
> +
> +	if (retval < 0) {
> +		errno = -retval;
> +		retval = -1;
> +	}
> +	return retval;
> +}

  parent reply	other threads:[~2009-12-06 20:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-06 20:31 c/r: support for x86-64 arch Oren Laadan
     [not found] ` <1260131469-2917-1-git-send-email-orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2009-12-06 20:31   ` [PATCH 1/2] c/r: [x86_32] sys_restore to use ptregs prototype Oren Laadan
     [not found]     ` <1260131469-2917-2-git-send-email-orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2009-12-06 20:31       ` [PATCH] user-cr: eclone x86-64 wrapper Oren Laadan
     [not found]         ` <1260131469-2917-3-git-send-email-orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2009-12-06 20:31           ` [PATCH 2/2] c/r: x86-64: checkpoint/restart implementation Oren Laadan
2009-12-06 20:35           ` Oren Laadan [this message]
2009-12-06 22:51       ` [PATCH 1/2] c/r: [x86_32] sys_restore to use ptregs prototype Oren Laadan
     [not found]         ` <4B1C357C.2090003-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2009-12-07 20:55           ` Nathan Lynch
     [not found]             ` <1260219307.7151.3.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2009-12-09 16:52               ` Serge E. Hallyn
2009-12-09 17:02               ` Serge E. Hallyn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B1C1598.1020200@cs.columbia.edu \
    --to=orenl-eqauephvms7envbuuze7ea@public.gmane.org \
    --cc=Louis.Rilling-aw0BnHfMbSpBDgjK7y7TUQ@public.gmane.org \
    --cc=adobriyan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=dave-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox