You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@teaclave.apache.org by "asir66 (via GitHub)" <gi...@apache.org> on 2025/11/08 05:57:25 UTC

[PR] examples: enable serde example for no-std and promote it to a common example [teaclave-trustzone-sdk]

asir66 opened a new pull request, #253:
URL: https://github.com/apache/teaclave-trustzone-sdk/pull/253

   # Summary
   
   This PR enables the Serde example to work in `no_std` environments and promotes it to a common example shared across different targets.
   
   ## changes
   
   - Modified the Serde example to be compatible with `no_std`.
   - Moved the example into the common examples directory for better reusability.
   - Adjusted build configuration and dependencies accordingly.
   
   ## References
   - https://serde.rs/no-std.html


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org


Re: [PR] examples: enable serde example for no-std and promote it to a common example [teaclave-trustzone-sdk]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #253:
URL: https://github.com/apache/teaclave-trustzone-sdk/pull/253#discussion_r2508607265


##########
examples/serde-rs/ta/src/main.rs:
##########
@@ -52,18 +55,26 @@ fn invoke_command(cmd_id: u32, params: &mut Parameters) -> Result<()> {
     match Command::from(cmd_id) {
         Command::DefaultOp => {
             let mut p = unsafe { params.0.as_memref()? };
-            let mut buffer = p.buffer();
+            let buffer = p.buffer();
             let point = Point { x: 1, y: 2 };
 
             // Convert the Point to a JSON string.
-            let serialized = serde_json::to_string(&point).map_err(|e| {
+            let serialized: String = serde_json::to_string(&point).map_err(|e| {
                 trace_println!("Failed to serialize point: {}", e);
                 ErrorKind::BadParameters
             })?;
-            let len = buffer.write(serialized.as_bytes()).map_err(|e| {
-                trace_println!("Failed to write to buffer: {}", e);
-                ErrorKind::BadParameters
-            })?;
+
+            let bytes = serialized.as_bytes();
+
+            // Ensure the buffer is large enough to hold the serialized data.
+            if bytes.len() > buffer.len() {
+                trace_println!("Buffer too small, Cannot copy all bytes");
+                return Err(ErrorKind::BadParameters.into());
+            }
+
+            // Copy the serialized JSON string into the buffer.
+            let len = bytes.len();
+            buffer[..len].copy_from_slice(&bytes[..len]);

Review Comment:
   The slice operation `&bytes[..len]` is redundant since `bytes` already has exactly length `len` (from line 76: `let len = bytes.len()`). You can simplify this to `buffer[..len].copy_from_slice(bytes)` to improve code clarity.
   ```suggestion
               buffer[..len].copy_from_slice(bytes);
   ```



##########
examples/serde-rs/ta/src/main.rs:
##########
@@ -52,18 +55,26 @@ fn invoke_command(cmd_id: u32, params: &mut Parameters) -> Result<()> {
     match Command::from(cmd_id) {
         Command::DefaultOp => {
             let mut p = unsafe { params.0.as_memref()? };
-            let mut buffer = p.buffer();
+            let buffer = p.buffer();
             let point = Point { x: 1, y: 2 };
 
             // Convert the Point to a JSON string.
-            let serialized = serde_json::to_string(&point).map_err(|e| {
+            let serialized: String = serde_json::to_string(&point).map_err(|e| {
                 trace_println!("Failed to serialize point: {}", e);
                 ErrorKind::BadParameters
             })?;
-            let len = buffer.write(serialized.as_bytes()).map_err(|e| {
-                trace_println!("Failed to write to buffer: {}", e);
-                ErrorKind::BadParameters
-            })?;
+
+            let bytes = serialized.as_bytes();
+
+            // Ensure the buffer is large enough to hold the serialized data.
+            if bytes.len() > buffer.len() {
+                trace_println!("Buffer too small, Cannot copy all bytes");

Review Comment:
   Corrected capitalization of 'Cannot' to 'cannot' in the error message for consistency with standard error message conventions.
   ```suggestion
                   trace_println!("Buffer too small, cannot copy all bytes");
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org


Re: [PR] examples: enable serde example for no-std and promote it to a common example [teaclave-trustzone-sdk]

Posted by "DemesneGH (via GitHub)" <gi...@apache.org>.
DemesneGH commented on PR #253:
URL: https://github.com/apache/teaclave-trustzone-sdk/pull/253#issuecomment-3514884102

   BTW could you also help to revise the similar `message_passing_interface-rs` example to enable the `no-std`? thanks!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org


Re: [PR] examples: enable serde example for no-std and promote it to a common example [teaclave-trustzone-sdk]

Posted by "DemesneGH (via GitHub)" <gi...@apache.org>.
DemesneGH commented on code in PR #253:
URL: https://github.com/apache/teaclave-trustzone-sdk/pull/253#discussion_r2509321635


##########
examples/serde-rs/ta/src/main.rs:
##########
@@ -52,18 +55,26 @@ fn invoke_command(cmd_id: u32, params: &mut Parameters) -> Result<()> {
     match Command::from(cmd_id) {
         Command::DefaultOp => {
             let mut p = unsafe { params.0.as_memref()? };
-            let mut buffer = p.buffer();
+            let buffer = p.buffer();
             let point = Point { x: 1, y: 2 };
 
             // Convert the Point to a JSON string.
-            let serialized = serde_json::to_string(&point).map_err(|e| {
+            let serialized: String = serde_json::to_string(&point).map_err(|e| {
                 trace_println!("Failed to serialize point: {}", e);
                 ErrorKind::BadParameters
             })?;
-            let len = buffer.write(serialized.as_bytes()).map_err(|e| {
-                trace_println!("Failed to write to buffer: {}", e);
-                ErrorKind::BadParameters
-            })?;
+
+            let bytes = serialized.as_bytes();
+
+            // Ensure the buffer is large enough to hold the serialized data.
+            if bytes.len() > buffer.len() {
+                trace_println!("Buffer too small, Cannot copy all bytes");
+                return Err(ErrorKind::BadParameters.into());
+            }
+
+            // Copy the serialized JSON string into the buffer.
+            let len = bytes.len();

Review Comment:
   move this line to line68 so that the line70 can use this variable `len`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org


Re: [PR] examples: enable serde example for no-std and promote it to a common example [teaclave-trustzone-sdk]

Posted by "asir66 (via GitHub)" <gi...@apache.org>.
asir66 commented on code in PR #253:
URL: https://github.com/apache/teaclave-trustzone-sdk/pull/253#discussion_r2509528313


##########
examples/serde-rs/ta/src/main.rs:
##########
@@ -52,18 +55,26 @@ fn invoke_command(cmd_id: u32, params: &mut Parameters) -> Result<()> {
     match Command::from(cmd_id) {
         Command::DefaultOp => {
             let mut p = unsafe { params.0.as_memref()? };
-            let mut buffer = p.buffer();
+            let buffer = p.buffer();
             let point = Point { x: 1, y: 2 };
 
             // Convert the Point to a JSON string.
-            let serialized = serde_json::to_string(&point).map_err(|e| {
+            let serialized: String = serde_json::to_string(&point).map_err(|e| {
                 trace_println!("Failed to serialize point: {}", e);
                 ErrorKind::BadParameters
             })?;
-            let len = buffer.write(serialized.as_bytes()).map_err(|e| {
-                trace_println!("Failed to write to buffer: {}", e);
-                ErrorKind::BadParameters
-            })?;
+
+            let bytes = serialized.as_bytes();
+
+            // Ensure the buffer is large enough to hold the serialized data.
+            if bytes.len() > buffer.len() {
+                trace_println!("Buffer too small, cannot copy all bytes");
+                return Err(ErrorKind::BadParameters.into());
+            }
+
+            // Copy the serialized JSON string into the buffer.
+            let len = bytes.len();
+            buffer[..len].copy_from_slice(bytes);
 
             // update size of output buffer
             unsafe { (*p.raw()).size = len };

Review Comment:
   LGTM, thanks for your review



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org


Re: [PR] examples: enable serde example for no-std and promote it to a common example [teaclave-trustzone-sdk]

Posted by "DemesneGH (via GitHub)" <gi...@apache.org>.
DemesneGH commented on code in PR #253:
URL: https://github.com/apache/teaclave-trustzone-sdk/pull/253#discussion_r2509357002


##########
examples/serde-rs/ta/src/main.rs:
##########
@@ -52,18 +55,26 @@ fn invoke_command(cmd_id: u32, params: &mut Parameters) -> Result<()> {
     match Command::from(cmd_id) {
         Command::DefaultOp => {
             let mut p = unsafe { params.0.as_memref()? };
-            let mut buffer = p.buffer();
+            let buffer = p.buffer();
             let point = Point { x: 1, y: 2 };
 
             // Convert the Point to a JSON string.
-            let serialized = serde_json::to_string(&point).map_err(|e| {
+            let serialized: String = serde_json::to_string(&point).map_err(|e| {
                 trace_println!("Failed to serialize point: {}", e);
                 ErrorKind::BadParameters
             })?;
-            let len = buffer.write(serialized.as_bytes()).map_err(|e| {
-                trace_println!("Failed to write to buffer: {}", e);
-                ErrorKind::BadParameters
-            })?;
+
+            let bytes = serialized.as_bytes();
+
+            // Ensure the buffer is large enough to hold the serialized data.
+            if bytes.len() > buffer.len() {
+                trace_println!("Buffer too small, cannot copy all bytes");
+                return Err(ErrorKind::BadParameters.into());
+            }
+
+            // Copy the serialized JSON string into the buffer.
+            let len = bytes.len();
+            buffer[..len].copy_from_slice(bytes);
 
             // update size of output buffer
             unsafe { (*p.raw()).size = len };

Review Comment:
   Please also help to correct this line, should use the `set_updated_size()`
   https://github.com/apache/teaclave-trustzone-sdk/blob/main/optee-utee/src/parameter.rs#L89C12-L89C28



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org


Re: [PR] examples: enable serde example for no-std and promote it to a common example [teaclave-trustzone-sdk]

Posted by "DemesneGH (via GitHub)" <gi...@apache.org>.
DemesneGH merged PR #253:
URL: https://github.com/apache/teaclave-trustzone-sdk/pull/253


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org


Re: [PR] examples: enable serde example for no-std and promote it to a common example [teaclave-trustzone-sdk]

Posted by "asir66 (via GitHub)" <gi...@apache.org>.
asir66 commented on PR #253:
URL: https://github.com/apache/teaclave-trustzone-sdk/pull/253#issuecomment-3510417560

   LGTM, thanks for your review


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org


Re: [PR] examples: enable serde example for no-std and promote it to a common example [teaclave-trustzone-sdk]

Posted by "DemesneGH (via GitHub)" <gi...@apache.org>.
DemesneGH commented on PR #253:
URL: https://github.com/apache/teaclave-trustzone-sdk/pull/253#issuecomment-3511117819

   LGTM, will merge once the CI passes, thanks!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org


Re: [PR] examples: enable serde example for no-std and promote it to a common example [teaclave-trustzone-sdk]

Posted by "DemesneGH (via GitHub)" <gi...@apache.org>.
DemesneGH commented on code in PR #253:
URL: https://github.com/apache/teaclave-trustzone-sdk/pull/253#discussion_r2509357002


##########
examples/serde-rs/ta/src/main.rs:
##########
@@ -52,18 +55,26 @@ fn invoke_command(cmd_id: u32, params: &mut Parameters) -> Result<()> {
     match Command::from(cmd_id) {
         Command::DefaultOp => {
             let mut p = unsafe { params.0.as_memref()? };
-            let mut buffer = p.buffer();
+            let buffer = p.buffer();
             let point = Point { x: 1, y: 2 };
 
             // Convert the Point to a JSON string.
-            let serialized = serde_json::to_string(&point).map_err(|e| {
+            let serialized: String = serde_json::to_string(&point).map_err(|e| {
                 trace_println!("Failed to serialize point: {}", e);
                 ErrorKind::BadParameters
             })?;
-            let len = buffer.write(serialized.as_bytes()).map_err(|e| {
-                trace_println!("Failed to write to buffer: {}", e);
-                ErrorKind::BadParameters
-            })?;
+
+            let bytes = serialized.as_bytes();
+
+            // Ensure the buffer is large enough to hold the serialized data.
+            if bytes.len() > buffer.len() {
+                trace_println!("Buffer too small, cannot copy all bytes");
+                return Err(ErrorKind::BadParameters.into());
+            }
+
+            // Copy the serialized JSON string into the buffer.
+            let len = bytes.len();
+            buffer[..len].copy_from_slice(bytes);
 
             // update size of output buffer
             unsafe { (*p.raw()).size = len };

Review Comment:
   Please also help to correct the line80, should use the `set_updated_size()`
   https://github.com/apache/teaclave-trustzone-sdk/blob/main/optee-utee/src/parameter.rs#L89C12-L89C28



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@teaclave.apache.org
For additional commands, e-mail: dev-help@teaclave.apache.org