[CRIU] [PATCH 1/9] compel: Initial commit for rework
Cyrill Gorcunov
gorcunov at openvz.org
Wed Aug 24 09:47:31 PDT 2016
We're going to rework compel to support parasite
engine and plugin structure so that CRIU would simply
use the scaffolds.
The plugins gonna provide syscalls, in/out routunes,
file descriptor transfer and such, just like we currently
do in CRIU itself.
Here we shuffle the directories and fixup various things.
Note the @hostprogs are now left, probably will bring it back
one day. For same reason tests won't work for now.
Moreover since we're goig to ship compel/libcompel together
with criu and same time we are to *use* compel during CRIU
building procedure, the @hostprogs mode likely to be removed
completely and compel is to build two times in case of
cross-compile: once when building criu and second when
prepare its shipping. This is in TODO list currently.
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
Makefile | 7 +-
Makefile.compel | 38 +++
Makefile.versions | 3 +-
compel/Makefile | 47 ++--
compel/arch/aarch64/handle-elf.c | 21 --
compel/arch/aarch64/include/handle-elf.h | 11 -
compel/arch/aarch64/src/lib/handle-elf.c | 34 +++
compel/arch/aarch64/src/lib/include/handle-elf.h | 11 +
compel/arch/arm/include/handle-elf.h | 11 -
compel/arch/arm/{ => src/lib}/handle-elf.c | 13 +-
compel/arch/arm/src/lib/include/handle-elf.h | 11 +
compel/arch/ppc64/handle-elf.c | 21 --
compel/arch/ppc64/include/handle-elf.h | 12 -
compel/arch/ppc64/src/lib/handle-elf.c | 34 +++
compel/arch/ppc64/src/lib/include/handle-elf.h | 13 +
compel/arch/x86/handle-elf.c | 16 --
.../x86/plugins/include/asm/std/syscall-types.h | 53 +++++
compel/arch/x86/plugins/std/call32.S | 71 ++++++
.../plugins/std/syscalls/syscall-common-x86-32.S | 36 +++
.../plugins/std/syscalls/syscall-common-x86-64.S | 21 ++
compel/arch/x86/plugins/std/syscalls/syscall32.c | 85 +++++++
.../arch/x86/plugins/std/syscalls/syscall_32.tbl | 94 ++++++++
.../arch/x86/plugins/std/syscalls/syscall_64.tbl | 105 +++++++++
compel/arch/x86/scripts/pack.lds.S | 30 +++
compel/arch/x86/src/lib/handle-elf.c | 29 +++
compel/arch/x86/{ => src/lib}/include/handle-elf.h | 18 +-
compel/include/elf32-types.h | 16 ++
compel/include/elf64-types.h | 16 ++
compel/include/piegen.h | 22 +-
compel/include/uapi/compel.h | 27 +++
compel/include/uapi/elf32-types.h | 20 --
compel/include/uapi/elf64-types.h | 20 --
compel/include/uapi/int.h | 15 ++
compel/include/uapi/piegen-err.h | 10 -
compel/include/uapi/plugins.h | 35 +++
compel/include/uapi/types.h | 16 +-
compel/plugins/Makefile | 127 ++++++++++
compel/plugins/include/uapi/plugin-std.h | 6 +
compel/plugins/include/uapi/std/string.h | 28 +++
compel/plugins/include/uapi/std/syscall-types.h | 55 +++++
compel/plugins/std/std.c | 89 +++++++
compel/plugins/std/string.c | 262 +++++++++++++++++++++
compel/{ => src/lib}/handle-elf-32.c | 0
compel/{ => src/lib}/handle-elf.c | 103 ++++----
compel/{ => src}/main.c | 1 +
45 files changed, 1443 insertions(+), 270 deletions(-)
create mode 100644 Makefile.compel
delete mode 100644 compel/arch/aarch64/handle-elf.c
delete mode 100644 compel/arch/aarch64/include/handle-elf.h
create mode 100644 compel/arch/aarch64/src/lib/handle-elf.c
create mode 100644 compel/arch/aarch64/src/lib/include/handle-elf.h
delete mode 100644 compel/arch/arm/include/handle-elf.h
rename compel/arch/arm/{ => src/lib}/handle-elf.c (54%)
create mode 100644 compel/arch/arm/src/lib/include/handle-elf.h
delete mode 100644 compel/arch/ppc64/handle-elf.c
delete mode 100644 compel/arch/ppc64/include/handle-elf.h
create mode 100644 compel/arch/ppc64/src/lib/handle-elf.c
create mode 100644 compel/arch/ppc64/src/lib/include/handle-elf.h
delete mode 100644 compel/arch/x86/handle-elf.c
create mode 100644 compel/arch/x86/plugins/include/asm/std/syscall-types.h
create mode 100644 compel/arch/x86/plugins/std/call32.S
create mode 100644 compel/arch/x86/plugins/std/syscalls/syscall-common-x86-32.S
create mode 100644 compel/arch/x86/plugins/std/syscalls/syscall-common-x86-64.S
create mode 100644 compel/arch/x86/plugins/std/syscalls/syscall32.c
create mode 100644 compel/arch/x86/plugins/std/syscalls/syscall_32.tbl
create mode 100644 compel/arch/x86/plugins/std/syscalls/syscall_64.tbl
create mode 100644 compel/arch/x86/scripts/pack.lds.S
create mode 100644 compel/arch/x86/src/lib/handle-elf.c
rename compel/arch/x86/{ => src/lib}/include/handle-elf.h (59%)
create mode 100644 compel/include/elf32-types.h
create mode 100644 compel/include/elf64-types.h
create mode 100644 compel/include/uapi/compel.h
delete mode 100644 compel/include/uapi/elf32-types.h
delete mode 100644 compel/include/uapi/elf64-types.h
create mode 100644 compel/include/uapi/int.h
delete mode 100644 compel/include/uapi/piegen-err.h
create mode 100644 compel/include/uapi/plugins.h
mode change 100644 => 120000 compel/include/uapi/types.h
create mode 100644 compel/plugins/Makefile
create mode 100644 compel/plugins/include/uapi/plugin-std.h
create mode 100644 compel/plugins/include/uapi/std/string.h
create mode 100644 compel/plugins/include/uapi/std/syscall-types.h
create mode 100644 compel/plugins/std/std.c
create mode 100644 compel/plugins/std/string.c
rename compel/{ => src/lib}/handle-elf-32.c (100%)
rename compel/{ => src/lib}/handle-elf.c (88%)
rename compel/{ => src}/main.c (99%)
diff --git a/Makefile b/Makefile
index f850507f014e..049bb8b76006 100644
--- a/Makefile
+++ b/Makefile
@@ -181,12 +181,9 @@ $(eval $(call gen-built-in,images))
.PHONY: .FORCE
+#
# Compel get used by CRIU, build it earlier
-compel/%: .FORCE
- $(Q) $(MAKE) $(build)=compel $@
-
-test/compel/%: .FORCE
- $(Q) $(MAKE) $(build)=compel $@
+include Makefile.compel
#
# CRIU building done in own directory
diff --git a/Makefile.compel b/Makefile.compel
new file mode 100644
index 000000000000..a1291465f08b
--- /dev/null
+++ b/Makefile.compel
@@ -0,0 +1,38 @@
+ifneq ($(filter-out clean mrproper,$(MAKECMDGOALS)),)
+COMPEL_VERSION_HEADER := compel/include/version.h
+
+$(COMPEL_VERSION_HEADER): $(SRC_DIR)/Makefile.versions
+ $(call msg-gen, $(COMPEL_VERSION_HEADER))
+ $(E) " GEN " $@
+ $(Q) echo "/* Autogenerated, do not edit */" > $(COMPEL_VERSION_HEADER)
+ $(Q) echo "#ifndef COMPEL_SO_VERSION_H__" >> $(COMPEL_VERSION_HEADER)
+ $(Q) echo "#define COMPEL_SO_VERSION_H__" >> $(COMPEL_VERSION_HEADER)
+ $(Q) echo "#define COMPEL_SO_VERSION \"$(COMPEL_SO_VERSION)\"" >> $(COMPEL_VERSION_HEADER)
+ $(Q) echo "#define COMPEL_SO_VERSION_MAJOR " $(COMPEL_SO_VERSION_MAJOR) >> $(COMPEL_VERSION_HEADER)
+ $(Q) echo "#define COMPEL_SO_VERSION_MINOR " $(COMPEL_SO_VERSION_MINOR) >> $(COMPEL_VERSION_HEADER)
+ $(Q) echo "#define COMPEL_SO_VERSION_SUBLEVEL " $(COMPEL_SO_VERSION_SUBLEVEL) >> $(COMPEL_VERSION_HEADER)
+ $(Q) echo "#endif /* COMPEL_SO_VERSION_H__ */" >> $(COMPEL_VERSION_HEADER)
+endif
+cleanup-y += $(COMPEL_VERSION_HEADER)
+
+#
+# Compel itself.
+compel/%: $(COMPEL_VERSION_HEADER) .FORCE
+ $(Q) $(MAKE) $(build)=compel $@
+
+#
+# Plugins
+compel/plugins/%: $(COMPEL_VERSION_HEADER) .FORCE
+ $(Q) $(MAKE) $(build)=compel/plugins $@
+
+compel/compel: compel/built-in.o compel/lib.a
+ $(call msg-link, $@)
+ $(Q) $(CC) $(CFLAGS) $^ $(WRAPFLAGS) $(LDFLAGS) -rdynamic -o $@
+
+#
+# And compel library.
+LIBCOMPEL_SO := libcompel.so
+LIBCOMPEL_SO_CFLAGS += $(CFLAGS) -rdynamic -Wl,-soname,$(LIBCOMPEL_SO).$(COMPEL_SO_VERSION_MAJOR)
+compel/$(LIBCOMPEL_SO): compel/lib.a
+ $(call msg-link, $@)
+ $(Q) $(CC) -shared $(LIBCOMPEL_SO_CFLAGS) -o $@ -Wl,--whole-archive $^ -Wl,--no-whole-archive $(LDFLAGS)
diff --git a/Makefile.versions b/Makefile.versions
index 87bfc822ec2a..22ca14c30b96 100644
--- a/Makefile.versions
+++ b/Makefile.versions
@@ -19,5 +19,6 @@ export CRIU_SO_VERSION_MAJOR CRIU_SO_VERSION_MINOR
COMPEL_SO_VERSION_MAJOR := 1
COMPEL_SO_VERSION_MINOR := 0
+COMPEL_SO_VERSION_SUBLEVEL := 0
-export COMPEL_SO_VERSION_MAJOR COMPEL_SO_VERSION_MINOR
+export COMPEL_SO_VERSION_MAJOR COMPEL_SO_VERSION_MINOR COMPEL_SO_VERSION_SUBLEVEL
diff --git a/compel/Makefile b/compel/Makefile
index 5166e9318196..52eb27ea72f4 100644
--- a/compel/Makefile
+++ b/compel/Makefile
@@ -1,38 +1,23 @@
include $(SRC_DIR)/Makefile.versions
-ccflags-y += -iquote criu/include
-ccflags-y += -iquote compel/include
-ccflags-y += -iquote compel/arch/$(ARCH)/include
-ccflags-y += -DCOMPEL_VERSION=\"$(COMPEL_SO_VERSION_MAJOR).$(COMPEL_SO_VERSION_MINOR)\"
-
-host-ccflags-y += $(filter-out -pg $(CFLAGS-GCOV),$(ccflags-y))
-HOSTCFLAGS += $(filter-out -pg $(CFLAGS-GCOV),$(WARNINGS) $(DEFINES))
-HOSTLDFLAGS += $(filter-out -pg $(CFLAGS-GCOV),$(LDFLAGS))
-HOSTCFLAGS := $(filter-out -DCONFIG_X86_64,$(HOSTCFLAGS))
-export host-ccflags-y HOSTCFLAGS HOSTLDFLAGS
-
-hostprogs-y += compel
-compel-objs += main.o
-compel-objs += handle-elf.o
-compel-objs += arch/$(ARCH)/handle-elf.o
-
-ifeq ($(ARCH),x86)
-# Add -DCONFIG_X86_64 or -DCONFIG_X86_32 to HOSTCFLAGS
-define ccflags-defines
- export HOSTCFLAGS_$(notdir $(1)) += -DCONFIG_X86_64
-endef
-$(eval $(call map,ccflags-defines,$(compel-objs)))
+.PHONY: .FORCE
-compel-objs += handle-elf-32.o
-export HOSTCFLAGS_handle-elf-32.o += -DCONFIG_X86_32
-endif # ARCH == x86
+COMPEL_SO_VERSION := $(COMPEL_SO_VERSION_MAJOR)$(if $(COMPEL_SO_VERSION_MINOR),.$(COMPEL_SO_VERSION_MINOR))$(if $(COMPEL_SO_VERSION_SUBLEVEL),.$(COMPEL_SO_VERSION_SUBLEVEL))
+COMPEL_SO_VERSION_CODE := $(shell expr $(COMPEL_SO_VERSION_MAJOR) \* 65536 \+ $(COMPEL_SO_VERSION_MINOR) \* 256 \+ $(COMPEL_SO_VERSION_SUBLEVEL))
+ccflags-y += -iquote compel/arch/$(ARCH)/src/lib/include
+ccflags-y += -iquote compel/include
+ccflags-y += -iquote compel/plugins/include
+ccflags-y += -iquote $(SRC_DIR)/criu/include
+ccflags-y += -fPIC
-.PHONY: .FORCE
+lib-y += arch/$(ARCH)/src/lib/handle-elf.o
+lib-y += src/lib/handle-elf.o
+lib-y += src/lib/handle-elf-32.o
-export compel-objs
-test/compel/%: .FORCE
- $(Q) $(MAKE) $(build)=test/compel $@
+obj-y += src/main.o
-test: test/compel/test_handle_binary
+CFLAGS_handle-elf-32.o += -UCONFIG_X86_64 -DCONFIG_X86_32
+CFLAGS_handle-elf-32.d += -UCONFIG_X86_64 -DCONFIG_X86_32
-.PHONY: test
+cleanup-y += compel/compel
+cleanup-y += compel/libcompel.so
diff --git a/compel/arch/aarch64/handle-elf.c b/compel/arch/aarch64/handle-elf.c
deleted file mode 100644
index bbd4bf1b0369..000000000000
--- a/compel/arch/aarch64/handle-elf.c
+++ /dev/null
@@ -1,21 +0,0 @@
-#include <string.h>
-
-#include "piegen.h"
-#include "uapi/piegen-err.h"
-#include "handle-elf.h"
-
-int handle_binary(void *mem, size_t size)
-{
- const unsigned char *elf_ident =
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
- elf_ident_64_le;
-#else
- elf_ident_64_be;
-#endif
-
- if (memcmp(mem, elf_ident, sizeof(elf_ident_64_le)) == 0)
- return handle_elf_aarch64(mem, size);
-
- pr_err("Unsupported Elf format detected\n");
- return -E_NOT_ELF;
-}
diff --git a/compel/arch/aarch64/include/handle-elf.h b/compel/arch/aarch64/include/handle-elf.h
deleted file mode 100644
index 7d7bfb7b3ade..000000000000
--- a/compel/arch/aarch64/include/handle-elf.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#ifndef __COMPEL_HANDLE_ELF_H__
-#define __COMPEL_HANDLE_ELF_H__
-
-#include "uapi/elf64-types.h"
-
-#define __handle_elf handle_elf_aarch64
-#define arch_is_machine_supported(e_machine) (e_machine == EM_AARCH64)
-
-extern int handle_elf_aarch64(void *mem, size_t size);
-
-#endif /* __COMPEL_HANDLE_ELF_H__ */
diff --git a/compel/arch/aarch64/src/lib/handle-elf.c b/compel/arch/aarch64/src/lib/handle-elf.c
new file mode 100644
index 000000000000..633a382cc2da
--- /dev/null
+++ b/compel/arch/aarch64/src/lib/handle-elf.c
@@ -0,0 +1,34 @@
+#include <string.h>
+
+#include "uapi/compel.h"
+
+#include "handle-elf.h"
+#include "piegen.h"
+
+static const unsigned char __maybe_unused
+elf_ident_64_le[EI_NIDENT] = {
+ 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+};
+
+static const unsigned char __maybe_unused
+elf_ident_64_be[EI_NIDENT] = {
+ 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x02, 0x01, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+};
+
+int handle_binary(void *mem, size_t size)
+{
+ const unsigned char *elf_ident =
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+ elf_ident_64_le;
+#else
+ elf_ident_64_be;
+#endif
+
+ if (memcmp(mem, elf_ident, sizeof(elf_ident_64_le)) == 0)
+ return handle_elf_aarch64(mem, size);
+
+ pr_err("Unsupported Elf format detected\n");
+ return -EINVAL;
+}
diff --git a/compel/arch/aarch64/src/lib/include/handle-elf.h b/compel/arch/aarch64/src/lib/include/handle-elf.h
new file mode 100644
index 000000000000..0f64b34cb9c5
--- /dev/null
+++ b/compel/arch/aarch64/src/lib/include/handle-elf.h
@@ -0,0 +1,11 @@
+#ifndef COMPEL_HANDLE_ELF_H__
+#define COMPEL_HANDLE_ELF_H__
+
+#include "elf64-types.h"
+
+#define __handle_elf handle_elf_aarch64
+#define arch_is_machine_supported(e_machine) (e_machine == EM_AARCH64)
+
+extern int handle_elf_aarch64(void *mem, size_t size);
+
+#endif /* COMPEL_HANDLE_ELF_H__ */
diff --git a/compel/arch/arm/include/handle-elf.h b/compel/arch/arm/include/handle-elf.h
deleted file mode 100644
index a465f427397c..000000000000
--- a/compel/arch/arm/include/handle-elf.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#ifndef __COMPEL_HANDLE_ELF_H__
-#define __COMPEL_HANDLE_ELF_H__
-
-#include "uapi/elf32-types.h"
-
-#define __handle_elf handle_elf_arm
-#define arch_is_machine_supported(e_machine) (e_machine == EM_ARM)
-
-extern int handle_elf_arm(void *mem, size_t size);
-
-#endif /* __COMPEL_HANDLE_ELF_H__ */
diff --git a/compel/arch/arm/handle-elf.c b/compel/arch/arm/src/lib/handle-elf.c
similarity index 54%
rename from compel/arch/arm/handle-elf.c
rename to compel/arch/arm/src/lib/handle-elf.c
index 2692439c71c7..e2df0f90ddf5 100644
--- a/compel/arch/arm/handle-elf.c
+++ b/compel/arch/arm/src/lib/handle-elf.c
@@ -1,8 +1,15 @@
#include <string.h>
-#include "piegen.h"
-#include "uapi/piegen-err.h"
+#include "uapi/compel.h"
+
#include "handle-elf.h"
+#include "piegen.h"
+
+static const unsigned char __maybe_unused
+elf_ident_32[EI_NIDENT] = {
+ 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+};
int handle_binary(void *mem, size_t size)
{
@@ -10,5 +17,5 @@ int handle_binary(void *mem, size_t size)
return handle_elf_arm(mem, size);
pr_err("Unsupported Elf format detected\n");
- return -E_NOT_ELF;
+ return -EINVAL;
}
diff --git a/compel/arch/arm/src/lib/include/handle-elf.h b/compel/arch/arm/src/lib/include/handle-elf.h
new file mode 100644
index 000000000000..e5971f37b98c
--- /dev/null
+++ b/compel/arch/arm/src/lib/include/handle-elf.h
@@ -0,0 +1,11 @@
+#ifndef COMPEL_HANDLE_ELF_H__
+#define COMPEL_HANDLE_ELF_H__
+
+#include "elf32-types.h"
+
+#define __handle_elf handle_elf_arm
+#define arch_is_machine_supported(e_machine) (e_machine == EM_ARM)
+
+extern int handle_elf_arm(void *mem, size_t size);
+
+#endif /* COMPEL_HANDLE_ELF_H__ */
diff --git a/compel/arch/ppc64/handle-elf.c b/compel/arch/ppc64/handle-elf.c
deleted file mode 100644
index 049e3fba0e66..000000000000
--- a/compel/arch/ppc64/handle-elf.c
+++ /dev/null
@@ -1,21 +0,0 @@
-#include <string.h>
-
-#include "piegen.h"
-#include "uapi/piegen-err.h"
-#include "handle-elf.h"
-
-int handle_binary(void *mem, size_t size)
-{
- const unsigned char *elf_ident =
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
- elf_ident_64_le;
-#else
- elf_ident_64_be;
-#endif
-
- if (memcmp(mem, elf_ident, sizeof(elf_ident_64_le)) == 0)
- return handle_elf_ppc64(mem, size);
-
- pr_err("Unsupported Elf format detected\n");
- return -E_NOT_ELF;
-}
diff --git a/compel/arch/ppc64/include/handle-elf.h b/compel/arch/ppc64/include/handle-elf.h
deleted file mode 100644
index b324debdf780..000000000000
--- a/compel/arch/ppc64/include/handle-elf.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef __COMPEL_HANDLE_ELF_H__
-#define __COMPEL_HANDLE_ELF_H__
-
-#include "uapi/elf64-types.h"
-
-#define ELF_PPC64
-#define __handle_elf handle_elf_ppc64
-#define arch_is_machine_supported(e_machine) (e_machine == EM_PPC64)
-
-extern int handle_elf_ppc64(void *mem, size_t size);
-
-#endif /* __COMPEL_HANDLE_ELF_H__ */
diff --git a/compel/arch/ppc64/src/lib/handle-elf.c b/compel/arch/ppc64/src/lib/handle-elf.c
new file mode 100644
index 000000000000..6491f20850ad
--- /dev/null
+++ b/compel/arch/ppc64/src/lib/handle-elf.c
@@ -0,0 +1,34 @@
+#include <string.h>
+
+#include "uapi/compel.h"
+
+#include "handle-elf.h"
+#include "piegen.h"
+
+static const unsigned char __maybe_unused
+elf_ident_64_le[EI_NIDENT] = {
+ 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+};
+
+static const unsigned char __maybe_unused
+elf_ident_64_be[EI_NIDENT] = {
+ 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x02, 0x01, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+};
+
+int handle_binary(void *mem, size_t size)
+{
+ const unsigned char *elf_ident =
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+ elf_ident_64_le;
+#else
+ elf_ident_64_be;
+#endif
+
+ if (memcmp(mem, elf_ident, sizeof(elf_ident_64_le)) == 0)
+ return handle_elf_ppc64(mem, size);
+
+ pr_err("Unsupported Elf format detected\n");
+ return -EINVAL;
+}
diff --git a/compel/arch/ppc64/src/lib/include/handle-elf.h b/compel/arch/ppc64/src/lib/include/handle-elf.h
new file mode 100644
index 000000000000..1a8217e6b8e4
--- /dev/null
+++ b/compel/arch/ppc64/src/lib/include/handle-elf.h
@@ -0,0 +1,13 @@
+#ifndef COMPEL_HANDLE_ELF_H__
+#define COMPEL_HANDLE_ELF_H__
+
+#include "elf64-types.h"
+
+#define ELF_PPC64
+
+#define __handle_elf handle_elf_ppc64
+#define arch_is_machine_supported(e_machine) (e_machine == EM_PPC64)
+
+extern int handle_elf_ppc64(void *mem, size_t size);
+
+#endif /* COMPEL_HANDLE_ELF_H__ */
diff --git a/compel/arch/x86/handle-elf.c b/compel/arch/x86/handle-elf.c
deleted file mode 100644
index 9edb94262f70..000000000000
--- a/compel/arch/x86/handle-elf.c
+++ /dev/null
@@ -1,16 +0,0 @@
-#include <string.h>
-
-#include "piegen.h"
-#include "uapi/piegen-err.h"
-#include "handle-elf.h"
-
-int handle_binary(void *mem, size_t size)
-{
- if (memcmp(mem, elf_ident_32, sizeof(elf_ident_32)) == 0)
- return handle_elf_x86_32(mem, size);
- else if (memcmp(mem, elf_ident_64_le, sizeof(elf_ident_64_le)) == 0)
- return handle_elf_x86_64(mem, size);
-
- pr_err("Unsupported Elf format detected\n");
- return -E_NOT_ELF;
-}
diff --git a/compel/arch/x86/plugins/include/asm/std/syscall-types.h b/compel/arch/x86/plugins/include/asm/std/syscall-types.h
new file mode 100644
index 000000000000..744809d07894
--- /dev/null
+++ b/compel/arch/x86/plugins/include/asm/std/syscall-types.h
@@ -0,0 +1,53 @@
+#ifndef COMPEL_ARCH_SYSCALL_TYPES_H__
+#define COMPEL_ARCH_SYSCALL_TYPES_H__
+
+/* Types for sigaction, sigprocmask syscalls */
+typedef void rt_signalfn_t(int, siginfo_t *, void *);
+typedef rt_signalfn_t *rt_sighandler_t;
+
+typedef void rt_restorefn_t(void);
+typedef rt_restorefn_t *rt_sigrestore_t;
+
+#define _KNSIG 64
+# define _NSIG_BPW 64
+
+#define _KNSIG_WORDS (_KNSIG / _NSIG_BPW)
+
+typedef struct {
+ u64 sig[_KNSIG_WORDS];
+} k_rtsigset_t;
+
+typedef struct {
+ rt_sighandler_t rt_sa_handler;
+ unsigned long rt_sa_flags;
+ rt_sigrestore_t rt_sa_restorer;
+ k_rtsigset_t rt_sa_mask;
+} rt_sigaction_t;
+
+/*
+ * Note: there is unaligned access on x86_64 and it's fine.
+ * However, when porting this code -- keep in mind about possible issues
+ * with unaligned rt_sa_mask.
+ */
+typedef struct __attribute__((packed)) {
+ u32 rt_sa_handler;
+ u32 rt_sa_flags;
+ u32 rt_sa_restorer;
+ k_rtsigset_t rt_sa_mask;
+} rt_sigaction_t_compat;
+
+/* Types for set_thread_area, get_thread_area syscalls */
+typedef struct {
+ unsigned int entry_number;
+ unsigned int base_addr;
+ unsigned int limit;
+ unsigned int seg_32bit:1;
+ unsigned int contents:2;
+ unsigned int read_exec_only:1;
+ unsigned int limit_in_pages:1;
+ unsigned int seg_not_present:1;
+ unsigned int useable:1;
+ unsigned int lm:1;
+} user_desc_t;
+
+#endif /* COMPEL_ARCH_SYSCALL_TYPES_H__ */
diff --git a/compel/arch/x86/plugins/std/call32.S b/compel/arch/x86/plugins/std/call32.S
new file mode 100644
index 000000000000..935461dcdc86
--- /dev/null
+++ b/compel/arch/x86/plugins/std/call32.S
@@ -0,0 +1,71 @@
+/*
+ * call32.S - assembly helpers for mixed-bitness code
+ * From kernel selftests originally: tools/testing/selftests/x86/thunks.S
+ * Copyright (c) 2015 Andrew Lutomirski
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * These are little helpers that make it easier to switch bitness on
+ * the fly.
+ */
+
+#include "asm/linkage.h"
+
+#define __USER32_CS 0x23
+#define __USER_CS 0x33
+
+ .text
+
+/*
+ * @rdi: Stack to use
+ * @esi: Pointer to function for calling
+ */
+ENTRY(call32_from_64)
+ /* Callee-saving registers due to ABI */
+ pushq %rbx
+ pushq %rbp
+ pushq %r12
+ pushq %r13
+ pushq %r14
+ pushq %r15
+ pushfq
+
+ /* Switch stacks */
+ sub $8, %rdi
+ mov %rsp,(%rdi)
+ mov %rdi,%rsp
+
+ /* Switch into compatibility mode */
+ pushq $__USER32_CS
+ pushq $1f
+ lretq
+
+1:
+ .code32
+ /* Run function and switch back */
+ call *%esi
+ jmp $__USER_CS,$1f
+ .code64
+
+1:
+ /* Restore the stack */
+ mov (%rsp),%rsp
+ add $8, %rdi
+
+ /* Restore registers */
+ popfq
+ popq %r15
+ popq %r14
+ popq %r13
+ popq %r12
+ popq %rbp
+ popq %rbx
+ ret
+END(call32_from_64)
diff --git a/compel/arch/x86/plugins/std/syscalls/syscall-common-x86-32.S b/compel/arch/x86/plugins/std/syscalls/syscall-common-x86-32.S
new file mode 100644
index 000000000000..ae6d594dc4fe
--- /dev/null
+++ b/compel/arch/x86/plugins/std/syscalls/syscall-common-x86-32.S
@@ -0,0 +1,36 @@
+#include "asm/linkage.h"
+
+#define SYSCALL(name, opcode) \
+ ENTRY(name); \
+ movl $opcode, %eax; \
+ jmp __syscall_common; \
+ END(name)
+
+ENTRY(__syscall_common)
+ pushl %ebx
+ pushl %esi
+ pushl %edi
+ pushl %ebp
+
+#define __arg(n) (4 * (n) + 20)(%esp)
+ movl __arg(0),%ebx
+ movl __arg(1),%ecx
+ movl __arg(2),%edx
+ movl __arg(3),%esi
+ movl __arg(4),%edi
+ movl __arg(5),%ebp
+#undef __arg
+
+ int $0x80
+
+ popl %ebp
+ popl %edi
+ popl %esi
+ popl %ebx
+ ret
+END(__syscall_common)
+
+ENTRY(__cr_restore_rt)
+ movl $__NR_rt_sigreturn, %eax
+ jmp __syscall_common
+END(__cr_restore_rt)
diff --git a/compel/arch/x86/plugins/std/syscalls/syscall-common-x86-64.S b/compel/arch/x86/plugins/std/syscalls/syscall-common-x86-64.S
new file mode 100644
index 000000000000..b93c31288a20
--- /dev/null
+++ b/compel/arch/x86/plugins/std/syscalls/syscall-common-x86-64.S
@@ -0,0 +1,21 @@
+#include "asm/linkage.h"
+
+#define SYSCALL(name, opcode) \
+ ENTRY(name); \
+ movl $opcode, %eax; \
+ jmp __syscall_common; \
+ END(name)
+
+ .text
+ .align 4
+
+ENTRY(__syscall_common)
+ movq %rcx, %r10
+ syscall
+ ret
+END(__syscall_common)
+
+ENTRY(__cr_restore_rt)
+ movq $__NR_rt_sigreturn, %rax
+ syscall
+END(__cr_restore_rt)
diff --git a/compel/arch/x86/plugins/std/syscalls/syscall32.c b/compel/arch/x86/plugins/std/syscalls/syscall32.c
new file mode 100644
index 000000000000..88af59330adf
--- /dev/null
+++ b/compel/arch/x86/plugins/std/syscalls/syscall32.c
@@ -0,0 +1,85 @@
+#include "asm/types.h"
+#include "syscall-32.h"
+
+#define SYS_SOCKET 1 /* sys_socket(2) */
+#define SYS_BIND 2 /* sys_bind(2) */
+#define SYS_CONNECT 3 /* sys_connect(2) */
+#define SYS_SENDTO 11 /* sys_sendto(2) */
+#define SYS_RECVFROM 12 /* sys_recvfrom(2) */
+#define SYS_SHUTDOWN 13 /* sys_shutdown(2) */
+#define SYS_SETSOCKOPT 14 /* sys_setsockopt(2) */
+#define SYS_GETSOCKOPT 15 /* sys_getsockopt(2) */
+#define SYS_SENDMSG 16 /* sys_sendmsg(2) */
+#define SYS_RECVMSG 17 /* sys_recvmsg(2) */
+
+long sys_socket(int domain, int type, int protocol)
+{
+ u32 a[] = { (u32)domain, (u32)type, (u32)protocol };
+ return sys_socketcall(SYS_SOCKET, (unsigned long *)a);
+}
+
+long sys_connect(int sockfd, struct sockaddr *addr, int addrlen)
+{
+ u32 a[] = {(u32)sockfd, (u32)addr, (u32)addrlen};
+ return sys_socketcall(SYS_CONNECT, (unsigned long *)a);
+}
+
+long sys_sendto(int sockfd, void *buff, size_t len, unsigned int flags, struct sockaddr *addr, int addr_len)
+{
+ u32 a[] = {(u32)sockfd, (u32)buff, (u32)len, (u32)flags, (u32)addr, (u32)addr_len};
+ return sys_socketcall(SYS_SENDTO, (unsigned long *)a);
+}
+
+long sys_recvfrom(int sockfd, void *ubuf, size_t size, unsigned int flags, struct sockaddr *addr, int *addr_len)
+{
+ u32 a[] = {(u32)sockfd, (u32)ubuf, (u32)size, (u32)flags, (u32)addr, (u32)addr_len};
+ return sys_socketcall(SYS_RECVFROM, (unsigned long *)a);
+}
+
+long sys_sendmsg(int sockfd, const struct msghdr *msg, int flags)
+{
+ u32 a[] = {(u32)sockfd, (u32)msg, (u32)flags};
+ return sys_socketcall(SYS_SENDMSG, (unsigned long *)a);
+}
+
+long sys_recvmsg(int sockfd, struct msghdr *msg, int flags)
+{
+ u32 a[] = {(u32)sockfd, (u32)msg, (u32)flags};
+ return sys_socketcall(SYS_RECVMSG, (unsigned long *)a);
+}
+
+long sys_shutdown(int sockfd, int how)
+{
+ u32 a[] = {(u32)sockfd, (u32)how};
+ return sys_socketcall(SYS_SHUTDOWN, (unsigned long *)a);
+}
+
+long sys_bind(int sockfd, const struct sockaddr *addr, int addrlen)
+{
+ u32 a[] = {(u32)sockfd, (u32)addr, (u32)addrlen};
+ return sys_socketcall(SYS_BIND, (unsigned long *)a);
+}
+
+long sys_setsockopt(int sockfd, int level, int optname, const void *optval, unsigned int optlen)
+{
+ u32 a[] = {(u32)sockfd, (u32)level, (u32)optname, (u32)optval, (u32)optlen};
+ return sys_socketcall(SYS_SETSOCKOPT, (unsigned long *)a);
+}
+
+long sys_getsockopt(int sockfd, int level, int optname, const void *optval, unsigned int *optlen)
+{
+ u32 a[] = {(u32)sockfd, (u32)level, (u32)optname, (u32)optval, (u32)optlen};
+ return sys_socketcall(SYS_GETSOCKOPT, (unsigned long *)a);
+}
+
+#define SHMAT 21
+
+long sys_shmat(int shmid, void *shmaddr, int shmflag)
+{
+ return sys_ipc(SHMAT, shmid, shmflag, 0, shmaddr, 0);
+}
+
+long sys_pread(unsigned int fd, char *ubuf, u32 count, u64 pos)
+{
+ return sys_pread64(fd, ubuf, count, (u32)(pos & 0xffffffffu), (u32)(pos >> 32));
+}
diff --git a/compel/arch/x86/plugins/std/syscalls/syscall_32.tbl b/compel/arch/x86/plugins/std/syscalls/syscall_32.tbl
new file mode 100644
index 000000000000..7c4867c1b3f5
--- /dev/null
+++ b/compel/arch/x86/plugins/std/syscalls/syscall_32.tbl
@@ -0,0 +1,94 @@
+#
+# System calls table, please make sure the table consist only the syscalls
+# really used somewhere in project.
+#
+# code name arguments
+# -------------------------------------------------------------------------------------------------------------------------------------------------------------
+__NR_restart_syscall 0 sys_restart_syscall (void)
+__NR_exit 1 sys_exit (unsigned long error_code)
+__NR_read 3 sys_read (int fd, void *buf, unsigned long count)
+__NR_write 4 sys_write (int fd, const void *buf, unsigned long count)
+__NR_open 5 sys_open (const char *filename, int flags, unsigned int mode)
+__NR_close 6 sys_close (int fd)
+__NR_unlink 10 sys_unlink (char *pathname)
+__NR_lseek 19 sys_lseek (int fd, s32 offset, unsigned int origin)
+__NR_getpid 20 sys_getpid (void)
+__NR_mount 21 sys_mount (const char *dev_name, const char *dir_name, const char *type, unsigned long flags, const void *data)
+__NR_ptrace 26 sys_ptrace (long request, pid_t pid, void *addr, void *data)
+__NR_kill 37 sys_kill (long pid, int sig)
+__NR_mkdir 39 sys_mkdir (const char *name, int mode)
+__NR_rmdir 40 sys_rmdir (const char *name)
+__NR_brk 45 sys_brk (void *addr)
+__NR_umount2 52 sys_umount2 (char *name, int flags)
+__NR_ioctl 54 sys_ioctl (unsigned int fd, unsigned int cmd, unsigned long arg)
+__NR_fcntl 55 sys_fcntl (unsigned int fd, unsigned int cmd, unsigned long arg)
+__NR_umask 60 sys_umask (int mask)
+__NR_setrlimit 75 sys_setrlimit (unsigned int resource, struct krlimit *rlim)
+__NR_munmap 91 sys_munmap (void *addr, unsigned long len)
+__NR_setpriority 97 sys_setpriority (int which, int who, int nice)
+__NR_socketcall 102 sys_socketcall (int call, unsigned long *args)
+__NR_setitimer 104 sys_setitimer (int which, struct itimerval *in, struct itimerval *out)
+__NR_getitimer 105 sys_getitimer (int which, struct itimerval *it)
+__NR_wait4 114 sys_wait4 (pid_t pid, int *stat_addr, int options, struct rusage *ru)
+__NR_ipc 117 sys_ipc (unsigned int call, int first, unsigned long second, unsigned long third, void *ptr, long fifth)
+__NR_clone 120 sys_clone (unsigned long flags, void *child_stack, void *parent_tid, void *child_tid)
+__NR_mprotect 125 sys_mprotect (const void *addr, unsigned long len, unsigned long prot)
+__NR_getpgid 132 sys_getpgid (pid_t pid)
+__NR_personality 136 sys_personality (unsigned int personality)
+__NR_flock 143 sys_flock (int fd, unsigned long cmd)
+__NR_getsid 147 sys_getsid (void)
+__NR_sched_setscheduler 156 sys_sched_setscheduler (int pid, int policy, struct sched_param *p)
+__NR_nanosleep 162 sys_nanosleep (struct timespec *rqtp, struct timespec *rmtp)
+__NR_mremap 163 sys_mremap (unsigned long addr, unsigned long old_len, unsigned long new_len, unsigned long flags, unsigned long new_addr)
+__NR_prctl 172 sys_prctl (int option, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5)
+__NR_rt_sigreturn 173 sys_rt_sigreturn (void)
+__NR_rt_sigaction 174 sys_sigaction (int signum, const rt_sigaction_t *act, rt_sigaction_t *oldact, size_t sigsetsize)
+__NR_rt_sigprocmask 175 sys_sigprocmask (int how, k_rtsigset_t *set, k_rtsigset_t *oset, size_t sigsetsize)
+__NR_rt_sigqueueinfo 178 sys_rt_sigqueueinfo (pid_t pid, int sig, siginfo_t *uinfo)
+__NR_pread64 180 sys_pread64 (unsigned int fd, char *ubuf, u32 count, u32 poslo, u32 poshi)
+__NR_capget 184 sys_capget (struct cap_header *h, struct cap_data *d)
+__NR_capset 185 sys_capset (struct cap_header *h, struct cap_data *d)
+__NR_sigaltstack 186 sys_sigaltstack (const void *uss_ptr, void *uoss_ptr)
+__NR_mmap2 192 sys_mmap (void *addr, unsigned long len, unsigned long prot, unsigned long flags, unsigned long fd, unsigned long pgoff)
+__NR_getgroups32 205 sys_getgroups (int gsize, unsigned int *groups)
+__NR_setgroups32 206 sys_setgroups (int gsize, unsigned int *groups)
+__NR_setresuid32 208 sys_setresuid (int uid, int euid, int suid)
+__NR_getresuid32 209 sys_getresuid (int *uid, int *euid, int *suid)
+__NR_setresgid32 210 sys_setresgid (int gid, int egid, int sgid)
+__NR_getresgid32 211 sys_getresgid (int *gid, int *egid, int *sgid)
+__NR_setfsuid32 215 sys_setfsuid (int fsuid)
+__NR_setfsgid32 216 sys_setfsgid (int fsgid)
+__NR_mincore 218 sys_mincore (void *addr, unsigned long size, unsigned char *vec)
+__NR_madvise 219 sys_madvise (unsigned long start, size_t len, int behavior)
+__NR_gettid 224 sys_gettid (void)
+__NR_futex 240 sys_futex (u32 *uaddr, int op, u32 val, struct timespec *utime, u32 *uaddr2, u32 val3)
+__NR_set_thread_area 243 sys_set_thread_area (user_desc_t *info)
+__NR_get_thread_area 244 sys_get_thread_area (user_desc_t *info)
+__NR_io_setup 245 sys_io_setup (unsigned nr_reqs, aio_context_t *ctx32p)
+__NR_io_getevents 247 sys_io_getevents (aio_context_t ctx_id, long min_nr, long nr, struct io_event *events, struct timespec *timeout)
+__NR_io_submit 248 sys_io_submit (aio_context_t ctx_id, long nr, struct iocb **iocbpp)
+__NR_exit_group 252 sys_exit_group (int error_code)
+__NR_set_tid_address 258 sys_set_tid_address (int *tid_addr)
+__NR_timer_create 259 sys_timer_create (clockid_t which_clock, struct sigevent *timer_event_spec, kernel_timer_t *created_timer_id)
+__NR_timer_settime 260 sys_timer_settime (kernel_timer_t timer_id, int flags, struct itimerspec *new, struct itimerspec *old)
+__NR_timer_gettime 261 sys_timer_gettime (int timer_id, struct itimerspec *setting)
+__NR_timer_getoverrun 262 sys_timer_getoverrun (int timer_id)
+__NR_timer_delete 263 sys_timer_delete (kernel_timer_t timer_id)
+__NR_clock_gettime 265 sys_clock_gettime (int which_clock, struct timespec *tp)
+__NR_waitid 284 sys_waitid (int which, pid_t pid, struct siginfo *infop, int options, struct rusage *ru)
+__NR_openat 295 sys_openat (int dfd, const char *filename, int flags, int mode)
+__NR_readlinkat 305 sys_readlinkat (int fd, const char *path, char *buf, int bufsize)
+__NR_set_robust_list 311 sys_set_robust_list (struct robust_list_head *head, size_t len)
+__NR_get_robust_list 312 sys_get_robust_list (int pid, struct robust_list_head **head_ptr, size_t *len_ptr)
+__NR_vmsplice 316 sys_vmsplice (int fd, const struct iovec *iov, unsigned int nr_segs, unsigned int flags)
+__NR_signalfd 321 sys_signalfd (int ufd, const k_rtsigset_t *sigmask, size_t sigsetsize)
+__NR_timerfd_settime 325 sys_timerfd_settime (int ufd, int flags, const struct itimerspec *utmr, struct itimerspec *otmr)
+__NR_rt_tgsigqueueinfo 335 sys_rt_tgsigqueueinfo (pid_t tgid, pid_t pid, int sig, siginfo_t *uinfo)
+__NR_fanotify_init 338 sys_fanotify_init (unsigned int flags, unsigned int event_f_flags)
+__NR_fanotify_mark 339 sys_fanotify_mark (int fanotify_fd, unsigned int flag, u32 mask, int dfd, const char *pathname)
+__NR_open_by_handle_at 342 sys_open_by_handle_at (int mountdirfd, struct file_handle *handle, int flags)
+__NR_setns 346 sys_setns (int fd, int nstype)
+__NR_kcmp 349 sys_kcmp (pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2)
+__NR_seccomp 354 sys_seccomp (unsigned int op, unsigned int flags, const char *uargs)
+__NR_memfd_create 356 sys_memfd_create (const char *name, unsigned int flags)
+__NR_userfaultfd 374 sys_userfaultfd (int flags)
diff --git a/compel/arch/x86/plugins/std/syscalls/syscall_64.tbl b/compel/arch/x86/plugins/std/syscalls/syscall_64.tbl
new file mode 100644
index 000000000000..285874938b38
--- /dev/null
+++ b/compel/arch/x86/plugins/std/syscalls/syscall_64.tbl
@@ -0,0 +1,105 @@
+#
+# System calls table, please make sure the table consist only the syscalls
+# really used somewhere in project.
+#
+# __NR_name code name arguments
+# -------------------------------------------------------------------------------------------------------------------------------------------------------------
+__NR_read 0 sys_read (int fd, void *buf, unsigned long count)
+__NR_write 1 sys_write (int fd, const void *buf, unsigned long count)
+__NR_open 2 sys_open (const char *filename, unsigned long flags, unsigned long mode)
+__NR_close 3 sys_close (int fd)
+__NR_lseek 8 sys_lseek (int fd, unsigned long offset, unsigned long origin)
+__NR_mmap 9 sys_mmap (void *addr, unsigned long len, unsigned long prot, unsigned long flags, unsigned long fd, unsigned long offset)
+__NR_mprotect 10 sys_mprotect (const void *addr, unsigned long len, unsigned long prot)
+__NR_munmap 11 sys_munmap (void *addr, unsigned long len)
+__NR_brk 12 sys_brk (void *addr)
+__NR_rt_sigaction 13 sys_sigaction (int signum, const rt_sigaction_t *act, rt_sigaction_t *oldact, size_t sigsetsize)
+__NR_rt_sigprocmask 14 sys_sigprocmask (int how, k_rtsigset_t *set, k_rtsigset_t *old, size_t sigsetsize)
+__NR_rt_sigreturn 15 sys_rt_sigreturn (void)
+__NR_ioctl 16 sys_ioctl (unsigned int fd, unsigned int cmd, unsigned long arg)
+__NR_pread64 17 sys_pread (unsigned int fd, char *buf, size_t count, loff_t pos)
+__NR_mremap 25 sys_mremap (unsigned long addr, unsigned long old_len, unsigned long new_len, unsigned long flags, unsigned long new_addr)
+__NR_mincore 27 sys_mincore (void *addr, unsigned long size, unsigned char *vec)
+__NR_madvise 28 sys_madvise (unsigned long start, size_t len, int behavior)
+__NR_shmat 30 sys_shmat (int shmid, void *shmaddr, int shmflag)
+__NR_dup2 33 sys_dup2 (int oldfd, int newfd)
+__NR_nanosleep 35 sys_nanosleep (struct timespec *req, struct timespec *rem)
+__NR_getitimer 36 sys_getitimer (int which, const struct itimerval *val)
+__NR_setitimer 38 sys_setitimer (int which, const struct itimerval *val, struct itimerval *old)
+__NR_getpid 39 sys_getpid (void)
+__NR_socket 41 sys_socket (int domain, int type, int protocol)
+__NR_connect 42 sys_connect (int sockfd, struct sockaddr *addr, int addrlen)
+__NR_sendto 44 sys_sendto (int sockfd, void *buff, size_t len, unsigned int flags, struct sockaddr *addr, int addr_len)
+__NR_recvfrom 45 sys_recvfrom (int sockfd, void *ubuf, size_t size, unsigned int flags, struct sockaddr *addr, int *addr_len)
+__NR_sendmsg 46 sys_sendmsg (int sockfd, const struct msghdr *msg, int flags)
+__NR_recvmsg 47 sys_recvmsg (int sockfd, struct msghdr *msg, int flags)
+__NR_shutdown 48 sys_shutdown (int sockfd, int how)
+__NR_bind 49 sys_bind (int sockfd, const struct sockaddr *addr, int addrlen)
+__NR_setsockopt 54 sys_setsockopt (int sockfd, int level, int optname, const void *optval, socklen_t optlen)
+__NR_getsockopt 55 sys_getsockopt (int sockfd, int level, int optname, const void *optval, socklen_t *optlen)
+__NR_clone 56 sys_clone (unsigned long flags, void *child_stack, void *parent_tid, void *child_tid)
+__NR_exit 60 sys_exit (unsigned long error_code)
+__NR_wait4 61 sys_wait4 (int pid, int *status, int options, struct rusage *ru)
+__NR_kill 62 sys_kill (long pid, int sig)
+__NR_fcntl 72 sys_fcntl (int fd, int type, long arg)
+__NR_flock 73 sys_flock (int fd, unsigned long cmd)
+__NR_mkdir 83 sys_mkdir (const char *name, int mode)
+__NR_rmdir 84 sys_rmdir (const char *name)
+__NR_unlink 87 sys_unlink (char *pathname)
+__NR_umask 95 sys_umask (int mask)
+__NR_ptrace 101 sys_ptrace (long request, pid_t pid, void *addr, void *data)
+__NR_getgroups 115 sys_getgroups (int gsize, unsigned int *groups)
+__NR_setgroups 116 sys_setgroups (int gsize, unsigned int *groups)
+__NR_setresuid 117 sys_setresuid (int uid, int euid, int suid)
+__NR_getresuid 118 sys_getresuid (int *uid, int *euid, int *suid)
+__NR_setresgid 119 sys_setresgid (int gid, int egid, int sgid)
+__NR_getresgid 120 sys_getresgid (int *gid, int *egid, int *sgid)
+__NR_getpgid 121 sys_getpgid (pid_t pid)
+__NR_setfsuid 122 sys_setfsuid (int fsuid)
+__NR_setfsgid 123 sys_setfsgid (int fsgid)
+__NR_getsid 124 sys_getsid (void)
+__NR_capget 125 sys_capget (struct cap_header *h, struct cap_data *d)
+__NR_capset 126 sys_capset (struct cap_header *h, struct cap_data *d)
+__NR_rt_sigqueueinfo 129 sys_rt_sigqueueinfo (pid_t pid, int sig, siginfo_t *info)
+__NR_sigaltstack 131 sys_sigaltstack (const void *uss, void *uoss)
+__NR_personality 135 sys_personality (unsigned int personality)
+__NR_setpriority 141 sys_setpriority (int which, int who, int nice)
+__NR_sched_setscheduler 144 sys_sched_setscheduler (int pid, int policy, struct sched_param *p)
+__NR_prctl 157 sys_prctl (int option, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5)
+__NR_arch_prctl 158 sys_arch_prctl (int option, unsigned long addr)
+__NR_setrlimit 160 sys_setrlimit (int resource, struct krlimit *rlim)
+__NR_mount 165 sys_mount (char *dev_nmae, char *dir_name, char *type, unsigned long flags, void *data)
+__NR_umount2 166 sys_umount2 (char *name, int flags)
+__NR_gettid 186 sys_gettid (void)
+__NR_futex 202 sys_futex (u32 *uaddr, int op, u32 val, struct timespec *utime, u32 *uaddr2, u32 val3)
+__NR_set_thread_area 205 sys_set_thread_area (user_desc_t *info)
+__NR_io_setup 206 sys_io_setup (unsigned nr_events, aio_context_t *ctx)
+__NR_io_getevents 208 sys_io_getevents (aio_context_t ctx, long min_nr, long nr, struct io_event *evs, struct timespec *tmo)
+__NR_io_submit 209 sys_io_submit (aio_context_t ctx, long nr, struct iocb **iocbpp)
+__NR_get_thread_area 211 sys_get_thread_area (user_desc_t *info)
+__NR_set_tid_address 218 sys_set_tid_address (int *tid_addr)
+__NR_restart_syscall 219 sys_restart_syscall (void)
+__NR_sys_timer_create 222 sys_timer_create (clockid_t which_clock, struct sigevent *timer_event_spec, kernel_timer_t *created_timer_id)
+__NR_sys_timer_settime 223 sys_timer_settime (kernel_timer_t timer_id, int flags, const struct itimerspec *new_setting, struct itimerspec *old_setting)
+__NR_sys_timer_gettime 224 sys_timer_gettime (int timer_id, const struct itimerspec *setting)
+__NR_sys_timer_getoverrun 225 sys_timer_getoverrun (int timer_id)
+__NR_sys_timer_delete 226 sys_timer_delete (kernel_timer_t timer_id)
+__NR_clock_gettime 228 sys_clock_gettime (const clockid_t which_clock, const struct timespec *tp)
+__NR_exit_group 231 sys_exit_group (int error_code)
+__NR_openat 257 sys_openat (int dfd, const char *filename, int flags, int mode)
+__NR_waitid 247 sys_waitid (int which, pid_t pid, struct siginfo *infop, int options, struct rusage *ru)
+__NR_readlinkat 267 sys_readlinkat (int fd, const char *path, char *buf, int bufsize)
+__NR_set_robust_list 273 sys_set_robust_list (struct robust_list_head *head, size_t len)
+__NR_get_robust_list 274 sys_get_robust_list (int pid, struct robust_list_head **head_ptr, size_t *len_ptr)
+__NR_seccomp 317 sys_seccomp (unsigned int op, unsigned int flags, const char *uargs)
+__NR_vmsplice 278 sys_vmsplice (int fd, const struct iovec *iov, unsigned long nr_segs, unsigned int flags)
+__NR_timerfd_settime 286 sys_timerfd_settime (int ufd, int flags, const struct itimerspec *utmr, struct itimerspec *otmr)
+__NR_signalfd4 289 sys_signalfd (int fd, k_rtsigset_t *mask, size_t sizemask, int flags)
+__NR_rt_tgsigqueueinfo 297 sys_rt_tgsigqueueinfo (pid_t tgid, pid_t pid, int sig, siginfo_t *info)
+__NR_fanotify_init 300 sys_fanotify_init (unsigned int flags, unsigned int event_f_flags)
+__NR_fanotify_mark 301 sys_fanotify_mark (int fanotify_fd, unsigned int flags, u64 mask, int dfd, const char *pathname)
+__NR_open_by_handle_at 304 sys_open_by_handle_at (int mountdirfd, struct file_handle *handle, int flags)
+__NR_setns 308 sys_setns (int fd, int nstype)
+__NR_kcmp 312 sys_kcmp (pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2)
+__NR_memfd_create 319 sys_memfd_create (const char *name, unsigned int flags)
+__NR_userfaultfd 323 sys_userfaultfd (int flags)
diff --git a/compel/arch/x86/scripts/pack.lds.S b/compel/arch/x86/scripts/pack.lds.S
new file mode 100644
index 000000000000..3b94b3ecd2f2
--- /dev/null
+++ b/compel/arch/x86/scripts/pack.lds.S
@@ -0,0 +1,30 @@
+OUTPUT_ARCH(i386:x86-64)
+SECTIONS
+{
+ . = ALIGN(64);
+ .text : {
+ *(.compel.prologue.text)
+ *(.text*)
+ } =0x0
+
+ . = ALIGN(64);
+ .compel.init : {
+ *(.compel.init)
+ } =0xff
+
+ . = ALIGN(64);
+ .data : {
+ *(.data*)
+ *(.bss*)
+ *(.rodata*)
+ } =0x0
+
+ /DISCARD/ : {
+ *(.debug*)
+ *(.comment*)
+ *(.note*)
+ *(.group*)
+ *(.eh_frame*)
+ *(*)
+ }
+}
diff --git a/compel/arch/x86/src/lib/handle-elf.c b/compel/arch/x86/src/lib/handle-elf.c
new file mode 100644
index 000000000000..7cfbaa1dd026
--- /dev/null
+++ b/compel/arch/x86/src/lib/handle-elf.c
@@ -0,0 +1,29 @@
+#include <string.h>
+
+#include "uapi/compel.h"
+
+#include "handle-elf.h"
+#include "piegen.h"
+
+static const unsigned char __maybe_unused
+elf_ident_64_le[EI_NIDENT] = {
+ 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+};
+
+static const unsigned char __maybe_unused
+elf_ident_32[EI_NIDENT] = {
+ 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+};
+
+int handle_binary(void *mem, size_t size)
+{
+ if (memcmp(mem, elf_ident_32, sizeof(elf_ident_32)) == 0)
+ return handle_elf_x86_32(mem, size);
+ else if (memcmp(mem, elf_ident_64_le, sizeof(elf_ident_64_le)) == 0)
+ return handle_elf_x86_64(mem, size);
+
+ pr_err("Unsupported Elf format detected\n");
+ return -EINVAL;
+}
diff --git a/compel/arch/x86/include/handle-elf.h b/compel/arch/x86/src/lib/include/handle-elf.h
similarity index 59%
rename from compel/arch/x86/include/handle-elf.h
rename to compel/arch/x86/src/lib/include/handle-elf.h
index eea94d4633ab..bfc935a4e751 100644
--- a/compel/arch/x86/include/handle-elf.h
+++ b/compel/arch/x86/src/lib/include/handle-elf.h
@@ -1,18 +1,22 @@
-#ifndef __COMPEL_HANDLE_ELF_H__
-#define __COMPEL_HANDLE_ELF_H__
+#ifndef COMPEL_HANDLE_ELF_H__
+#define COMPEL_HANDLE_ELF_H__
#ifdef CONFIG_X86_32
-#include "uapi/elf32-types.h"
+#include "elf32-types.h"
+
#define ELF_X86_32
-#define __handle_elf handle_elf_x86_32
+
+#define __handle_elf handle_elf_x86_32
#define arch_is_machine_supported(e_machine) (e_machine == EM_386)
#else /* CONFIG_X86_64 */
-#include "uapi/elf64-types.h"
+#include "elf64-types.h"
+
#define ELF_X86_64
-#define __handle_elf handle_elf_x86_64
+
+#define __handle_elf handle_elf_x86_64
#define arch_is_machine_supported(e_machine) (e_machine == EM_X86_64)
#endif
@@ -20,4 +24,4 @@
extern int handle_elf_x86_32(void *mem, size_t size);
extern int handle_elf_x86_64(void *mem, size_t size);
-#endif /* __COMPEL_HANDLE_ELF_H__ */
+#endif /* COMPEL_HANDLE_ELF_H__ */
diff --git a/compel/include/elf32-types.h b/compel/include/elf32-types.h
new file mode 100644
index 000000000000..b516ba17ea55
--- /dev/null
+++ b/compel/include/elf32-types.h
@@ -0,0 +1,16 @@
+#ifndef COMPEL_ELF32_TYPES_H__
+#define COMPEL_ELF32_TYPES_H__
+
+#define Elf_Ehdr Elf32_Ehdr
+#define Elf_Shdr Elf32_Shdr
+#define Elf_Sym Elf32_Sym
+#define Elf_Rel Elf32_Rel
+#define Elf_Rela Elf32_Rela
+
+#define ELF_ST_TYPE ELF32_ST_TYPE
+#define ELF_ST_BIND ELF32_ST_BIND
+
+#define ELF_R_SYM ELF32_R_SYM
+#define ELF_R_TYPE ELF32_R_TYPE
+
+#endif /* COMPEL_ELF32_TYPES_H__ */
diff --git a/compel/include/elf64-types.h b/compel/include/elf64-types.h
new file mode 100644
index 000000000000..c4d5f1c72aa2
--- /dev/null
+++ b/compel/include/elf64-types.h
@@ -0,0 +1,16 @@
+#ifndef COMPEL_ELF64_TYPES_H__
+#define COMPEL_ELF64_TYPES_H__
+
+#define Elf_Ehdr Elf64_Ehdr
+#define Elf_Shdr Elf64_Shdr
+#define Elf_Sym Elf64_Sym
+#define Elf_Rel Elf64_Rel
+#define Elf_Rela Elf64_Rela
+
+#define ELF_ST_TYPE ELF64_ST_TYPE
+#define ELF_ST_BIND ELF64_ST_BIND
+
+#define ELF_R_SYM ELF64_R_SYM
+#define ELF_R_TYPE ELF64_R_TYPE
+
+#endif /* COMPEL_ELF64_TYPES_H__ */
diff --git a/compel/include/piegen.h b/compel/include/piegen.h
index 736152a2c475..f1ed2e13d309 100644
--- a/compel/include/piegen.h
+++ b/compel/include/piegen.h
@@ -1,5 +1,5 @@
-#ifndef __ELFTIL_H__
-#define __ELFTIL_H__
+#ifndef COMPEL_PIEGEN_H__
+#define COMPEL_PIEGEN_H__
#include <stdio.h>
#include <unistd.h>
@@ -51,20 +51,4 @@ do { \
extern int handle_binary(void *mem, size_t size);
-static const unsigned char __maybe_unused
-elf_ident_32[EI_NIDENT] = {
- 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-};
-static const unsigned char __maybe_unused
-elf_ident_64_le[EI_NIDENT] = {
- 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-};
-static const unsigned char __maybe_unused
-elf_ident_64_be[EI_NIDENT] = {
- 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x02, 0x01, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-};
-
-#endif /* __ELFTIL_H__ */
+#endif /* COMPEL_PIEGEN_H__ */
diff --git a/compel/include/uapi/compel.h b/compel/include/uapi/compel.h
new file mode 100644
index 000000000000..67b67c476c63
--- /dev/null
+++ b/compel/include/uapi/compel.h
@@ -0,0 +1,27 @@
+#ifndef UAPI_COMPEL_H__
+#define UAPI_COMPEL_H__
+
+#include <errno.h>
+
+#define COMPEL_TYPE_INT (1u << 0)
+#define COMPEL_TYPE_LONG (1u << 1)
+#define COMPEL_TYPE_GOTPCREL (1u << 2)
+
+typedef struct {
+ unsigned int offset;
+ unsigned int type;
+ long addend;
+ long value;
+} compel_reloc_t;
+
+/*
+ * FIXME: Backward compat layer for CRIU. Need to
+ * drop it later, before the release.
+ */
+
+#define elf_reloc_t compel_reloc_t
+#define PIEGEN_TYPE_INT COMPEL_TYPE_INT
+#define PIEGEN_TYPE_LONG COMPEL_TYPE_LONG
+#define PIEGEN_TYPE_GOTPCREL COMPEL_TYPE_GOTPCREL
+
+#endif /* UAPI_COMPEL_H__ */
diff --git a/compel/include/uapi/elf32-types.h b/compel/include/uapi/elf32-types.h
deleted file mode 100644
index 51bf4a24a59b..000000000000
--- a/compel/include/uapi/elf32-types.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#ifndef __COMPEL_ELF32_TYPES_H__
-#define __COMPEL_ELF32_TYPES_H__
-
-#define Ehdr_t Elf32_Ehdr
-#define Shdr_t Elf32_Shdr
-#define Sym_t Elf32_Sym
-#define Rel_t Elf32_Rel
-#define Rela_t Elf32_Rela
-
-#define Off_t Elf32_Off
-#define Word_t Elf32_Word
-#define Half_t Elf32_Half
-
-#define ELF_ST_TYPE ELF32_ST_TYPE
-#define ELF_ST_BIND ELF32_ST_BIND
-
-#define ELF_R_SYM ELF32_R_SYM
-#define ELF_R_TYPE ELF32_R_TYPE
-
-#endif /* __COMPEL_ELF32_TYPES_H__ */
diff --git a/compel/include/uapi/elf64-types.h b/compel/include/uapi/elf64-types.h
deleted file mode 100644
index d4d6f6f163da..000000000000
--- a/compel/include/uapi/elf64-types.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#ifndef __COMPEL_ELF64_TYPES_H__
-#define __COMPEL_ELF64_TYPES_H__
-
-#define Ehdr_t Elf64_Ehdr
-#define Shdr_t Elf64_Shdr
-#define Sym_t Elf64_Sym
-#define Rel_t Elf64_Rel
-#define Rela_t Elf64_Rela
-
-#define Off_t Elf64_Off
-#define Word_t Elf64_Word
-#define Half_t Elf64_Half
-
-#define ELF_ST_TYPE ELF64_ST_TYPE
-#define ELF_ST_BIND ELF64_ST_BIND
-
-#define ELF_R_SYM ELF64_R_SYM
-#define ELF_R_TYPE ELF64_R_TYPE
-
-#endif /* __COMPEL_ELF64_TYPES_H__ */
diff --git a/compel/include/uapi/int.h b/compel/include/uapi/int.h
new file mode 100644
index 000000000000..ac3088d5ac3b
--- /dev/null
+++ b/compel/include/uapi/int.h
@@ -0,0 +1,15 @@
+#ifndef __CR_INT_H__
+#define __CR_INT_H__
+
+#include <stdint.h>
+
+typedef uint64_t u64;
+typedef int64_t s64;
+typedef uint32_t u32;
+typedef int32_t s32;
+typedef uint16_t u16;
+typedef int16_t s16;
+typedef uint8_t u8;
+typedef int8_t s8;
+
+#endif /* __CR_INT_H__ */
diff --git a/compel/include/uapi/piegen-err.h b/compel/include/uapi/piegen-err.h
deleted file mode 100644
index f8a2349a1d26..000000000000
--- a/compel/include/uapi/piegen-err.h
+++ /dev/null
@@ -1,10 +0,0 @@
-#ifndef __PIEGEN_ERR_H__
-#define __PIEGEN_ERR_H__
-
-/* Error numbers for piegen. Success is 0, so errors should differ. */
-#define E_UNKNOWN 1
-#define E_NOMEM 2
-#define E_NOT_ELF 3
-#define E_NO_STR_SEC 4
-
-#endif /* __PIEGEN_ERR_H__ */
diff --git a/compel/include/uapi/plugins.h b/compel/include/uapi/plugins.h
new file mode 100644
index 000000000000..e9ebfb67f7c7
--- /dev/null
+++ b/compel/include/uapi/plugins.h
@@ -0,0 +1,35 @@
+#ifndef UAPI_COMPEL_PLUGIN_H__
+#define UAPI_COMPEL_PLUGIN_H__
+
+#define __init __attribute__((__used__)) __attribute__ ((__section__(".compel.init")))
+#define __exit __attribute__((__used__)) __attribute__ ((__section__(".compel.exit")))
+
+#ifndef __ASSEMBLY__
+
+typedef struct {
+ const char *name;
+ int (*init)(void);
+ void (*exit)(void);
+} plugin_init_t;
+
+#define plugin_register(___desc) \
+ static const plugin_init_t * const \
+ ___ptr__##___desc __init = &___desc;
+
+#define PLUGIN_REGISTER(___id, ___name, ___init, ___exit) \
+ static const plugin_init_t __plugin_desc_##___id = { \
+ .name = ___name, \
+ .init = ___init, \
+ .exit = ___exit, \
+ }; \
+ plugin_register(__plugin_desc_##___id);
+
+#define PLUGIN_REGISTER_DUMMY(___id) \
+ static const plugin_init_t __plugin_desc_##___id = { \
+ .name = #___id, \
+ }; \
+ plugin_register(__plugin_desc_##___id);
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* UAPI_COMPEL_PLUGIN_H__ */
diff --git a/compel/include/uapi/types.h b/compel/include/uapi/types.h
deleted file mode 100644
index 34696e8c6aa5..000000000000
--- a/compel/include/uapi/types.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef __PIEGEN_TYPES_H__
-#define __PIEGEN_TYPES_H__
-
-#define PIEGEN_TYPE_INT (1u << 0)
-#define PIEGEN_TYPE_LONG (1u << 1)
-#define PIEGEN_TYPE_GOTPCREL (1u << 2)
-
-typedef struct {
- unsigned int offset;
- unsigned int type;
- long addend;
- long value;
-} elf_reloc_t;
-
-#endif /* __PIEGEN_TYPES_H__ */
diff --git a/compel/include/uapi/types.h b/compel/include/uapi/types.h
new file mode 120000
index 000000000000..28c80ee9f7cf
--- /dev/null
+++ b/compel/include/uapi/types.h
@@ -0,0 +1 @@
+compel.h
\ No newline at end of file
diff --git a/compel/plugins/Makefile b/compel/plugins/Makefile
new file mode 100644
index 000000000000..f0b1de802368
--- /dev/null
+++ b/compel/plugins/Makefile
@@ -0,0 +1,127 @@
+.PHONY: .FORCE
+
+ARCH_DIR := compel/arch/$(ARCH)/plugins
+
+ccflags-y += -iquote $(obj)/include/
+ccflags-y += -iquote $(obj)/include/uapi
+ccflags-y += -iquote $(SRC_DIR)/criu/include
+ccflags-y += -iquote $(SRC_DIR)/criu/arch/$(ARCH)/include
+ccflags-y += -iquote $(SRC_DIR)/compel/include
+ccflags-y += -iquote $(SRC_DIR)/$(ARCH_DIR)/include
+
+asflags-y += -iquote $(SRC_DIR)/criu/arch/$(ARCH)/include
+asflags-y += -iquote $(SRC_DIR)/compel/plugins/include/uapi
+asflags-y += -iquote $(SRC_DIR)/$(ARCH_DIR)
+
+#
+# STD plugin
+target += std
+std-obj-y += std/std.o
+std-obj-y += std/string.o
+std-obj-y += arch/$(ARCH)/plugins/std/syscalls-64.o
+std-obj-y += arch/$(ARCH)/plugins/std/calls32.o
+
+sys-proto-generic := $(obj)/include/uapi/std/syscall.h
+sys-codes-generic := $(obj)/include/uapi/std/syscall-codes.h
+sys-codes = $(obj)/include/uapi/std/syscall-codes-$(1).h
+sys-proto = $(obj)/include/uapi/std/syscall-$(1).h
+sys-def = $(ARCH_DIR)/std/syscalls/syscall_$(1).tbl
+sys-asm = $(ARCH_DIR)/std/syscalls-$(1).S
+sys-asm-common-name = std/syscalls/syscall-common-x86-$(1).S
+sys-asm-common = $(ARCH_DIR)/$(sys-asm-common-name)
+
+sys-bits := 64
+
+AV := $$$$
+
+define gen-rule-sys-codes
+$(sys-codes): $(sys-def)
+ $(call msg-gen, $$@)
+ $(Q) echo "/* Autogenerated, don't edit */" > $$@
+ $(Q) echo "#ifndef ASM_SYSCALL_CODES_H_$(1)__" >> $$@
+ $(Q) echo "#define ASM_SYSCALL_CODES_H_$(1)__" >> $$@
+ $(Q) cat $$< | awk '/^__NR/{SYSN=$(AV)1; \
+ sub("^__NR", "SYS", SYSN); \
+ print "\n#ifndef ", $(AV)1; \
+ print "#define", $(AV)1, $(AV)2; \
+ print "#endif"; \
+ print "\n#ifndef ", SYSN; \
+ print "#define ", SYSN, $(AV)1; \
+ print "#endif";}' >> $$@
+ $(Q) echo "#endif /* ASM_SYSCALL_CODES_H_$(1)__ */" >> $$@
+endef
+
+define gen-rule-sys-proto
+$(sys-proto): $(sys-def)
+ $(call msg-gen, $$@)
+ $(Q) echo "/* Autogenerated, don't edit */" > $$@
+ $(Q) echo "#ifndef ASM_SYSCALL_PROTO_H_$(1)__" >> $$@
+ $(Q) echo "#define ASM_SYSCALL_PROTO_H_$(1)__" >> $$@
+ $(Q) echo '#include "std/syscall-codes-$(1).h"' >> $$@
+ $(Q) echo '#include "syscall-types.h"' >> $$@
+ifeq ($(1),32)
+ $(Q) echo '#include "asm/syscall32.h"' >> $$@
+endif
+ $(Q) cat $$< | awk '/^__NR/{print "extern long", $(AV)3, \
+ substr($(AV)0, index($(AV)0,$(AV)4)), ";"}' >> $$@
+ $(Q) echo "#endif /* ASM_SYSCALL_PROTO_H_$(1)__ */" >> $$@
+endef
+
+define gen-rule-sys-asm
+$(sys-asm): $(sys-def) $(sys-asm-common) $(sys-codes) $(sys-proto)
+ $(call msg-gen, $$@)
+ $(Q) echo "/* Autogenerated, don't edit */" > $$@
+ $(Q) echo '#include "std/syscall-codes-$(1).h"' >> $$@
+ $(Q) echo '#include "$(sys-asm-common-name)"' >> $$@
+ $(Q) cat $$< | awk '/^__NR/{print "SYSCALL(", $(AV)3, ",", $(AV)2, ")"}' >> $$@
+endef
+
+define gen-rule-sys-exec-tbl
+$(sys-exec-tbl): $(sys-def) $(sys-codes) $(sys-proto) $(sys-proto-generic)
+ $(call msg-gen, $$@)
+ $(Q) echo "/* Autogenerated, don't edit */" > $$@
+ $(Q) cat $$< | awk '/^__NR/{print \
+ "SYSCALL(", substr($(AV)3, 5), ",", $(AV)2, ")"}' >> $$@
+endef
+
+$(sys-codes-generic): $(ARCH_DIR)/std/syscalls/syscall_32.tbl
+ $(call msg-gen, $@)
+ $(Q) echo "/* Autogenerated, don't edit */" > $@
+ $(Q) echo "#ifndef __ASM_CR_SYSCALL_CODES_H__" >> $@
+ $(Q) echo "#define __ASM_CR_SYSCALL_CODES_H__" >> $@
+ $(Q) echo '#include "std/syscall-codes-64.h"' >> $@
+ $(Q) cat $< | awk '/^__NR/{NR32=$$1; \
+ sub("^__NR", "__NR32", NR32); \
+ print "\n#ifndef ", NR32; \
+ print "#define ", NR32, $$2; \
+ print "#endif";}' >> $@
+ $(Q) echo "#endif /* __ASM_CR_SYSCALL_CODES_H__ */" >> $@
+
+$(sys-proto-generic): $(strip $(call map,sys-proto,$(sys-bits)))
+ $(call msg-gen, $@)
+ $(Q) echo "/* Autogenerated, don't edit */" > $@
+ $(Q) echo "#ifndef __ASM_CR_SYSCALL_PROTO_H__" >> $@
+ $(Q) echo "#define __ASM_CR_SYSCALL_PROTO_H__" >> $@
+ $(Q) echo "" >> $@
+ $(Q) echo "#ifdef CONFIG_X86_32" >> $@
+ $(Q) echo '#include "std/syscall-32.h"' >> $@
+ $(Q) echo "#else" >> $@
+ $(Q) echo '#include "std/syscall-64.h"' >> $@
+ $(Q) echo "#endif /* CONFIG_X86_32 */" >> $@
+ $(Q) echo "" >> $@
+ $(Q) echo "#endif /* __ASM_CR_SYSCALL_PROTO_H__ */" >> $@
+
+$(eval $(call map,gen-rule-sys-codes,$(sys-bits)))
+$(eval $(call map,gen-rule-sys-proto,$(sys-bits)))
+$(eval $(call map,gen-rule-sys-asm,$(sys-bits)))
+
+std-headers-deps += $(call sys-codes,$(sys-bits))
+std-headers-deps += $(call sys-proto,$(sys-bits))
+std-headers-deps += $(call sys-asm,$(sys-bits))
+std-headers-deps += $(sys-codes-generic)
+std-headers-deps += $(sys-proto-generic)
+
+$(addprefix $(obj)/,$(std-obj-y:%.o=%.d)): | $(std-headers-deps)
+$(addprefix $(obj)/,$(std-obj-y:%.o=%.i)): | $(std-headers-deps)
+$(addprefix $(obj)/,$(std-obj-y:%.o=%.s)): | $(std-headers-deps)
+$(addprefix $(obj)/,$(std-obj-y)): | $(std-headers-deps)
diff --git a/compel/plugins/include/uapi/plugin-std.h b/compel/plugins/include/uapi/plugin-std.h
new file mode 100644
index 000000000000..292db8839383
--- /dev/null
+++ b/compel/plugins/include/uapi/plugin-std.h
@@ -0,0 +1,6 @@
+#ifndef COMPEL_PLUGIN_STD_STD_H__
+#define COMPEL_PLUGIN_STD_STD_H__
+
+#include "uapi/std/syscall.h"
+
+#endif /* COMPEL_PLUGIN_STD_STD_H__ */
diff --git a/compel/plugins/include/uapi/std/string.h b/compel/plugins/include/uapi/std/string.h
new file mode 100644
index 000000000000..8aec886bd093
--- /dev/null
+++ b/compel/plugins/include/uapi/std/string.h
@@ -0,0 +1,28 @@
+#ifndef COMPEL_PLUGIN_STD_STRING_H__
+#define COMPEL_PLUGIN_STD_STRING_H__
+
+#include <sys/types.h>
+#include <stdbool.h>
+#include <stdarg.h>
+
+/* Standard file descriptors. */
+#define STDIN_FILENO 0 /* Standard input. */
+#define STDOUT_FILENO 1 /* Standard output. */
+#define STDERR_FILENO 2 /* Standard error output. */
+
+
+extern void __std_putc(int fd, char c);
+extern void __std_puts(int fd, const char *s);
+extern void __std_printk(int fd, const char *format, va_list args);
+extern void __std_printf(int fd, const char *format, ...);
+
+#define std_printf(fmt, ...) __std_printf(STDOUT_FILENO, fmt, ##__VA_ARGS__)
+#define std_puts(s) __std_puts(STDOUT_FILENO, s)
+#define std_putchar(c) __std_putc(STDOUT_FILENO, c)
+
+extern unsigned long std_strtoul(const char *nptr, char **endptr, int base);
+extern void *std_memcpy(void *to, const void *from, unsigned int n);
+extern int std_memcmp(const void *cs, const void *ct, size_t count);
+extern int std_strcmp(const char *cs, const char *ct);
+
+#endif /* COMPEL_PLUGIN_STD_STRING_H__ */
diff --git a/compel/plugins/include/uapi/std/syscall-types.h b/compel/plugins/include/uapi/std/syscall-types.h
new file mode 100644
index 000000000000..1b8188299103
--- /dev/null
+++ b/compel/plugins/include/uapi/std/syscall-types.h
@@ -0,0 +1,55 @@
+/*
+ * Please add here type definitions if
+ * syscall prototypes need them.
+ */
+
+#ifndef COMPEL_SYSCALL_TYPES_H__
+#define COMPEL_SYSCALL_TYPES_H__
+
+#include <arpa/inet.h>
+#include <sys/time.h>
+#include <stdbool.h>
+#include <signal.h>
+#include <sched.h>
+#include <fcntl.h>
+#include <time.h>
+
+struct cap_header {
+ u32 version;
+ int pid;
+};
+
+struct cap_data {
+ u32 eff;
+ u32 prm;
+ u32 inh;
+};
+
+struct robust_list_head;
+struct file_handle;
+struct itimerspec;
+struct io_event;
+struct sockaddr;
+struct timespec;
+struct siginfo;
+struct msghdr;
+struct rusage;
+struct iocb;
+
+typedef unsigned long aio_context_t;
+
+#ifndef F_GETFD
+# define F_GETFD 1
+#endif
+
+struct krlimit {
+ unsigned long rlim_cur;
+ unsigned long rlim_max;
+};
+
+/* Type of timers in the kernel. */
+typedef int kernel_timer_t;
+
+#include "asm/std/syscall-types.h"
+
+#endif /* COMPEL_SYSCALL_TYPES_H__ */
diff --git a/compel/plugins/std/std.c b/compel/plugins/std/std.c
new file mode 100644
index 000000000000..b3ea971f9079
--- /dev/null
+++ b/compel/plugins/std/std.c
@@ -0,0 +1,89 @@
+#include <sys/types.h>
+
+#include "uapi/int.h"
+#include "uapi/plugins.h"
+#include "uapi/plugin-std.h"
+
+extern int main(void *arg_p, unsigned int arg_s);
+
+static struct prologue_init_args *init_args;
+static int ctl_socket = -1;
+
+int std_ctl_sock(void)
+{
+ return ctl_socket;
+}
+
+static int init_socket(struct prologue_init_args *args)
+{
+ int ret;
+
+ ctl_socket = sys_socket(PF_UNIX, SOCK_SEQPACKET, 0);
+ if (ctl_socket < 0)
+ return ctl_socket;
+
+ ret = sys_connect(ctl_socket, (struct sockaddr *)&args->ctl_sock_addr, args->ctl_sock_addr_len);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
+static int fini_socket(void)
+{
+ char buf[32];
+ int ret = 0;
+
+ ret = sys_shutdown(ctl_socket, SHUT_WR);
+ if (ret)
+ goto err;
+
+ ret = sys_recvfrom(ctl_socket, buf, sizeof(buf), MSG_WAITALL, 0, 0);
+ if (ret)
+ goto err;
+err:
+ sys_close(ctl_socket);
+ ctl_socket = -1;
+ return ret;
+}
+
+#define plugin_init_count(size) ((size) / (sizeof(plugin_init_t *)))
+
+int __export_std_compel_start(struct prologue_init_args *args,
+ const plugin_init_t * const *init_array,
+ size_t init_size)
+{
+ unsigned int i;
+ int ret = 0;
+
+ init_args = args;
+
+ ret = init_socket(args);
+ if (ret)
+ return ret;
+
+ for (i = 0; i < plugin_init_count(init_size); i++) {
+ const plugin_init_t *d = init_array[i];
+
+ if (d && d->init) {
+ ret = d->init();
+ if (ret)
+ break;
+ }
+ }
+
+ if (!ret)
+ ret = main(args->arg_p, args->arg_s);
+
+ for (; i > 0; i--) {
+ const plugin_init_t *d = init_array[i - 1];
+
+ if (d && d->exit)
+ d->exit();
+ }
+
+ fini_socket();
+ return ret;
+}
+
+PLUGIN_REGISTER_DUMMY(std)
diff --git a/compel/plugins/std/string.c b/compel/plugins/std/string.c
new file mode 100644
index 000000000000..f4181f92a903
--- /dev/null
+++ b/compel/plugins/std/string.c
@@ -0,0 +1,262 @@
+#include <sys/types.h>
+#include <stdbool.h>
+#include <stdarg.h>
+
+#include "uapi/std/syscall.h"
+#include "uapi/std/string.h"
+
+static const char conv_tab[] = "0123456789abcdefghijklmnopqrstuvwxyz";
+
+void __std_putc(int fd, char c)
+{
+ sys_write(fd, &c, 1);
+}
+
+void __std_puts(int fd, const char *s)
+{
+ for (; *s; s++)
+ __std_putc(fd, *s);
+}
+
+static size_t __std_vprint_long_hex(char *buf, size_t blen, unsigned long num, char **ps)
+{
+ char *s = &buf[blen - 2];
+
+ buf[blen - 1] = '\0';
+
+ if (num == 0) {
+ *s = '0', s--;
+ goto done;
+ }
+
+ while (num > 0) {
+ *s = conv_tab[num % 16], s--;
+ num /= 16;
+ }
+
+done:
+ s++;
+ *ps = s;
+ return blen - (s - buf);
+}
+
+static size_t __std_vprint_long(char *buf, size_t blen, long num, char **ps)
+{
+ char *s = &buf[blen - 2];
+ int neg = 0;
+
+ buf[blen - 1] = '\0';
+
+ if (num < 0) {
+ neg = 1;
+ num = -num;
+ } else if (num == 0) {
+ *s = '0';
+ s--;
+ goto done;
+ }
+
+ while (num > 0) {
+ *s = (num % 10) + '0';
+ s--;
+ num /= 10;
+ }
+
+ if (neg) {
+ *s = '-';
+ s--;
+ }
+done:
+ s++;
+ *ps = s;
+ return blen - (s - buf);
+}
+
+void __std_printk(int fd, const char *format, va_list args)
+{
+ const char *s = format;
+
+ for (; *s != '\0'; s++) {
+ char buf[32], *t;
+ int along = 0;
+
+ if (*s != '%') {
+ __std_putc(fd, *s);
+ continue;
+ }
+
+ s++;
+ if (*s == 'l') {
+ along = 1;
+ s++;
+ if (*s == 'l')
+ s++;
+ }
+
+ switch (*s) {
+ case 's':
+ __std_puts(fd, va_arg(args, char *));
+ break;
+ case 'd':
+ __std_vprint_long(buf, sizeof(buf),
+ along ?
+ va_arg(args, long) :
+ (long)va_arg(args, int),
+ &t);
+ __std_puts(fd, t);
+ break;
+ case 'x':
+ __std_vprint_long_hex(buf, sizeof(buf),
+ along ?
+ va_arg(args, long) :
+ (long)va_arg(args, int),
+ &t);
+ __std_puts(fd, t);
+ break;
+ }
+ }
+}
+
+void __std_printf(int fd, const char *format, ...)
+{
+ va_list args;
+
+ va_start(args, format);
+ __std_printk(fd, format, args);
+ va_end(args);
+}
+
+static inline bool __isspace(unsigned char c)
+{
+ return c == ' ' || c == '\f' ||
+ c == '\n' || c == '\r' ||
+ c == '\t' || c == '\v';
+}
+
+static unsigned char __tolower(unsigned char c)
+{
+ return (c <= 'Z' && c >= 'A') ? c - 'A' + 'a' : c;
+}
+
+static inline bool __isalpha(unsigned char c)
+{
+ return ((c <= 'Z' && c >= 'A') ||
+ (c <= 'z' && c >= 'a'));
+}
+
+static inline bool __isdigit(unsigned char c)
+{
+ return (c <= '9' && c >= '0');
+}
+
+static inline bool __isalnum(unsigned char c)
+{
+ return (__isalpha(c) || __isdigit(c));
+}
+
+static unsigned int __conv_val(unsigned char c)
+{
+ if (__isdigit(c))
+ return c - '0';
+ else if (__isalpha(c))
+ return &conv_tab[__tolower(c)] - conv_tab;
+ return -1u;
+}
+
+unsigned long std_strtoul(const char *nptr, char **endptr, int base)
+{
+ const char *s = nptr;
+ bool neg = false;
+ unsigned int v;
+ long num = 0;
+
+ if (base < 0 || base == 1 || base > 36)
+ goto fin;
+
+ while (__isspace(*s))
+ s++;
+ if (!*s)
+ goto fin;
+
+ if (*s == '-')
+ neg = true, s++;
+
+ if (base == 0) {
+ if (s[0] == '0') {
+ unsigned char p = __tolower(s[1]);
+ switch (p) {
+ case 'b':
+ base = 2, s += 2;
+ break;
+ case 'x':
+ base = 16, s += 2;
+ break;
+ default:
+ base = 8, s += 1;
+ break;
+ }
+ } else
+ base = 10;
+ } else if (base == 16) {
+ if (s[0] == '0' && __tolower(s[1]) == 'x')
+ s += 2;
+ }
+
+ for (; *s; s++) {
+ if (__isspace(*s))
+ continue;
+ if (!__isalnum(*s))
+ goto fin;
+ v = __conv_val(*s);
+ if (v == -1u || v > base)
+ goto fin;
+ num *= base;
+ num += v;
+ }
+
+fin:
+ if (endptr)
+ *endptr = (char *)s;
+ return neg ? (unsigned long)-num : (unsigned long)num;
+}
+
+void *std_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;
+}
+
+int std_memcmp(const void *cs, const void *ct, size_t count)
+{
+ const unsigned char *su1, *su2;
+ int res = 0;
+
+ for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
+ if ((res = *su1 - *su2) != 0)
+ break;
+ return res;
+}
+
+int std_strcmp(const char *cs, const char *ct)
+{
+ unsigned char c1, c2;
+
+ while (1) {
+ c1 = *cs++;
+ c2 = *ct++;
+ if (c1 != c2)
+ return c1 < c2 ? -1 : 1;
+ if (!c1)
+ break;
+ }
+ return 0;
+}
diff --git a/compel/handle-elf-32.c b/compel/src/lib/handle-elf-32.c
similarity index 100%
rename from compel/handle-elf-32.c
rename to compel/src/lib/handle-elf-32.c
diff --git a/compel/handle-elf.c b/compel/src/lib/handle-elf.c
similarity index 88%
rename from compel/handle-elf.c
rename to compel/src/lib/handle-elf.c
index 64616f978d87..c9d9a4955e35 100644
--- a/compel/handle-elf.c
+++ b/compel/src/lib/handle-elf.c
@@ -11,16 +11,15 @@
#include <sys/stat.h>
#include <sys/mman.h>
+#include "uapi/compel.h"
+
#include "asm-generic/int.h"
-#include "uapi/piegen-err.h"
-#include "piegen.h"
#include "handle-elf.h"
+#include "piegen.h"
-/* TODO: merge with util-vdso.c part in criu header */
/* Check if pointer is out-of-bound */
-static bool
-__ptr_oob(const uintptr_t ptr, const uintptr_t start, const size_t size)
+static bool __ptr_oob(const uintptr_t ptr, const uintptr_t start, const size_t size)
{
uintptr_t end = start + size;
@@ -29,7 +28,7 @@ __ptr_oob(const uintptr_t ptr, const uintptr_t start, const size_t size)
/* Check if pointed structure's end is out-of-bound */
static bool __ptr_struct_end_oob(const uintptr_t ptr, const size_t struct_size,
- const uintptr_t start, const size_t size)
+ const uintptr_t start, const size_t size)
{
/* the last byte of the structure should be inside [begin, end) */
return __ptr_oob(ptr + struct_size - 1, start, size);
@@ -37,7 +36,7 @@ static bool __ptr_struct_end_oob(const uintptr_t ptr, const size_t struct_size,
/* Check if pointed structure is out-of-bound */
static bool __ptr_struct_oob(const uintptr_t ptr, const size_t struct_size,
- const uintptr_t start, const size_t size)
+ const uintptr_t start, const size_t size)
{
return __ptr_oob(ptr, start, size) ||
__ptr_struct_end_oob(ptr, struct_size, start, size);
@@ -73,7 +72,8 @@ static int do_relative_toc(long value, uint16_t *location,
}
if ((~mask & 0xffff) & value) {
- pr_err("bad TOC16 relocation (%ld) (0x%lx)\n", value, (~mask & 0xffff) & value);
+ pr_err("bad TOC16 relocation (%ld) (0x%lx)\n",
+ value, (~mask & 0xffff) & value);
return -1;
}
@@ -82,7 +82,7 @@ static int do_relative_toc(long value, uint16_t *location,
}
#endif
-static bool is_header_supported(Ehdr_t *hdr)
+static bool is_header_supported(Elf_Ehdr *hdr)
{
if (!arch_is_machine_supported(hdr->e_machine))
return false;
@@ -91,11 +91,11 @@ static bool is_header_supported(Ehdr_t *hdr)
return true;
}
-static const char *get_strings_section(Ehdr_t *hdr, uintptr_t mem, size_t size)
+static const char *get_strings_section(Elf_Ehdr *hdr, uintptr_t mem, size_t size)
{
size_t sec_table_size = ((size_t) hdr->e_shentsize) * hdr->e_shnum;
uintptr_t sec_table = mem + hdr->e_shoff;
- Shdr_t *secstrings_hdr;
+ Elf_Shdr *secstrings_hdr;
uintptr_t addr;
if (__ptr_struct_oob(sec_table, sec_table_size, mem, size)) {
@@ -109,7 +109,7 @@ static const char *get_strings_section(Ehdr_t *hdr, uintptr_t mem, size_t size)
* (size of section header * index of string section header)
*/
addr = sec_table + ((size_t) hdr->e_shentsize) * hdr->e_shstrndx;
- if (__ptr_struct_oob(addr, sizeof(Shdr_t),
+ if (__ptr_struct_oob(addr, sizeof(Elf_Shdr),
sec_table, sec_table + sec_table_size)) {
pr_err("String section header @%#zx is out of [%#zx, %#zx)\n",
addr, sec_table, sec_table + sec_table_size);
@@ -128,51 +128,55 @@ static const char *get_strings_section(Ehdr_t *hdr, uintptr_t mem, size_t size)
return (void*)addr;
}
+/*
+ * This name @__handle_elf get renamed into
+ * @handle_elf_ppc64 or say @handle_elf_x86_64
+ * depending on the architecture it's compiled
+ * under.
+ */
int __handle_elf(void *mem, size_t size)
{
const char *symstrings = NULL;
- Shdr_t *symtab_hdr = NULL;
- Sym_t *symbols = NULL;
- Ehdr_t *hdr = mem;
+ Elf_Shdr *symtab_hdr = NULL;
+ Elf_Sym *symbols = NULL;
+ Elf_Ehdr *hdr = mem;
- Shdr_t *strtab_hdr = NULL;
- Shdr_t **sec_hdrs = NULL;
+ Elf_Shdr *strtab_hdr = NULL;
+ Elf_Shdr **sec_hdrs = NULL;
const char *secstrings;
size_t i, k, nr_gotpcrel = 0;
#ifdef ELF_PPC64
s64 toc_offset = 0;
#endif
- int ret = -E_UNKNOWN;
+ int ret = -EINVAL;
pr_debug("Header\n");
pr_debug("------------\n");
pr_debug("\ttype 0x%x machine 0x%x version 0x%x\n",
- (unsigned)hdr->e_type, (unsigned)hdr->e_machine, (unsigned)hdr->e_version);
+ (unsigned)hdr->e_type, (unsigned)hdr->e_machine,
+ (unsigned)hdr->e_version);
if (!is_header_supported(hdr)) {
pr_err("Unsupported header detected\n");
- ret = -E_NOT_ELF;
goto err;
}
sec_hdrs = malloc(sizeof(*sec_hdrs) * hdr->e_shnum);
if (!sec_hdrs) {
pr_err("No memory for section headers\n");
- ret = -E_NOMEM;
+ ret = -ENOMEM;
goto err;
}
secstrings = get_strings_section(hdr, (uintptr_t)mem, size);
- if (!secstrings) {
- ret = -E_NO_STR_SEC;
+ if (!secstrings)
goto err;
- }
pr_debug("Sections\n");
pr_debug("------------\n");
for (i = 0; i < hdr->e_shnum; i++) {
- Shdr_t *sh = mem + hdr->e_shoff + hdr->e_shentsize * i;
+ Elf_Shdr *sh = mem + hdr->e_shoff + hdr->e_shentsize * i;
ptr_func_exit(sh);
if (sh->sh_type == SHT_SYMTAB)
@@ -221,9 +225,9 @@ int __handle_elf(void *mem, size_t size)
pr_out("#include \"%s/types.h\"\n", opts.uapi_dir);
for (i = 0; i < symtab_hdr->sh_size / symtab_hdr->sh_entsize; i++) {
- Sym_t *sym = &symbols[i];
+ Elf_Sym *sym = &symbols[i];
const char *name;
- Shdr_t *sh_src;
+ Elf_Shdr *sh_src;
ptr_func_exit(sym);
name = &symstrings[sym->st_name];
@@ -245,7 +249,8 @@ int __handle_elf(void *mem, size_t size)
#endif
if (strncmp(name, "__export", 8))
continue;
- if ((sym->st_shndx && sym->st_shndx < hdr->e_shnum) || sym->st_shndx == SHN_ABS) {
+ if ((sym->st_shndx && sym->st_shndx < hdr->e_shnum) ||
+ sym->st_shndx == SHN_ABS) {
if (sym->st_shndx == SHN_ABS) {
sh_src = NULL;
} else {
@@ -254,7 +259,8 @@ int __handle_elf(void *mem, size_t size)
}
pr_out("#define %s%s 0x%lx\n",
opts.prefix_name, name,
- (unsigned long)(sym->st_value + (sh_src ? sh_src->sh_addr : 0)));
+ (unsigned long)(sym->st_value +
+ (sh_src ? sh_src->sh_addr : 0)));
}
}
}
@@ -264,8 +270,8 @@ int __handle_elf(void *mem, size_t size)
pr_debug("Relocations\n");
pr_debug("------------\n");
for (i = 0; i < hdr->e_shnum; i++) {
- Shdr_t *sh = sec_hdrs[i];
- Shdr_t *sh_rel;
+ Elf_Shdr *sh = sec_hdrs[i];
+ Elf_Shdr *sh_rel;
if (sh->sh_type != SHT_REL && sh->sh_type != SHT_RELA)
continue;
@@ -283,11 +289,11 @@ int __handle_elf(void *mem, size_t size)
unsigned long place;
const char *name;
void *where;
- Sym_t *sym;
+ Elf_Sym *sym;
union {
- Rel_t rel;
- Rela_t rela;
+ Elf_Rel rel;
+ Elf_Rela rela;
} *r = mem + sh->sh_offset + sh->sh_entsize * k;
ptr_func_exit(r);
@@ -340,7 +346,7 @@ int __handle_elf(void *mem, size_t size)
value32 = (s32)sym->st_value;
value64 = (s64)sym->st_value;
} else {
- Shdr_t *sh_src;
+ Elf_Shdr *sh_src;
if ((unsigned)sym->st_shndx > (unsigned)hdr->e_shnum) {
pr_err("Unexpected symbol section index %u/%u\n",
@@ -355,7 +361,9 @@ int __handle_elf(void *mem, size_t size)
}
#ifdef ELF_PPC64
-/* Snippet from the OpenPOWER ABI for Linux Supplement:
+/*
+ * Snippet from the OpenPOWER ABI for Linux Supplement:
+ *
* The OpenPOWER ABI uses the three most-significant bits in the symbol
* st_other field specifies the number of instructions between a function's
* global entry point and local entry point. The global entry point is used
@@ -363,6 +371,7 @@ int __handle_elf(void *mem, size_t size)
* local entry point is used when r2 is known to already be valid for the
* function. A value of zero in these bits asserts that the function does
* not use r2.
+ *
* The st_other values have the following meanings:
* 0 and 1, the local and global entry points are the same.
* 2, the local entry point is at 1 instruction past the global entry point.
@@ -407,7 +416,7 @@ int __handle_elf(void *mem, size_t size)
case R_PPC64_ADDR32:
pr_debug("\t\t\tR_PPC64_ADDR32 at 0x%-4lx val 0x%x\n",
place, (unsigned int)(value32 + addend32));
- pr_out(" { .offset = 0x%-8x, .type = PIEGEN_TYPE_INT, "
+ pr_out(" { .offset = 0x%-8x, .type = COMPEL_TYPE_INT, "
" .addend = %-8d, .value = 0x%-16x, "
"}, /* R_PPC64_ADDR32 */\n",
(unsigned int) place, addend32, value32);
@@ -417,7 +426,7 @@ int __handle_elf(void *mem, size_t size)
case R_PPC64_REL64:
pr_debug("\t\t\tR_PPC64_ADDR64 at 0x%-4lx val 0x%lx\n",
place, value64 + addend64);
- pr_out("\t{ .offset = 0x%-8x, .type = PIEGEN_TYPE_LONG,"
+ pr_out("\t{ .offset = 0x%-8x, .type = COMPEL_TYPE_LONG,"
" .addend = %-8ld, .value = 0x%-16lx, "
"}, /* R_PPC64_ADDR64 */\n",
(unsigned int) place, (long)addend64, (long)value64);
@@ -477,13 +486,13 @@ int __handle_elf(void *mem, size_t size)
case R_X86_64_32: /* Symbol + Addend (4 bytes) */
case R_X86_64_32S: /* Symbol + Addend (4 bytes) */
pr_debug("\t\t\t\tR_X86_64_32 at 0x%-4lx val 0x%x\n", place, value32);
- pr_out(" { .offset = 0x%-8x, .type = PIEGEN_TYPE_INT, "
+ pr_out(" { .offset = 0x%-8x, .type = COMPEL_TYPE_INT, "
".addend = %-8d, .value = 0x%-16x, }, /* R_X86_64_32 */\n",
(unsigned int)place, addend32, value32);
break;
case R_X86_64_64: /* Symbol + Addend (8 bytes) */
pr_debug("\t\t\t\tR_X86_64_64 at 0x%-4lx val 0x%lx\n", place, (long)value64);
- pr_out(" { .offset = 0x%-8x, .type = PIEGEN_TYPE_LONG, "
+ pr_out(" { .offset = 0x%-8x, .type = COMPEL_TYPE_LONG, "
".addend = %-8ld, .value = 0x%-16lx, }, /* R_X86_64_64 */\n",
(unsigned int)place, (long)addend64, (long)value64);
break;
@@ -503,7 +512,7 @@ int __handle_elf(void *mem, size_t size)
break;
case R_X86_64_GOTPCREL: /* SymbolOffsetInGot + GOT + Addend - Place (4 bytes) */
pr_debug("\t\t\t\tR_X86_64_GOTPCREL at 0x%-4lx val 0x%x\n", place, value32);
- pr_out(" { .offset = 0x%-8x, .type = PIEGEN_TYPE_LONG | PIEGEN_TYPE_GOTPCREL, "
+ pr_out(" { .offset = 0x%-8x, .type = COMPEL_TYPE_LONG | COMPEL_TYPE_GOTPCREL, "
".addend = %-8d, .value = 0x%-16x, }, /* R_X86_64_GOTPCREL */\n",
(unsigned int)place, addend32, value32);
nr_gotpcrel++;
@@ -513,7 +522,7 @@ int __handle_elf(void *mem, size_t size)
#ifdef ELF_X86_32
case R_386_32: /* Symbol + Addend */
pr_debug("\t\t\t\tR_386_32 at 0x%-4lx val 0x%x\n", place, value32 + addend32);
- pr_out(" { .offset = 0x%-8x, .type = PIEGEN_TYPE_INT, "
+ pr_out(" { .offset = 0x%-8x, .type = COMPEL_TYPE_INT, "
".addend = %-4d, .value = 0x%x, },\n",
(unsigned int)place, addend32, value32);
break;
@@ -538,8 +547,8 @@ int __handle_elf(void *mem, size_t size)
pr_out("static __maybe_unused const char %s[] = {\n\t", opts.stream_name);
- for (i=0, k=0; i < hdr->e_shnum; i++) {
- Shdr_t *sh = sec_hdrs[i];
+ for (i = 0, k = 0; i < hdr->e_shnum; i++) {
+ Elf_Shdr *sh = sec_hdrs[i];
unsigned char *shdata;
size_t j;
@@ -547,19 +556,19 @@ int __handle_elf(void *mem, size_t size)
continue;
shdata = mem + sh->sh_offset;
- pr_debug("Copying section '%s'\n" \
+ pr_debug("Copying section '%s'\n"
"\tstart:0x%lx (gap:0x%lx) size:0x%lx\n",
&secstrings[sh->sh_name], (unsigned long) sh->sh_addr,
(unsigned long)(sh->sh_addr - k), (unsigned long) sh->sh_size);
/* write 0 in the gap between the 2 sections */
- for (;k < sh->sh_addr; k++) {
+ for (; k < sh->sh_addr; k++) {
if (k && (k % 8) == 0)
pr_out("\n\t");
pr_out("0x00,");
}
- for (j=0; j < sh->sh_size; j++, k++) {
+ for (j = 0; j < sh->sh_size; j++, k++) {
if (k && (k % 8) == 0)
pr_out("\n\t");
pr_out("%#02x,", shdata[j]);
diff --git a/compel/main.c b/compel/src/main.c
similarity index 99%
rename from compel/main.c
rename to compel/src/main.c
index 6f117cded569..ee6ccd53acdd 100644
--- a/compel/main.c
+++ b/compel/src/main.c
@@ -12,6 +12,7 @@
#include <sys/stat.h>
#include <sys/mman.h>
+#include "version.h"
#include "piegen.h"
static const char compel_cflags_pie[] = "-fpie -Wa,--noexecstack -fno-stack-protector";
--
2.7.4
More information about the CRIU
mailing list