[CRIU] [PATCHv2 07/12] arm/pie: Provide __clear_cache()

Dmitry Safonov dima at arista.com
Wed May 29 19:15:10 MSK 2019


After patching code - we need to flush CPU cache, it's done with
__builtin___clear_cache(). As we don't link to libgcc, provide a helper
that wraps ARM-specific syscall.

Fixes:
  LINK     criu/pie/restorer.built-in.o
ld: ./criu/arch/arm/vdso-pie.o: in function `insert_trampoline':
/root/criu/criu/arch/arm/vdso-pie.c:32: undefined reference to `__clear_cache'

Signed-off-by: Dmitry Safonov <dima at arista.com>
---
 compel/arch/arm/plugins/std/syscalls/syscall.def | 1 +
 criu/arch/arm/pie-cacheflush.c                   | 7 +++++++
 criu/pie/Makefile.library                        | 1 +
 3 files changed, 9 insertions(+)
 create mode 100644 criu/arch/arm/pie-cacheflush.c

diff --git a/compel/arch/arm/plugins/std/syscalls/syscall.def b/compel/arch/arm/plugins/std/syscalls/syscall.def
index bcd61d4a1bad..653a7539b770 100644
--- a/compel/arch/arm/plugins/std/syscalls/syscall.def
+++ b/compel/arch/arm/plugins/std/syscalls/syscall.def
@@ -110,3 +110,4 @@ gettimeofday			169	78	(struct timeval *tv, struct timezone *tz)
 preadv_raw			69	361	(int fd, struct iovec *iov, unsigned long nr, unsigned long pos_l, unsigned long pos_h)
 userfaultfd			282	388	(int flags)
 fallocate			47	352	(int fd, int mode, loff_t offset, loff_t len)
+cacheflush			!	983042	(void *start, void *end, int flags)
diff --git a/criu/arch/arm/pie-cacheflush.c b/criu/arch/arm/pie-cacheflush.c
new file mode 100644
index 000000000000..e6fd71f1eef7
--- /dev/null
+++ b/criu/arch/arm/pie-cacheflush.c
@@ -0,0 +1,7 @@
+#include <compel/plugins/std/syscall.h>
+
+/* That's __builtin___clear_cache() to flush CPU cache */
+void __clear_cache(void *start, void *end)
+{
+	sys_cacheflush(start, end, 0);
+}
diff --git a/criu/pie/Makefile.library b/criu/pie/Makefile.library
index 2d2d1faf1bd7..b1ac600c6f18 100644
--- a/criu/pie/Makefile.library
+++ b/criu/pie/Makefile.library
@@ -25,6 +25,7 @@ endif
 
 ifeq ($(SRCARCH),arm)
         lib-y		+= ./$(ARCH_DIR)/aeabi-helpers.o
+        lib-y		+= ./$(ARCH_DIR)/pie-cacheflush.o
 endif
 
 CFLAGS		:= $(filter-out -pg $(CFLAGS-GCOV) $(CFLAGS-ASAN),$(CFLAGS))
-- 
2.21.0



More information about the CRIU mailing list