[CRIU] [PATCH 1/2] define macro for stack alignment
Vijaya Kumar K
Vijaya.Kumar at caviumnetworks.com
Wed Dec 30 08:56:41 PST 2015
Replace stack alignment magic constant with
__stack_aligned__ macro.
Also align stack for sigaltstack test case.
Signed-off-by: Vijaya Kumar K <vijayak at caviumnetworks.com>
---
cr-check.c | 2 +-
cr-restore.c | 2 +-
include/compiler.h | 6 ++++++
include/restorer.h | 2 +-
test/zdtm/lib/ns.c | 3 ++-
test/zdtm/lib/zdtmtst.h | 6 ++++++
test/zdtm/live/static/fdt_shared.c | 2 +-
test/zdtm/live/static/mntns_link_remap.c | 2 +-
test/zdtm/live/static/mntns_open.c | 2 +-
test/zdtm/live/static/mountpoints.c | 2 +-
test/zdtm/live/static/session02.c | 2 +-
test/zdtm/live/static/session03.c | 2 +-
test/zdtm/live/static/sigaltstack.c | 4 ++--
13 files changed, 25 insertions(+), 12 deletions(-)
diff --git a/cr-check.c b/cr-check.c
index ee35568..6ecc998 100644
--- a/cr-check.c
+++ b/cr-check.c
@@ -808,7 +808,7 @@ struct clone_arg {
* Reserve some space for clone() to locate arguments
* and retcode in this place
*/
- char stack[128] __attribute__((aligned (16)));
+ char stack[128] __stack_aligned__;
char stack_ptr[0];
};
diff --git a/cr-restore.c b/cr-restore.c
index e12207f..f9621b6 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -1075,7 +1075,7 @@ struct cr_clone_arg {
* Reserve some space for clone() to locate arguments
* and retcode in this place
*/
- char stack[128] __attribute__((aligned (16)));
+ char stack[128] __stack_aligned__;
char stack_ptr[0];
struct pstree_item *item;
unsigned long clone_flags;
diff --git a/include/compiler.h b/include/compiler.h
index 894393e..6bce935 100644
--- a/include/compiler.h
+++ b/include/compiler.h
@@ -38,6 +38,12 @@
#define __aligned(x) __attribute__((aligned(x)))
+/*
+ * Macro to define stack alignment.
+ * aarch64 requires stack to be aligned to 16 bytes.
+ */
+#define __stack_aligned__ __attribute__((aligned(16)))
+
#ifndef offsetof
# define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif
diff --git a/include/restorer.h b/include/restorer.h
index fe3af18..4c4377c 100644
--- a/include/restorer.h
+++ b/include/restorer.h
@@ -50,7 +50,7 @@ struct restore_mem_zone {
u8 redzone[RESTORE_STACK_REDZONE];
u8 stack[RESTORE_STACK_SIZE];
u8 rt_sigframe[RESTORE_STACK_SIGFRAME];
-} __aligned(16);
+} __stack_aligned__;
struct rst_sched_param {
int policy;
diff --git a/test/zdtm/lib/ns.c b/test/zdtm/lib/ns.c
index 8d7e7af..bc5c395 100644
--- a/test/zdtm/lib/ns.c
+++ b/test/zdtm/lib/ns.c
@@ -16,6 +16,7 @@
#include <sched.h>
#include <sys/socket.h>
+#include "zdtmtst.h"
#include "ns.h"
extern int pivot_root(const char *new_root, const char *put_old);
@@ -143,7 +144,7 @@ static int prepare_namespaces(void)
/* All arguments should be above stack, because it grows down */
struct ns_exec_args {
- char stack[NS_STACK_SIZE] __attribute__((aligned (16)));
+ char stack[NS_STACK_SIZE] __stack_aligned__;
char stack_ptr[0];
int argc;
char **argv;
diff --git a/test/zdtm/lib/zdtmtst.h b/test/zdtm/lib/zdtmtst.h
index f58435f..a8f9e02 100644
--- a/test/zdtm/lib/zdtmtst.h
+++ b/test/zdtm/lib/zdtmtst.h
@@ -99,6 +99,12 @@ extern int parse_opt_string(char *param, void *arg);
#define __stringify_1(x) #x
#define __stringify(x) __stringify_1(x)
+/*
+ * Macro to define stack alignment.
+ * aarch64 requires stack to be aligned to 16 bytes.
+ */
+#define __stack_aligned__ __attribute__((aligned(16)))
+
/* message helpers */
extern int test_log_init(const char *outfile, const char *suffix);
extern int zdtm_seccomp;
diff --git a/test/zdtm/live/static/fdt_shared.c b/test/zdtm/live/static/fdt_shared.c
index 605bb6d..908f6bc 100644
--- a/test/zdtm/live/static/fdt_shared.c
+++ b/test/zdtm/live/static/fdt_shared.c
@@ -48,7 +48,7 @@ static void wait_children()
static pid_t clone_child(int (*fn)(void *), int flags)
{
- char stack[STACK_SIZE] __attribute__((aligned (16)));
+ char stack[STACK_SIZE] __stack_aligned__;
pid_t pid;
pid = clone(fn, stack + STACK_SIZE,
diff --git a/test/zdtm/live/static/mntns_link_remap.c b/test/zdtm/live/static/mntns_link_remap.c
index 6d62920..210188b 100644
--- a/test/zdtm/live/static/mntns_link_remap.c
+++ b/test/zdtm/live/static/mntns_link_remap.c
@@ -29,7 +29,7 @@ TEST_OPTION(dirname, string, "directory name", 1);
#define NS_STACK_SIZE 4096
/* All arguments should be above stack, because it grows down */
struct ns_exec_args {
- char stack[NS_STACK_SIZE] __attribute__((aligned (16)));
+ char stack[NS_STACK_SIZE] __stack_aligned__;
char stack_ptr[0];
int fd;
int sync;
diff --git a/test/zdtm/live/static/mntns_open.c b/test/zdtm/live/static/mntns_open.c
index 2f91801..629d762 100644
--- a/test/zdtm/live/static/mntns_open.c
+++ b/test/zdtm/live/static/mntns_open.c
@@ -29,7 +29,7 @@ char fpath[PATH_MAX];
#define NS_STACK_SIZE 4096
/* All arguments should be above stack, because it grows down */
struct ns_exec_args {
- char stack[NS_STACK_SIZE] __attribute__((aligned (16)));
+ char stack[NS_STACK_SIZE] __stack_aligned__;
char stack_ptr[0];
int fd;
};
diff --git a/test/zdtm/live/static/mountpoints.c b/test/zdtm/live/static/mountpoints.c
index 7ad5c92..0b46480 100644
--- a/test/zdtm/live/static/mountpoints.c
+++ b/test/zdtm/live/static/mountpoints.c
@@ -22,7 +22,7 @@ static char buf[1024];
#define NS_STACK_SIZE 4096
/* All arguments should be above stack, because it grows down */
struct ns_exec_args {
- char stack[NS_STACK_SIZE] __attribute__((aligned (16)));
+ char stack[NS_STACK_SIZE] __stack_aligned__;
char stack_ptr[0];
int status_pipe[2];
};
diff --git a/test/zdtm/live/static/session02.c b/test/zdtm/live/static/session02.c
index c4c3922..6c5e771 100644
--- a/test/zdtm/live/static/session02.c
+++ b/test/zdtm/live/static/session02.c
@@ -67,7 +67,7 @@ static void mainloop()
#define CLONE_STACK_SIZE 4096
/* All arguments should be above stack, because it grows down */
struct clone_args {
- char stack[CLONE_STACK_SIZE] __attribute__((aligned (16)));
+ char stack[CLONE_STACK_SIZE] __stack_aligned__;
char stack_ptr[0];
int id;
};
diff --git a/test/zdtm/live/static/session03.c b/test/zdtm/live/static/session03.c
index a8e14b1..ef268e5 100644
--- a/test/zdtm/live/static/session03.c
+++ b/test/zdtm/live/static/session03.c
@@ -109,7 +109,7 @@ static void mainloop()
#define CLONE_STACK_SIZE 4096
/* All arguments should be above stack, because it grows down */
struct clone_args {
- char stack[CLONE_STACK_SIZE] __attribute__((aligned (16)));
+ char stack[CLONE_STACK_SIZE] __stack_aligned__;
char stack_ptr[0];
int id;
};
diff --git a/test/zdtm/live/static/sigaltstack.c b/test/zdtm/live/static/sigaltstack.c
index d84c35c..be5ddf7 100644
--- a/test/zdtm/live/static/sigaltstack.c
+++ b/test/zdtm/live/static/sigaltstack.c
@@ -16,8 +16,8 @@
const char *test_doc = "Check for alternate signal stack";
const char *test_author = "Cyrill Gorcunov <gorcunov at openvz.org>";
-static char stack_thread[SIGSTKSZ + TEST_MSG_BUFFER_SIZE];
-static char stack_main[SIGSTKSZ + TEST_MSG_BUFFER_SIZE];
+static char stack_thread[SIGSTKSZ + TEST_MSG_BUFFER_SIZE] __stack_aligned__;
+static char stack_main[SIGSTKSZ + TEST_MSG_BUFFER_SIZE] __stack_aligned__;
enum {
SAS_MAIN_OLD,
--
1.7.9.5
More information about the CRIU
mailing list