[PATCH] restore: Add restoration of alternative signal stack
Cyrill Gorcunov
gorcunov at openvz.org
Mon Jun 17 12:34:00 EDT 2013
To restore SAS we have two ways:
- call for sigaltstack explicitly in restorer.c right before we call for sigreturn
- pass stack value to sigreturn call and allow the kernel to restore stack for us
Since second way is a simplier one -- we stick with it.
[alekskartashov@: use RT_SIGFRAME_UC]
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
CC: Alexander Kartashov <alekskartashov at parallels.com>
---
cr-restore.c | 5 +++++
include/restorer.h | 2 ++
include/sigframe.h | 17 +++++++++++++++++
pie/restorer.c | 9 +++++++++
sigframe.c | 12 ++++++++++++
5 files changed, 45 insertions(+)
diff --git a/cr-restore.c b/cr-restore.c
index 2146da2..b9beb02 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -2153,6 +2153,11 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core)
if (prepare_rlimits(pid, task_args))
goto err;
+ if (core->thread_core->sas)
+ task_args->sas = *core->thread_core->sas;
+ else
+ task_args->sas.ss_sp = (u64)SAS_INVALID_SP;
+
/*
* Fill up per-thread data.
*/
diff --git a/include/restorer.h b/include/restorer.h
index 8a796a5..073dec9 100644
--- a/include/restorer.h
+++ b/include/restorer.h
@@ -153,6 +153,8 @@ 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 */
+
+ ThreadSasEntry sas;
} __aligned(sizeof(long));
#define SHMEMS_SIZE 4096
diff --git a/include/sigframe.h b/include/sigframe.h
index afc2c9d..65edaa4 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,19 @@ extern int construct_sigframe(struct rt_sigframe *sigframe,
struct rt_sigframe *rsigframe,
CoreEntry *core);
+#define SAS_INVALID_SP (-1ull)
+/*
+ * 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 f1b1ca2..1cacb79 100644
--- a/pie/restorer.c
+++ b/pie/restorer.c
@@ -784,6 +784,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->sas.ss_sp != (u64)SAS_INVALID_SP)
+ setup_sas(rt_sigframe, &args->sas);
+
+ /*
* 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..053bdf0 100644
--- a/sigframe.c
+++ b/sigframe.c
@@ -31,5 +31,17 @@ int construct_sigframe(struct rt_sigframe *sigframe,
if (restore_gpregs(sigframe, CORE_THREAD_ARCH_INFO(core)->gpregs))
return -1;
+ /*
+ * On restore we have 2 ways for sas
+ * - either call for sigaltstack explicitly in restorer.c right before
+ * we call for sigreturn
+ *
+ * - either pass stack value to sigreturn call and allow the kernel to
+ * restore stack for us
+ *
+ * Second way looks more clean and simple, and here we go.
+ */
+ setup_sas(sigframe, core->thread_core->sas);
+
return 0;
}
--
1.8.1.4
--kfjH4zxOES6UT95V--
More information about the CRIU
mailing list