Commit fd814de1 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Andrei Vagin

infect: Move compel_relocs_apply into engine

It will move into compel on a final pass.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent e9700c4f
......@@ -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
......
......@@ -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
......@@ -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;
......
#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();
}
}
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment