diff --git a/include/amduat/pel/opreg_kernel.h b/include/amduat/pel/opreg_kernel.h index 455718d..49fbb4b 100644 --- a/include/amduat/pel/opreg_kernel.h +++ b/include/amduat/pel/opreg_kernel.h @@ -24,6 +24,8 @@ enum { }; enum { + AMDUAT_PEL_KERNEL_STATUS_OOM = 0x00000001u, + AMDUAT_PEL_KERNEL_STATUS_INTERNAL = 0x00000002u, AMDUAT_PEL_KERNEL_STATUS_CONCAT_TYPE_TAG_MISMATCH = 0x00010001u, AMDUAT_PEL_KERNEL_STATUS_SLICE_RANGE_OUT_OF_BOUNDS = 0x00020001u }; diff --git a/src/pel_stack/opreg/kernel.c b/src/pel_stack/opreg/kernel.c index dc85acc..fcc5e88 100644 --- a/src/pel_stack/opreg/kernel.c +++ b/src/pel_stack/opreg/kernel.c @@ -8,8 +8,6 @@ #include #include -enum { AMDUAT_PEL_KERNEL_STATUS_INTERNAL = 1 }; - static bool amduat_name_eq(amduat_octets_t name, const char *literal) { size_t len = strlen(literal); if (name.len != len) { @@ -175,7 +173,7 @@ static bool amduat_kernel_concat(const amduat_artifact_t *inputs, buffer = (uint8_t *)malloc(total_len); if (buffer == NULL) { if (out_status_code) { - *out_status_code = AMDUAT_PEL_KERNEL_STATUS_INTERNAL; + *out_status_code = AMDUAT_PEL_KERNEL_STATUS_OOM; } return false; } @@ -194,7 +192,7 @@ static bool amduat_kernel_concat(const amduat_artifact_t *inputs, if (!amduat_alloc_outputs(1, out_outputs)) { free(buffer); if (out_status_code) { - *out_status_code = AMDUAT_PEL_KERNEL_STATUS_INTERNAL; + *out_status_code = AMDUAT_PEL_KERNEL_STATUS_OOM; } return false; } @@ -254,7 +252,7 @@ static bool amduat_kernel_slice(const amduat_artifact_t *inputs, buffer = (uint8_t *)malloc((size_t)length); if (buffer == NULL) { if (out_status_code) { - *out_status_code = AMDUAT_PEL_KERNEL_STATUS_INTERNAL; + *out_status_code = AMDUAT_PEL_KERNEL_STATUS_OOM; } return false; } @@ -271,7 +269,7 @@ static bool amduat_kernel_slice(const amduat_artifact_t *inputs, if (!amduat_alloc_outputs(1, out_outputs)) { free(buffer); if (out_status_code) { - *out_status_code = AMDUAT_PEL_KERNEL_STATUS_INTERNAL; + *out_status_code = AMDUAT_PEL_KERNEL_STATUS_OOM; } return false; } @@ -314,7 +312,7 @@ static bool amduat_kernel_const(const amduat_pel_kernel_const_params_t *params, buffer = (uint8_t *)malloc(params->bytes.len); if (buffer == NULL) { if (out_status_code) { - *out_status_code = AMDUAT_PEL_KERNEL_STATUS_INTERNAL; + *out_status_code = AMDUAT_PEL_KERNEL_STATUS_OOM; } return false; } @@ -326,7 +324,7 @@ static bool amduat_kernel_const(const amduat_pel_kernel_const_params_t *params, if (!amduat_alloc_outputs(1, out_outputs)) { free(buffer); if (out_status_code) { - *out_status_code = AMDUAT_PEL_KERNEL_STATUS_INTERNAL; + *out_status_code = AMDUAT_PEL_KERNEL_STATUS_OOM; } return false; } @@ -384,7 +382,7 @@ static bool amduat_kernel_hash(const amduat_artifact_t *inputs, buffer = (uint8_t *)malloc(desc->digest_len); if (buffer == NULL) { if (out_status_code) { - *out_status_code = AMDUAT_PEL_KERNEL_STATUS_INTERNAL; + *out_status_code = AMDUAT_PEL_KERNEL_STATUS_OOM; } return false; } @@ -401,7 +399,7 @@ static bool amduat_kernel_hash(const amduat_artifact_t *inputs, if (!amduat_alloc_outputs(1, out_outputs)) { free(buffer); if (out_status_code) { - *out_status_code = AMDUAT_PEL_KERNEL_STATUS_INTERNAL; + *out_status_code = AMDUAT_PEL_KERNEL_STATUS_OOM; } return false; } diff --git a/src/pel_stack/program_dag/program_dag.c b/src/pel_stack/program_dag/program_dag.c index ef929de..493af28 100644 --- a/src/pel_stack/program_dag/program_dag.c +++ b/src/pel_stack/program_dag/program_dag.c @@ -596,6 +596,10 @@ static bool amduat_pel_program_dag_exec_internal( prepared.ops[node_index], resolved_inputs, node->inputs_len, &prepared.params[node_index], &node_results[node_index].outputs, &node_results[node_index].outputs_len, &status_code)) { + if (status_code == AMDUAT_PEL_KERNEL_STATUS_OOM) { + free(resolved_inputs); + goto oom_finish; + } if (status_code == 2 || status_code == 3 || status_code == 0) { status_code = 1; }