[CRIU] [PATCH 03/11] Add builtin_memcpy helper

Cyrill Gorcunov gorcunov at openvz.org
Sun Mar 25 09:35:16 EDT 2012


We will need it in parasite code where
we can't use libc functions.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 include/builtins.h |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)
 create mode 100644 include/builtins.h

diff --git a/include/builtins.h b/include/builtins.h
new file mode 100644
index 0000000..8e35aa0
--- /dev/null
+++ b/include/builtins.h
@@ -0,0 +1,22 @@
+#ifndef BUILTINS_H__
+#define BUILTINS_H__
+
+#include "compiler.h"
+#include "types.h"
+
+static always_inline void *builtin_memcpy(void *to, const void *from, unsigned int n)
+{
+	int d0, d1, d2;
+	asm volatile("rep ; movsl		\n"
+		     "movl %4,%%ecx		\n"
+		     "andl $3,%%ecx		\n"
+		     "jz 1f			\n"
+		     "rep ; movsb		\n"
+		     "1:"
+		     : "=&c" (d0), "=&D" (d1), "=&S" (d2)
+		     : "0" (n / 4), "g" (n), "1" ((long)to), "2" ((long)from)
+		     : "memory");
+	return to;
+}
+
+#endif /* BUILTINS_H__ */
-- 
1.7.7.6



More information about the CRIU mailing list