[CRIU] [PATCH 09/10] compel: Initial commit
Pavel Emelyanov
xemul at virtuozzo.com
Thu Mar 24 07:53:35 PDT 2016
On 03/22/2016 10:15 PM, Cyrill Gorcunov wrote:
> The compel component is a replacement for several aspects of CRIU
> functionality: binary blobs generation for PIE parasite/restore code,
> and a library for parasite code injection and execution (to be implemented).
OK, so at this stage compel tool starts with
1) cflags
2) ldflags
3) piegen
right?
> --- a/criu/pie/piegen/main.c
> +++ b/compel/src/main.c
> @@ -14,19 +15,23 @@
> #include <sys/mman.h>
>
> #include "compiler.h"
> -#include "config.h"
> #include "piegen.h"
>
> +FILE *fout;
> +
> +static const char compel_cflags_pie[] = "-fpie -Wa,--noexecstack -fno-stack-protector";
> +static const char compel_cflags_nopic[] = "-fno-pic -Wa,--noexecstack -fno-stack-protector";
> +static const char compel_ldflags[] = "-r";
> +
> piegen_opt_t opts = {
> .input_filename = NULL,
> .stream_name = "stream",
> .prefix_name = "__",
> .var_name = "elf_relocs",
> .nrgotpcrel_name = "nr_gotpcrel",
> + .uapi_dir = "compel/uapi",
> };
>
> -FILE *fout;
> -
> static int handle_elf(void *mem, size_t size)
> {
> #if defined(CONFIG_X86_32) || defined(CONFIG_X86_64)
> @@ -65,43 +70,120 @@ static int handle_elf(void *mem, size_t size)
> return -1;
> }
>
> -/*
> - * That;s the tool to generate patches object files.
> - */
> -int main(int argc, char *argv[])
> +static int piegen(void)
> {
> struct stat st;
> - int opt, idx;
> void *mem;
> int fd;
>
> - static const char short_opts[] = "f:o:s:p:v:r:h";
> + fd = open(opts.input_filename, O_RDONLY);
> + if (fd < 0) {
> + pr_perror("Can't open file %s", opts.input_filename);
> + goto err;
> + }
> +
> + if (fstat(fd, &st)) {
> + pr_perror("Can't stat file %s", opts.input_filename);
> + goto err;
> + }
> +
> + fout = fopen(opts.output_filename, "w");
> + if (fout == NULL) {
> + pr_perror("Can't open %s", opts.output_filename);
> + goto err;
> + }
> +
> + mem = mmap(NULL, st.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FILE, fd, 0);
> + if (mem == MAP_FAILED) {
> + pr_perror("Can't mmap file %s", opts.input_filename);
> + goto err;
> + }
> +
> + if (handle_elf(mem, st.st_size)) {
> + fclose(fout);
> + unlink(opts.output_filename);
> + goto err;
> + }
> +
> +err:
> + fclose(fout);
> + printf("%s generated successfully.\n", opts.output_filename);
> + return 0;
> +}
> +
> +int main(int argc, char *argv[])
> +{
> + const char *current_cflags = NULL;
> + int opt, idx, i;
> + char *action;
> +
> + typedef struct {
> + const char *arch;
> + const char *cflags;
> + } compel_cflags_t;
> +
> + static const compel_cflags_t compel_cflags[] = {
> + {
> + .arch = "x86",
> + .cflags = compel_cflags_pie,
> + }, {
> + .arch = "ia32",
> + .cflags = compel_cflags_nopic,
> + }, {
> + .arch = "aarch64",
> + .cflags = compel_cflags_pie,
> + }, {
> + .arch = "arm",
> + .cflags = compel_cflags_pie,
> + }, {
> + .arch = "ppc64",
> + .cflags = compel_cflags_pie,
> + },
> + };
> +
> + const char short_opts[] = "f:o:s:p:v:r:a:u:Vh";
> static struct option long_opts[] = {
> - { "file", required_argument, 0, 'f' },
> - { "output", required_argument, 0, 'o' },
> - { "stream", required_argument, 0, 's' },
> - { "sym-prefix", required_argument, 0, 'p' },
> - { "variable", required_argument, 0, 'v' },
> - { "pcrelocs", required_argument, 0, 'r' },
> - { "help", required_argument, 0, 'h' },
> + { "arch", required_argument, 0, 'a' },
> + { "file", required_argument, 0, 'f' },
> + { "output", required_argument, 0, 'o' },
> + { "stream", required_argument, 0, 's' },
> + { "uapi-dir", required_argument, 0, 'u' },
> + { "sym-prefix", required_argument, 0, 'p' },
> + { "variable", required_argument, 0, 'v' },
> + { "pcrelocs", required_argument, 0, 'r' },
> + { "version", no_argument, 0, 'V' },
> + { "help", no_argument, 0, 'h' },
This seem to add much more than just moving the piegen code. What?
More information about the CRIU
mailing list