[Devel] Re: clone_with_pids() library interface

Oren Laadan orenl at cs.columbia.edu
Mon Jun 8 01:25:54 PDT 2009


Coindicentally I also got it to run. The prototype is in agreement
with the usual clone() prototype.

#if defined(__i386__) && defined(__NR_clone_with_pids)
/*
 * libc doesn't support clone_with_pid() yet...
 * (see: http://lkml.indiana.edu/hypermail/linux/kernel/9604.3/0204.html)
 */
static int clone_with_pids(int (*fn)(void *), void *child_stack, int flags,
			   struct target_pid_set *target_pids, void *arg)
{
	long retval;
	void **newstack;

	/*
	 * Set up the stack for child:
	 *  - the (void *) arg will be the argument for the child function
	 *  - the fn pointer will be loaded into ebx after the clone
	 */
	newstack = (void **) child_stack;
	*--newstack = arg;
	*--newstack = fn;

	__asm__  __volatile__(
		 "movl %0, %%ebx\n\t"		/* flags -> 1st (ebx) */
		 "movl %1, %%ecx\n\t"		/* newstack -> 2nd (ecx)*/
		 "xorl %%edi, %%edi\n\t"	/* 0 -> edi */
		 "xorl %%edx, %%edx\n\t"	/* 0 -> edx */
		 "pushl %%ebp\n\t"		/* save value of ebp */
		 "movl %2, %%ebp\n\t"		/* flags -> 6th (ebp) */
		:
		:"b" (flags),
		 "c" (newstack),
		 "r" (target_pids)
		);

	__asm__ __volatile__(
		 "int $0x80\n\t"	/* Linux/i386 system call */
		 "testl %0,%0\n\t"	/* check return value */
		 "jne 1f\n\t"		/* jump if parent */
		 "popl %%ebx\n\t"	/* get subthread function */
		 "call *%%ebx\n\t"	/* start subthread function */
		 "movl %2,%0\n\t"
		 "int $0x80\n"		/* exit system call: exit subthread */
		 "1:\n\t"
		 "popl %%ebp\t"		/* restore parent's ebp */
		:"=a" (retval)
		:"0" (__NR_clone_with_pids), "i" (__NR_exit)
		:"ebx", "ecx"
		);

	if (retval < 0) {
		errno = -retval;
		retval = -1;
	}
	return retval;
}
#endif

I added it to mktree.c and commited to user-cr.git :: ckpt-v16-dev,
I also added the clone_with_pids patches to linux-cr.git :: ckpt-v16-dev

It works well when not in a new namespace (mktree --pids < ckpt.image)
assuming the the pids are avaiable.

It doesn't work yet when in a new namespace, as the kernel code needs
to be adjusted (for the restarting tasks to find the coordintor in an
ancestor namespace).

Oren.


On Fri, 5 Jun 2009, Sukadev Bhattiprolu wrote:

> 
> Attached are two files -
> 
> 	cwp.c 		- implements clone_with_pids() library interface
> 	cwp-test.c	- a simple program to test the interface
> 
> There maybe more optimal ways of implementing it though :-)
> 
> If it makes sense, will submit as a patch to user-cr tree.
> 
> Sukadev
> 
_______________________________________________
Containers mailing list
Containers at lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/containers




More information about the Devel mailing list