[CRIU] [PATCH 76/78] infect: Move compel_relocs_apply into engine
Cyrill Gorcunov
gorcunov at openvz.org
Mon Nov 7 08:37:01 PST 2016
It will move into compel on a final pass.
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
criu/Makefile.crtools | 1 -
criu/include/infect.h | 2 ++
criu/infect.c | 33 ++++++++++++++++++++++++++++++---
criu/pie/pie-relocs.c | 49 -------------------------------------------------
criu/pie/pie-relocs.h | 4 +---
5 files changed, 33 insertions(+), 56 deletions(-)
delete mode 100644 criu/pie/pie-relocs.c
diff --git a/criu/Makefile.crtools b/criu/Makefile.crtools
index 93df4ab4e7ef..ab4735611454 100644
--- a/criu/Makefile.crtools
+++ b/criu/Makefile.crtools
@@ -50,7 +50,6 @@ obj-y += page-pipe.o
obj-y += pagemap.o
obj-y += page-xfer.o
obj-y += parasite-syscall.o
-obj-y += pie/pie-relocs.o
obj-y += pie-util-fd.o
obj-y += pie-util.o
obj-y += pipes.o
diff --git a/criu/include/infect.h b/criu/include/infect.h
index 71255b54cf1c..760bdb80dc54 100644
--- a/criu/include/infect.h
+++ b/criu/include/infect.h
@@ -137,4 +137,6 @@ extern struct parasite_blob_desc *compel_parasite_blob_desc(struct parasite_ctl
typedef int (*save_regs_t)(void *, user_regs_struct_t *, user_fpregs_struct_t *);
extern int compel_get_task_regs(pid_t pid, user_regs_struct_t regs, save_regs_t, void *);
+extern void compel_relocs_apply(void *mem, void *vbase, size_t size, compel_reloc_t *elf_relocs, size_t nr_relocs);
+
#endif
diff --git a/criu/infect.c b/criu/infect.c
index 27b557abbb36..e27df9afe04a 100644
--- a/criu/infect.c
+++ b/criu/infect.c
@@ -9,7 +9,6 @@
#include <fcntl.h>
#include <linux/seccomp.h>
-#include "pie-relocs.h"
#include "criu-log.h"
#include "common/bug.h"
#include "common/xmalloc.h"
@@ -730,6 +729,34 @@ err_cure:
return -1;
}
+void compel_relocs_apply(void *mem, void *vbase, size_t size, compel_reloc_t *elf_relocs, size_t nr_relocs)
+{
+ size_t i, j;
+
+ for (i = 0, j = 0; i < nr_relocs; i++) {
+ if (elf_relocs[i].type & COMPEL_TYPE_LONG) {
+ long *where = mem + elf_relocs[i].offset;
+ long *p = mem + size;
+
+ if (elf_relocs[i].type & COMPEL_TYPE_GOTPCREL) {
+ int *value = (int *)where;
+ int rel;
+
+ p[j] = (long)vbase + elf_relocs[i].value;
+ rel = (unsigned)((void *)&p[j] - (void *)mem) - elf_relocs[i].offset + elf_relocs[i].addend;
+
+ *value = rel;
+ j++;
+ } else
+ *where = elf_relocs[i].value + elf_relocs[i].addend + (unsigned long)vbase;
+ } else if (elf_relocs[i].type & COMPEL_TYPE_INT) {
+ int *where = (mem + elf_relocs[i].offset);
+ *where = elf_relocs[i].value + elf_relocs[i].addend + (unsigned long)vbase;
+ } else
+ BUG();
+ }
+}
+
int compel_map_exchange(struct parasite_ctl *ctl, unsigned long size)
{
int ret;
@@ -782,8 +809,8 @@ int compel_infect(struct parasite_ctl *ctl, unsigned long nr_threads, unsigned l
memcpy(ctl->local_map, ctl->pblob.mem, ctl->pblob.size);
if (ctl->pblob.nr_relocs)
- elf_relocs_apply(ctl->local_map, ctl->remote_map, ctl->pblob.bsize,
- ctl->pblob.relocs, ctl->pblob.nr_relocs);
+ compel_relocs_apply(ctl->local_map, ctl->remote_map, ctl->pblob.bsize,
+ ctl->pblob.relocs, ctl->pblob.nr_relocs);
p = parasite_size;
diff --git a/criu/pie/pie-relocs.c b/criu/pie/pie-relocs.c
deleted file mode 100644
index f0802a0a2ab0..000000000000
--- a/criu/pie/pie-relocs.c
+++ /dev/null
@@ -1,49 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <unistd.h>
-#include <stdint.h>
-#include <string.h>
-
-#include <fcntl.h>
-#include <elf.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-
-#include "asm-generic/int.h"
-
-#include "log.h"
-
-#include "common/compiler.h"
-#include <compel/compel.h>
-#include "common/bug.h"
-
-__maybe_unused void elf_relocs_apply(void *mem, void *vbase, size_t size, compel_reloc_t *elf_relocs, size_t nr_relocs)
-{
- size_t i, j;
-
- for (i = 0, j = 0; i < nr_relocs; i++) {
- if (elf_relocs[i].type & COMPEL_TYPE_LONG) {
- long *where = mem + elf_relocs[i].offset;
- long *p = mem + size;
-
- if (elf_relocs[i].type & COMPEL_TYPE_GOTPCREL) {
- int *value = (int *)where;
- int rel;
-
- p[j] = (long)vbase + elf_relocs[i].value;
- rel = (unsigned)((void *)&p[j] - (void *)mem) - elf_relocs[i].offset + elf_relocs[i].addend;
-
- *value = rel;
- j++;
- } else
- *where = elf_relocs[i].value + elf_relocs[i].addend + (unsigned long)vbase;
- } else if (elf_relocs[i].type & COMPEL_TYPE_INT) {
- int *where = (mem + elf_relocs[i].offset);
- *where = elf_relocs[i].value + elf_relocs[i].addend + (unsigned long)vbase;
- } else
- BUG();
- }
-}
diff --git a/criu/pie/pie-relocs.h b/criu/pie/pie-relocs.h
index 2fc5f6a339ae..442e70d13939 100644
--- a/criu/pie/pie-relocs.h
+++ b/criu/pie/pie-relocs.h
@@ -8,12 +8,10 @@
#ifdef CONFIG_PIEGEN
-extern __maybe_unused void elf_relocs_apply(void *mem, void *vbase, size_t size,
- compel_reloc_t *elf_relocs, size_t nr_relocs);
#define pie_size(__pie_name) (round_up(sizeof(__pie_name##_blob) + \
__pie_name ## _nr_gotpcrel * sizeof(long), page_size()))
#define ELF_RELOCS_APPLY(__pie_name, __mem, __vbase) \
- elf_relocs_apply(__mem, __vbase, sizeof(__pie_name##_blob), \
+ compel_relocs_apply(__mem, __vbase, sizeof(__pie_name##_blob), \
__pie_name##_relocs, ARRAY_SIZE(__pie_name##_relocs))
#else
--
2.7.4
More information about the CRIU
mailing list