Skip to content

Commit

Permalink
Bypass weird C compiler error in ffi-types
Browse files Browse the repository at this point in the history
  • Loading branch information
assafmo committed Jun 27, 2023
1 parent f0b92f4 commit 3d79d50
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions cosmwasm/enclaves/ffi-types/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,10 @@ pub enum MigrateResult {

#[repr(C)]
pub enum UpdateAdminResult {
Success {
UpdateAdminSuccess {
admin_proof: [u8; 32],
},
Failure {
UpdateAdminFailure {
/// The error that happened in the enclave
err: EnclaveError,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ pub unsafe extern "C" fn ecall_update_admin(
) -> UpdateAdminResult {
if let Err(err) = oom_handler::register_oom_handler() {
error!("Could not register OOM handler!");
return UpdateAdminResult::Failure { err };
return UpdateAdminResult::UpdateAdminFailure { err };
}

let failed_call =
Expand All @@ -528,19 +528,19 @@ pub unsafe extern "C" fn ecall_update_admin(

if let Err(err) = oom_handler::restore_safety_buffer() {
error!("Could not restore OOM safety buffer!");
return UpdateAdminResult::Failure { err };
return UpdateAdminResult::UpdateAdminFailure { err };
}

if let Ok(res) = result {
res
} else if oom_handler::get_then_clear_oom_happened() {
error!("Call ecall_update_admin failed because the enclave ran out of memory!");
UpdateAdminResult::Failure {
UpdateAdminResult::UpdateAdminFailure {
err: EnclaveError::OutOfMemory,
}
} else {
error!("Call ecall_update_admin panicked unexpectedly!");
UpdateAdminResult::Failure {
UpdateAdminResult::UpdateAdminFailure {
err: EnclaveError::Panic,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,10 @@ pub fn result_update_admin_success_to_result(
result: Result<UpdateAdminSuccess, EnclaveError>,
) -> UpdateAdminResult {
match result {
Ok(UpdateAdminSuccess { admin_proof }) => UpdateAdminResult::Success { admin_proof },
Err(err) => UpdateAdminResult::Failure { err },
Ok(UpdateAdminSuccess { admin_proof }) => {
UpdateAdminResult::UpdateAdminSuccess { admin_proof }
}
Err(err) => UpdateAdminResult::UpdateAdminFailure { err },
}
}

Expand Down
6 changes: 4 additions & 2 deletions cosmwasm/packages/sgx-vm/src/wasmi/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ pub fn migrate_result_to_vm_result(other: MigrateResult) -> VmResult<MigrateSucc

pub fn update_admin_result_to_vm_result(other: UpdateAdminResult) -> VmResult<UpdateAdminSuccess> {
match other {
UpdateAdminResult::Success { admin_proof } => Ok(UpdateAdminSuccess { admin_proof }),
UpdateAdminResult::Failure { err } => Err(err.into()),
UpdateAdminResult::UpdateAdminSuccess { admin_proof } => {
Ok(UpdateAdminSuccess { admin_proof })
}
UpdateAdminResult::UpdateAdminFailure { err } => Err(err.into()),
}
}

Expand Down

0 comments on commit 3d79d50

Please sign in to comment.