Update implementation of PluginParameters
diff --git a/examples/supp_plugin/plugin/src/lib.rs b/examples/supp_plugin/plugin/src/lib.rs
index 0f26126..25a6ed9 100644
--- a/examples/supp_plugin/plugin/src/lib.rs
+++ b/examples/supp_plugin/plugin/src/lib.rs
@@ -30,10 +30,10 @@
     println!("*plugin*: invoke");
     match PluginCommand::from(params.cmd) {
         PluginCommand::Print => {
-            println!("*plugin*: receive value: {:?} length {:?}", params.inbuf, params.inbuf.len());
+            println!("*plugin*: receive value: {:?} length {:?}", params.inout, params.inout.len());
 
             let send_slice: [u8;9] = [0x40;9];
-            params.set_outbuf_from_slice(&send_slice)?;
+            params.set_buf_from_slice(&send_slice)?;
             println!("*plugin*: send value: {:?} length {:?} to ta", send_slice, send_slice.len());
         }
         _ => println!("Unsupported plugin command: {:?}", params.cmd),
diff --git a/optee-teec/macros/src/lib.rs b/optee-teec/macros/src/lib.rs
index 7c69abf..274a4be 100644
--- a/optee-teec/macros/src/lib.rs
+++ b/optee-teec/macros/src/lib.rs
@@ -93,11 +93,14 @@
             in_len: u32,
             out_len: *mut u32
         ) -> optee_teec::Result<()> {
-            let inbuf = unsafe { std::slice::from_raw_parts(data, in_len as usize) };
+            let mut inbuf = unsafe { std::slice::from_raw_parts_mut(data, in_len as usize) };
             let mut params = PluginParameters::new(cmd, sub_cmd, inbuf);
             #f_block
-            let outslice = params.get_outbuf_as_slice();
-            unsafe { std::ptr::copy(outslice.as_ptr(), data, outslice.len()) };
+            let outslice = params.get_out_slice();
+            unsafe {
+                *out_len = outslice.len() as u32;
+                std::ptr::copy(outslice.as_ptr(), data, outslice.len());
+            }
 
             Ok(())
         }
diff --git a/optee-teec/src/extension.rs b/optee-teec/src/extension.rs
index 949d4b9..bac750f 100644
--- a/optee-teec/src/extension.rs
+++ b/optee-teec/src/extension.rs
@@ -34,37 +34,36 @@
 }
 
 /// struct PluginParameters {
-/// @cmd: u32,          plugin cmd, defined in proto/
-/// @sub_cmd: u32,      plugin subcmd, defined in proto/
-/// @inbuf: &'a [u8],   input buffer sent from TA
-/// @outbuf: Vec<u8>,   output buffer sent from plugin to TA,
-///                     outlen SHOULD be less than or equal to inlen
+/// @cmd: u32,              plugin cmd, defined in proto/
+/// @sub_cmd: u32,          plugin subcmd, defined in proto/
+/// @inout: &'a mut [u8],   input/output buffer shared with TA and plugin
+/// @outlen,                length of output sent to TA
 /// }
 pub struct PluginParameters<'a> {
     pub cmd: u32,
     pub sub_cmd: u32,
-    pub inbuf: &'a [u8],
-    outbuf: Vec<u8>,
+    pub inout: &'a mut [u8],
+    outlen: usize,
 }
 impl<'a> PluginParameters<'a> {
-    pub fn new(cmd: u32, sub_cmd: u32, inbuf: &'a [u8]) -> Self {
-        let mut outbuf = vec![0u8; inbuf.len() as usize];
+    pub fn new(cmd: u32, sub_cmd: u32, inout: &'a mut [u8]) -> Self {
         Self {
-            cmd,
-            sub_cmd,
-            inbuf,
-            outbuf,
+            cmd: cmd,
+            sub_cmd: sub_cmd,
+            inout: inout,
+            outlen: 0 as usize,
         }
     }
-    pub fn set_outbuf_from_slice(&mut self, sendslice: &[u8]) -> Result<()> {
-        if self.inbuf.len() < sendslice.len() {
+    pub fn set_buf_from_slice(&mut self, sendslice: &[u8]) -> Result<()> {
+        if self.inout.len() < sendslice.len() {
             println!("Overflow: Input length is less than output length");
             return Err(Error::new(ErrorKind::Security));
         }
-        self.outbuf[..sendslice.len()].copy_from_slice(&sendslice);
+        self.outlen = sendslice.len() as usize;
+        self.inout[..self.outlen].copy_from_slice(&sendslice);
         Ok(())
     }
-    pub fn get_outbuf_as_slice(&self) -> &[u8] {
-        self.outbuf.as_slice()
+    pub fn get_out_slice(&self) -> &[u8] {
+        &self.inout[..self.outlen]
     }
 }