DemesneGH commented on code in PR #178:
URL: 
https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/178#discussion_r2034427335


##########
optee-utee/src/tee_parameter.rs:
##########
@@ -0,0 +1,302 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use crate::ParamType;
+use core::ops::{Index, IndexMut};
+use optee_utee_sys as raw;
+
+#[derive(Copy, Clone, Debug)]
+pub enum ParamIndex {
+    Arg0,
+    Arg1,
+    Arg2,
+    Arg3,
+}
+
+impl ParamIndex {
+    fn to_usize(self) -> usize {
+        match self {
+            ParamIndex::Arg0 => 0,
+            ParamIndex::Arg1 => 1,
+            ParamIndex::Arg2 => 2,
+            ParamIndex::Arg3 => 3,
+        }
+    }
+}
+
+enum ParamContent<'a> {
+    None,
+    MemrefInput {
+        buffer: &'a [u8],
+    },
+    MemrefOutput {
+        buffer: &'a mut [u8],
+        written: usize,
+    },
+    MemrefInout {
+        buffer: &'a mut [u8],
+        written: usize,
+    },
+    ValueInput {
+        a: u32,
+        b: u32,
+    },
+    ValueOutput {
+        a: u32,
+        b: u32,
+    },
+    ValueInout {
+        a: u32,
+        b: u32,
+    },
+}
+
+pub struct Param<'a> {
+    content: ParamContent<'a>,
+}
+
+impl<'a> Param<'a> {
+    fn new() -> Self {
+        Self {
+            content: ParamContent::None,
+        }
+    }
+
+    pub fn written_slice(&self) -> Option<&[u8]> {
+        match &self.content {
+            ParamContent::MemrefOutput { buffer, written } => 
Some(&buffer[..*written]),
+            ParamContent::MemrefInout { buffer, written } => 
Some(&buffer[..*written]),
+            _ => None,
+        }
+    }
+
+    pub fn output_value(&self) -> Option<(u32, u32)> {
+        match &self.content {
+            ParamContent::ValueOutput { a, b } => Some((*a, *b)),
+            ParamContent::ValueInout { a, b } => Some((*a, *b)),
+            _ => None,
+        }
+    }
+
+    fn get_type(&self) -> ParamType {
+        match &self.content {
+            ParamContent::None => ParamType::None,
+            ParamContent::MemrefInput { .. } => ParamType::MemrefInput,
+            ParamContent::MemrefOutput { .. } => ParamType::MemrefOutput,
+            ParamContent::MemrefInout { .. } => ParamType::MemrefInout,
+            ParamContent::ValueInput { .. } => ParamType::ValueInput,
+            ParamContent::ValueOutput { .. } => ParamType::ValueOutput,
+            ParamContent::ValueInout { .. } => ParamType::ValueInout,
+        }
+    }
+
+    fn get_raw_type(&self) -> u32 {
+        self.get_type() as u32
+    }
+
+    fn as_raw(&mut self) -> raw::TEE_Param {
+        match &mut self.content {
+            ParamContent::None => raw::TEE_Param {
+                memref: raw::Memref {
+                    buffer: core::ptr::null_mut(),
+                    size: 0,
+                },
+            },
+            ParamContent::MemrefInput { buffer } => raw::TEE_Param {
+                memref: raw::Memref {
+                    buffer: (*buffer).as_ptr() as *mut core::ffi::c_void,
+                    size: buffer.len(),
+                },
+            },
+            ParamContent::MemrefOutput { buffer, written: _ } => 
raw::TEE_Param {
+                memref: raw::Memref {
+                    buffer: (*buffer).as_mut_ptr() as *mut core::ffi::c_void,
+                    size: buffer.len(),
+                },
+            },
+            ParamContent::MemrefInout { buffer, written: _ } => raw::TEE_Param 
{
+                memref: raw::Memref {
+                    buffer: (*buffer).as_mut_ptr() as *mut core::ffi::c_void,
+                    size: buffer.len(),
+                },
+            },
+            ParamContent::ValueInput { a, b } => raw::TEE_Param {
+                value: raw::Value { a: *a, b: *b },
+            },
+            ParamContent::ValueInout { a, b } => raw::TEE_Param {
+                value: raw::Value { a: *a, b: *b },
+            },
+            ParamContent::ValueOutput { a, b } => raw::TEE_Param {
+                value: raw::Value { a: *a, b: *b },
+            },
+        }
+    }
+
+    fn update_size_from_raw(&mut self, raw_param: &raw::TEE_Param) {
+        match &mut self.content {
+            ParamContent::MemrefOutput { buffer: _, written } => {
+                *written = unsafe { raw_param.memref.size };

Review Comment:
   Will add `SAFETY` comment for the modules inside this PR. Since `cargo 
clippy` infects many other modules, there will be another PR to address all 
rules.



-- 
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-unsubscr...@teaclave.apache.org

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


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

Reply via email to