Skip to content

Commit 55a3667

Browse files
sangho2Sangho Lee
andauthored
Fix error code return for OP-TEE syscall dispatch (#999)
This PR fixes the error code return of OP-TEE syscall dispatching. Instead of returning `Errno` (Linux), it now returns `TeeResult` (OP-TEE) to the TA/ldelf if its syscall request is invalid (e.g., nonexistent/unsupported syscall, invalid arguments, ...). Co-authored-by: Sangho Lee <[email protected]>
1 parent faba6c9 commit 55a3667

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

litebox_common_optee/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,20 @@ impl From<TeeResult> for u32 {
11461146
}
11471147
}
11481148

1149+
impl From<Errno> for TeeResult {
1150+
fn from(err: Errno) -> Self {
1151+
match err {
1152+
Errno::ENOSYS => Self::NotSupported,
1153+
Errno::EINVAL | Errno::EFAULT => Self::BadParameters,
1154+
Errno::EPERM | Errno::EACCES => Self::AccessDenied,
1155+
Errno::ENOMEM => Self::OutOfMemory,
1156+
Errno::EOVERFLOW => Self::Overflow,
1157+
Errno::EBUSY => Self::Busy,
1158+
_ => Self::GenericError,
1159+
}
1160+
}
1161+
}
1162+
11491163
const UTEE_ENTRY_FUNC_OPEN_SESSION: u32 = 0;
11501164
const UTEE_ENTRY_FUNC_CLOSE_SESSION: u32 = 1;
11511165
const UTEE_ENTRY_FUNC_INVOKE_COMMAND: u32 = 2;

litebox_shim_optee/src/lib.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use litebox::{
2020
mm::{PageManager, linux::PAGE_SIZE},
2121
platform::{Instant as _, RawConstPointer as _, RawMutPointer as _, TimeProvider},
2222
shim::ContinueOperation,
23-
utils::{ReinterpretUnsignedExt, TruncateExt},
23+
utils::TruncateExt,
2424
};
2525
use litebox_common_linux::{MapFlags, ProtFlags, errno::Errno};
2626
use litebox_common_optee::{
@@ -383,8 +383,7 @@ impl Task {
383383
let request = match SyscallRequest::<Platform>::try_from_raw(ctx.orig_rax, ctx) {
384384
Ok(request) => request,
385385
Err(err) => {
386-
// TODO: this seems like the wrong kind of error for OPTEE.
387-
ctx.rax = (err.as_neg() as isize).reinterpret_as_unsigned();
386+
ctx.rax = TeeResult::from(err) as usize;
388387
return ContinueOperation::Resume;
389388
}
390389
};
@@ -664,8 +663,7 @@ impl Task {
664663
let request = match LdelfSyscallRequest::<Platform>::try_from_raw(ctx.orig_rax, ctx) {
665664
Ok(request) => request,
666665
Err(err) => {
667-
// TODO: this seems like the wrong kind of error for OPTEE.
668-
ctx.rax = (err.as_neg() as isize).reinterpret_as_unsigned();
666+
ctx.rax = TeeResult::from(err) as usize;
669667
return ContinueOperation::Resume;
670668
}
671669
};

0 commit comments

Comments
 (0)