selftests/sgx: Provide per-op parameter structs for the test enclave
Jarkko Sakkinen
maintainerPATCH v2 1/1 selftests/sgx: Provide per-op parameter structs for the test enclave
To add more operations to the test enclave, the protocol needs to allow to have operations with varying parameters. Create a separate parameter struct for each existing operation, with the shared parameters in struct encl_op_header.
Signed-off-by Jarkko Sakkinen <[email protected]>
---
v2:
* Declare do_encl_op_put() and do_encl_op_get() as static symbols.
* Use a jump table for ops.
--- tools/testing/selftests/sgx/defines.h | 14 ++++++- tools/testing/selftests/sgx/main.c | 52 +++++++++++++------------ tools/testing/selftests/sgx/test_encl.c | 33 ++++++++++------ 3 files changed, 61 insertions(+), 38 deletions(-)
tools/testing/selftests/sgx/defines.h +12 -2
@@ -21,11 +21,21 @@enum encl_op_type {ENCL_OP_PUT ,ENCL_OP_GET , +ENCL_OP_MAX , }; -struct encl_op { +struct encl_op_header {uint64_t type; -uint64_t buffer; +}; + +struct encl_op_put { +struct encl_op_header header; +uint64_t value; +}; + +struct encl_op_get { +struct encl_op_header header; +uint64_t value; };#endif /* DEFINES_H */
tools/testing/selftests/sgx/main.c +28 -24
99 lines not on this page · raw message
tools/testing/selftests/sgx/test_encl.c +21 -12
@@ -16,20 +16,29 @@ static void *memcpy(void *dest, const void *src, size_t n)return dest; } -void encl_body (void *rdi,void *rsi) +static void do_encl_op_put (void *op) +{ +struct encl_op_put *op2 = op; + +memcpy (&encl_buffer[0 ], &op2->value,8 ); +} + +static void do_encl_op_get (void *op) { -struct encl_op *op = (struct encl_op *)rdi; +struct encl_op_get *op2 = op; -switch (op->type) { -case ENCL_OP_PUT : -memcpy (&encl_buffer[0 ], &op->buffer,8 ); -break ; +memcpy (&op2->value, &encl_buffer[0 ],8 ); +} + +void encl_body (void *rdi,void *rsi) +{ +const void (*encl_op_array[ENCL_OP_MAX ])(void *) = { + do_encl_op_put, + do_encl_op_get, + }; -case ENCL_OP_GET : -memcpy (&op->buffer, &encl_buffer[0 ],8 ); -break ; +struct encl_op_header *op = (struct encl_op_header *)rdi; -default : -break ; - } +if (op->type <ENCL_OP_MAX ) + (*encl_op_array[op->type])(op); }
Signature · 1 line
2.32.0