[CRIU] [PATCH 4/4] x86/compat: provide optimized memcpy_x86

Dmitry Safonov dsafonov at virtuozzo.com
Tue Nov 22 03:42:20 PST 2016


Implementation for PIE's builtin_memcpy located at
criu/arch/x86/include/asm/string.h

Signed-off-by: Dmitry Safonov <dsafonov at virtuozzo.com>
---
 criu/arch/x86/compat/memcpy-compat.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 criu/arch/x86/compat/memcpy-compat.c

diff --git a/criu/arch/x86/compat/memcpy-compat.c b/criu/arch/x86/compat/memcpy-compat.c
new file mode 100644
index 000000000000..793c27dcaa7d
--- /dev/null
+++ b/criu/arch/x86/compat/memcpy-compat.c
@@ -0,0 +1,25 @@
+#include <stddef.h>
+
+/*
+ * This provides an optimized implementation of memcpy, and a simplified
+ * implementation of memset and memmove. These are used here because the
+ * standard kernel runtime versions are not yet available and we don't
+ * trust the gcc built-in implementations as they may do unexpected things
+ * (e.g. FPU ops) in the minimal decompression stub execution environment.
+ *
+ * From Linux kernel boot helpers: arch/x86/boot/compressed/string.c
+ */
+
+void *memcpy_x86(void *dest, const void *src, size_t n)
+{
+	int d0, d1, d2;
+	asm volatile(
+		"rep ; movsl\n\t"
+		"movl %4,%%ecx\n\t"
+		"rep ; movsb\n\t"
+		: "=&c" (d0), "=&D" (d1), "=&S" (d2)
+		: "0" (n >> 2), "g" (n & 3), "1" (dest), "2" (src)
+		: "memory");
+
+	return dest;
+}
-- 
2.10.2



More information about the CRIU mailing list