[CRIU] [PATCH] pstree: Aligned pstree item allocation

Kirill Tkhai ktkhai at virtuozzo.com
Sat Jan 28 07:56:21 PST 2017


According to man futex(2):

    "On all platforms, futexes are four-byte integers
     that must be aligned on a four-byte boundary".

So, allocate them aligned.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/include/pstree.h |    9 +++++----
 criu/pstree.c         |    1 +
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/criu/include/pstree.h b/criu/include/pstree.h
index b4dc6b635..ee46a14db 100644
--- a/criu/include/pstree.h
+++ b/criu/include/pstree.h
@@ -12,6 +12,11 @@
  */
 #define INIT_PID	(1)
 struct pstree_item {
+	union {
+		/* Must be 4 bytes aligned */
+		futex_t		task_st;
+		unsigned long	task_st_le_bits;
+	};
 	struct pstree_item	*parent;
 	struct list_head	children;	/* list of my children */
 	struct list_head	sibling;	/* linkage in my parent's children list */
@@ -25,10 +30,6 @@ struct pstree_item {
 	struct pid		*threads;	/* array of threads */
 	CoreEntry		**core;
 	TaskKobjIdsEntry	*ids;
-	union {
-		futex_t		task_st;
-		unsigned long	task_st_le_bits;
-	};
 };
 
 enum {
diff --git a/criu/pstree.c b/criu/pstree.c
index 8eeea947c..bee9c8917 100644
--- a/criu/pstree.c
+++ b/criu/pstree.c
@@ -203,6 +203,7 @@ struct pstree_item *__alloc_pstree_item(bool rst)
 			return NULL;
 	} else {
 		sz = sizeof(*item) + sizeof(struct rst_info);
+		/* Guarantees sizeof(void *) alignment */
 		item = shmalloc(sz);
 		if (!item)
 			return NULL;



More information about the CRIU mailing list