[CRIU] [PATCH 7/8] restore: Add restoration of alternative signal stack

Andrew Vagin avagin at parallels.com
Tue Jun 18 05:55:39 EDT 2013


On Tue, Jun 18, 2013 at 10:06:57AM +0400, Cyrill Gorcunov wrote:
> 
> [alekskartashov@: use RT_SIGFRAME_UC]
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
>  cr-restore.c       |  7 +++++++
>  include/restorer.h |  3 +++
>  include/sigframe.h | 16 ++++++++++++++++
>  pie/restorer.c     |  9 +++++++++
>  sigframe.c         |  2 ++
>  5 files changed, 37 insertions(+)
> 

> diff --git a/cr-restore.c b/cr-restore.c
> index d62c598..24885f1 100644
> --- a/cr-restore.c
> +++ b/cr-restore.c
> @@ -2031,6 +2031,13 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core)
>  	if (prepare_rlimits(pid, task_args))
>  		goto err;
>  
> +	if (core->sas) {
> +		task_args->has_sas = true;
> +		task_args->sas = *core->sas;
> +	} else {
> +		task_args->has_sas = false;
> +	}
> +
>  	/*
>  	 * Fill up per-thread data.
>  	 */
> diff --git a/include/restorer.h b/include/restorer.h
> index a5c0667..c69d4d1 100644
> --- a/include/restorer.h
> +++ b/include/restorer.h
> @@ -133,6 +133,9 @@ struct task_restore_core_args {
>  
>  	struct vdso_symtable		vdso_sym_rt;		/* runtime vdso symbols */
>  	unsigned long			vdso_rt_parked_at;	/* safe place to keep vdso */
> +
> +	bool				has_sas;
> +	ThreadSasEntry			sas;
>  } __aligned(sizeof(long));
>  
>  #define SHMEMS_SIZE	4096
> diff --git a/include/sigframe.h b/include/sigframe.h
> index afc2c9d..bb5a43c 100644
> --- a/include/sigframe.h
> +++ b/include/sigframe.h
> @@ -5,6 +5,8 @@
>  #ifndef __CR_SIGFRAME_H__
>  #define __CR_SIGFRAME_H__
>  
> +#include "protobuf/core.pb-c.h"
> +
>  struct rt_sigframe;
>  
>  #ifndef __ARCH_SI_PREAMBLE_SIZE
> @@ -43,4 +45,18 @@ extern int construct_sigframe(struct rt_sigframe *sigframe,
>  			      struct rt_sigframe *rsigframe,
>  			      CoreEntry *core);
>  
> +/*
> + * FIXME Convert it to inline helper, which requires
> + *	 to unweave types mess we've generated for
> + *	 run-time data.
> + */
> +#define setup_sas(sigframe, sas)															\
> +do {																						\
> +	if ((sas)) {																			\
> +		RT_SIGFRAME_UC((sigframe)).uc_stack.ss_sp	= (void *)decode_pointer((sas)->ss_sp);	\
> +		RT_SIGFRAME_UC((sigframe)).uc_stack.ss_flags= (int)(sas)->ss_flags;					\
> +		RT_SIGFRAME_UC((sigframe)).uc_stack.ss_size	= (size_t)(sas)->ss_size;				\
> +	}																						\
> +} while (0)
> +
>  #endif /* __CR_SIGFRAME_H__ */
> diff --git a/pie/restorer.c b/pie/restorer.c
> index 06b24a9..ddac648 100644
> --- a/pie/restorer.c
> +++ b/pie/restorer.c
> @@ -733,6 +733,15 @@ long __export_restore_task(struct task_restore_core_args *args)
>  		goto core_restore_end;
>  
>  	/*
> +	 * FIXME
> +	 * Alternative signal stack for the group leader
> +	 * is setting up separately from the threads.
> +	 * This better should be unified one day.
> +	 */
> +	if (args->has_sas)
> +		setup_sas(rt_sigframe, &args->sas);
> +

I think would be better if setup_sas will be called after restore_signals,
because before this moment SIGCHLD isn't blocked.

Can you explain how that works for nested signal handlers?

> +	/*
>  	 * Threads restoration. This requires some more comments. This
>  	 * restorer routine and thread restorer routine has the following
>  	 * memory map, prepared by a caller code.
> diff --git a/sigframe.c b/sigframe.c
> index 68c9776..5d19be6 100644
> --- a/sigframe.c
> +++ b/sigframe.c
> @@ -31,5 +31,7 @@ int construct_sigframe(struct rt_sigframe *sigframe,
>  	if (restore_gpregs(sigframe, CORE_THREAD_ARCH_INFO(core)->gpregs))
>  		return -1;
>  
> +	setup_sas(sigframe, core->sas);
> +
>  	return 0;
>  }



More information about the CRIU mailing list