diff options
author | Alice Frosi <afrosi@redhat.com> | 2023-05-02 17:21:57 +0200 |
---|---|---|
committer | Alice Frosi <afrosi@redhat.com> | 2023-05-08 14:36:43 +0200 |
commit | c29157e78df7fa335c56d0d7f2cca7dc50bfffd6 (patch) | |
tree | 6c7ce428c01a602f89c8897015e7428b84038871 /common | |
parent | 82b77505f9420f11d614c2ae0f74153ca4ee3cb5 (diff) | |
download | seitan-c29157e78df7fa335c56d0d7f2cca7dc50bfffd6.tar seitan-c29157e78df7fa335c56d0d7f2cca7dc50bfffd6.tar.gz seitan-c29157e78df7fa335c56d0d7f2cca7dc50bfffd6.tar.bz2 seitan-c29157e78df7fa335c56d0d7f2cca7dc50bfffd6.tar.lz seitan-c29157e78df7fa335c56d0d7f2cca7dc50bfffd6.tar.xz seitan-c29157e78df7fa335c56d0d7f2cca7dc50bfffd6.tar.zst seitan-c29157e78df7fa335c56d0d7f2cca7dc50bfffd6.zip |
seitan: refactor operations
Refactoring:
- rename do_operations to eval and reduce the number of arguments
- create macro HANDLE_OP
- rename all functions with op_*(operation name)
- exposed the op_* functions in the operations.h
Fixes:
- use pread for op_load
Diffstat (limited to 'common')
-rw-r--r-- | common/gluten.h | 46 |
1 files changed, 21 insertions, 25 deletions
diff --git a/common/gluten.h b/common/gluten.h index 61270d8..b1723ca 100644 --- a/common/gluten.h +++ b/common/gluten.h @@ -1,8 +1,8 @@ /* SPDX-License-Identifier: GPL-3.0-or-later - * Copyright 2023 Red Hat GmbH - * Authors: Alice Frosi <afrosi@redhat.com> - * Stefano Brivio <sbrivio@redhat.com> - */ +* Copyright 2023 Red Hat GmbH +* Authors: Alice Frosi <afrosi@redhat.com> +* Stefano Brivio <sbrivio@redhat.com> +*/ #ifndef COMMON_GLUTEN_H #define COMMON_GLUTEN_H @@ -22,25 +22,27 @@ extern struct seccomp_data anonymous_seccomp_data; #define DATA_SIZE 4096 #define INST_MAX 16 -#define OFFSET_MAX MAX(MAX(MAX(DATA_SIZE, RO_DATA_SIZE), \ - INST_MAX), \ - ARRAY_SIZE(anonymous_seccomp_data.args)) +#define OFFSET_MAX \ + MAX(MAX(MAX(DATA_SIZE, RO_DATA_SIZE), INST_MAX), \ + ARRAY_SIZE(anonymous_seccomp_data.args)) + +#define seccomp_offset_args(x) (sizeof(uint64_t) / sizeof(uint16_t)) * (x) enum gluten_offset_type { - OFFSET_RO_DATA = 0, - OFFSET_DATA = 1, - OFFSET_SECCOMP_DATA = 2, - OFFSET_INSTRUCTION = 3, - OFFSET_TYPE_MAX = OFFSET_INSTRUCTION, + OFFSET_RO_DATA = 0, + OFFSET_DATA = 1, + OFFSET_SECCOMP_DATA = 2, + OFFSET_INSTRUCTION = 3, + OFFSET_TYPE_MAX = OFFSET_INSTRUCTION, }; struct gluten_offset { #ifdef __GNUC__ - enum gluten_offset_type type:BITS_PER_NUM(OFFSET_TYPE_MAX); + enum gluten_offset_type type : BITS_PER_NUM(OFFSET_TYPE_MAX); #else - uint16_t type:BITS_PER_NUM(OFFSET_TYPE_MAX); + uint16_t type : BITS_PER_NUM(OFFSET_TYPE_MAX); #endif - uint16_t offset:BITS_PER_NUM(OFFSET_MAX); + uint16_t offset : BITS_PER_NUM(OFFSET_MAX); }; BUILD_BUG_ON(BITS_PER_NUM(OFFSET_TYPE_MAX) + BITS_PER_NUM(OFFSET_MAX) > 16) @@ -90,9 +92,9 @@ enum op_type { OP_INJECT_A, OP_RETURN, OP_LOAD, - OP_END, OP_CMP, OP_RESOLVEDFD, + OP_END, }; enum value_type { @@ -130,12 +132,6 @@ struct op_inject { struct gluten_offset old_fd; }; -struct copy_arg { - uint16_t args_off; - enum value_type type; - size_t size; -}; - struct op_load { struct gluten_offset src; struct gluten_offset dst; @@ -160,8 +156,8 @@ struct op_cmp { }; struct op_resolvedfd { - uint16_t fd_off; - uint16_t path_off; + struct gluten_offset fd; + struct gluten_offset path; size_t path_size; unsigned int jmp; }; @@ -171,8 +167,8 @@ struct op { union { struct op_nr nr; struct op_call call; - struct op_block block; struct op_continue cont; + struct op_block block; struct op_return ret; struct op_inject inject; struct op_load load; |