Skip to content

Conversation

@ivila
Copy link
Contributor

@ivila ivila commented Mar 25, 2025

  1. Fix usage of Rust types as return values in FFI functions.
    https://github.com/apache/incubator-teaclave-trustzone-sdk/blob/cf0f662eec9213be32bf972888f422575b03bc7a/optee-teec/src/extension.rs#L23-L33
    Currently, the plugin's methods use Rust's optee_teec::Result as the return value for FFI, which is incorrect since Rust does not guarantee a stable ABI. We need to change them to optee_teec_sys::TEEC_Result(alias of u32) instead.

  2. Standardize the function signature to require returning a Result.
    Similar to the original signatures of TEEC functions, we currently require the plugin's methods to return an error.

    • For init: from fn() to fn() -> optee_teec::Result<()>
    • For invoke_command: from fn(&mut optee_teec::PluginParameters) to fn(&mut optee_teec::PluginParameters) -> optee_teec::Result<()>

    And in fact, the current examples of supp_plugin-rs already return a Result, even though this contradicts their function signatures.
    image

  3. Use inner functions in generated code to prevent unexpected early returns.
    Previous macros simply duplicated the code into the new function.
    https://github.com/apache/incubator-teaclave-trustzone-sdk/blob/cf0f662eec9213be32bf972888f422575b03bc7a/optee-teec/macros/src/lib.rs#L60-L67
    Which is buggy if developers have some return statements inside.
    For example, if developer define a function:

    fn init() {
        if method() {
            return;
        }
        // some other codes
    }

    It will be rewrite to:

    #[no_mangle]
    pub fn _plugin_init() -> optee_teec::Result<()> {
        if method() {
            return;  // this line is a syntax error
        }
        // some other codes
        Ok(())
    }
  • Fix example: supp_plugin-rs.

@ivila
Copy link
Contributor Author

ivila commented Mar 26, 2025

image

Network Error, the pipeline pass on my fork: https://github.com/ivila/incubator-teaclave-trustzone-sdk/actions/runs/14073623792

@ivila
Copy link
Contributor Author

ivila commented Mar 27, 2025

Update: remove the unnessesary #[no_mangle] tag and re-trigger the pipeline.

@ivila ivila force-pushed the fix_Plugin_zc branch 2 times, most recently from 7fa7393 to 34d31ee Compare March 27, 2025 06:30
@DemesneGH
Copy link
Contributor

Reviewed-by: Yuan Zhuang <yuanz@apache.org>
Thanks!

* Fix usage of Rust types as return values in FFI functions.
* Standardize the function signature to require returning a Result.
* Use inner functions in generated code to prevent unexpected early returns.
* Fix example: supp_plugin-rs.

Signed-off-by: Zehui Chen <ivila@apache.org>
Reviewed-by: Yuan Zhuang <yuanz@apache.org>
@DemesneGH
Copy link
Contributor

Please feel free to rebase and merge once CI passed 😄

@ivila ivila merged commit 7dac025 into apache:main Mar 28, 2025
7 checks passed
@ivila ivila deleted the fix_Plugin_zc branch April 11, 2025 03:31
@DemesneGH DemesneGH added bug Something isn't working refactor labels Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants