[CRIU] [PATCHv3 1/5] parasite/x86: introduce&use builtin_memset

Dmitry Safonov dsafonov at virtuozzo.com
Fri Sep 16 11:46:54 PDT 2016


Don't use compiler-provided memset in parasite.

Fixes: commit 86434deba0b4 ("x86: dump TLS entries from GDT").

Cc: Cyrill Gorcunov <gorcunov at openvz.org>
Signed-off-by: Dmitry Safonov <dsafonov at virtuozzo.com>
---
v3: iterate in (char *) in builtin_memset()

 criu/arch/x86/include/asm/parasite.h |  4 +++-
 criu/include/asm-generic/string.h    | 11 +++++++++++
 criu/pie/parasite.c                  |  2 --
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/criu/arch/x86/include/asm/parasite.h b/criu/arch/x86/include/asm/parasite.h
index d238327dbbeb..7f9c16033067 100644
--- a/criu/arch/x86/include/asm/parasite.h
+++ b/criu/arch/x86/include/asm/parasite.h
@@ -1,6 +1,8 @@
 #ifndef __ASM_PARASITE_H__
 #define __ASM_PARASITE_H__
 
+#include "asm-generic/string.h"
+
 #ifdef CONFIG_X86_32
 # define __parasite_entry __attribute__((regparm(3)))
 #endif
@@ -50,7 +52,7 @@ static void arch_get_tls(tls_t *ptls)
 	{
 		user_desc_t *d = &ptls->desc[i];
 
-		memset(d, 0, sizeof(user_desc_t));
+		builtin_memset(d, 0, sizeof(user_desc_t));
 		d->entry_number = GDT_ENTRY_TLS_MIN + i;
 		arch_get_user_desc(d);
 	}
diff --git a/criu/include/asm-generic/string.h b/criu/include/asm-generic/string.h
index 9e649c027da1..26d5c9bea3d8 100644
--- a/criu/include/asm-generic/string.h
+++ b/criu/include/asm-generic/string.h
@@ -46,4 +46,15 @@ static always_inline int builtin_strncmp(const char *cs, const char *ct, size_t
 }
 #endif
 
+#ifndef HAS_BUILTIN_MEMSET
+static always_inline void builtin_memset(void *s, const int c, size_t count)
+{
+	char *dest = s;
+	size_t i = 0;
+
+	while (i < count)
+		dest[i++] = (char) c;
+}
+#endif
+
 #endif /* __CR_ASM_GENERIC_STRING_H__ */
diff --git a/criu/pie/parasite.c b/criu/pie/parasite.c
index e54dc2e43b02..53985b4352c2 100644
--- a/criu/pie/parasite.c
+++ b/criu/pie/parasite.c
@@ -18,8 +18,6 @@
 #include "tty.h"
 #include "aio.h"
 
-#include <string.h>
-
 #include "asm/types.h"
 #include "asm/parasite.h"
 #include "asm/restorer.h"
-- 
2.9.0



More information about the CRIU mailing list