You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@teaclave.apache.org by di...@apache.org on 2020/08/24 03:01:21 UTC

[incubator-teaclave-sgx-sdk] branch mem_footprint created (now ca3d05e)

This is an automated email from the ASF dual-hosted git repository.

dingyu pushed a change to branch mem_footprint
in repository https://gitbox.apache.org/repos/asf/incubator-teaclave-sgx-sdk.git.


      at ca3d05e  Statis of memory footprint

This branch includes the following new commits:

     new ca3d05e  Statis of memory footprint

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



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


[incubator-teaclave-sgx-sdk] 01/01: Statis of memory footprint

Posted by di...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dingyu pushed a commit to branch mem_footprint
in repository https://gitbox.apache.org/repos/asf/incubator-teaclave-sgx-sdk.git

commit ca3d05e085ebc558310530ae6d5b36d0194d764c
Author: Yu Ding <di...@gmail.com>
AuthorDate: Sun Aug 23 20:01:03 2020 -0700

    Statis of memory footprint
---
 samplecode/hello-rust/Readme.md          |  3 ++
 samplecode/hello-rust/enclave/src/lib.rs | 71 ++++++++++++++++++++++++++++++--
 2 files changed, 71 insertions(+), 3 deletions(-)

diff --git a/samplecode/hello-rust/Readme.md b/samplecode/hello-rust/Readme.md
new file mode 100644
index 0000000..da1d1f0
--- /dev/null
+++ b/samplecode/hello-rust/Readme.md
@@ -0,0 +1,3 @@
+```
+sudo objcopy --globalize-symbol=_gm_ ./libsgx_tstdc.a
+```
diff --git a/samplecode/hello-rust/enclave/src/lib.rs b/samplecode/hello-rust/enclave/src/lib.rs
index f661955..12bbff7 100644
--- a/samplecode/hello-rust/enclave/src/lib.rs
+++ b/samplecode/hello-rust/enclave/src/lib.rs
@@ -37,8 +37,75 @@ use std::io::{self, Write};
 use std::slice;
 use std::backtrace::{self, PrintFormat};
 
+type binmap_t = u32;
+//type size_t = u64;
+type flag_t = u32;
+
+#[repr(C)]
+struct malloc_chunk {
+    prev_foot: size_t,
+    head: size_t,
+    fd: * mut malloc_chunk,
+    bk: * mut malloc_chunk,
+}
+
+const NSMALLBINS: size_t = 32;
+const NTREEBINS: size_t = 32;
+
+#[repr(C)]
+struct malloc_segment {
+    base: * mut i8,
+    size: * mut size_t,
+    next: * mut malloc_segment,
+    fsflags: flag_t,
+}
+
+#[repr(C)]
+struct malloc_state {
+    smallmap: binmap_t,
+    treemap: binmap_t,
+    dvsize: size_t,
+    topsize: size_t,
+    least_addr: * mut i8,
+    dv: * mut malloc_chunk,
+    top: * mut malloc_chunk,
+    trim_check: size_t,
+    release_checks: size_t,
+    magic: size_t,
+    smallbins: [* mut malloc_chunk;(NSMALLBINS+1)*2],
+    treebins: [* mut malloc_chunk;NTREEBINS],
+    footprint: size_t,
+    max_footprint: size_t,
+    footprint_limit: size_t,
+    mflags: flag_t,
+    seg: malloc_segment,
+    extp: * mut c_void,
+    mutex: u32, // MLOCK_T
+    exts: size_t,
+}
+
+#[link_name = "sgx_tstdc"]
+extern "C" {
+    static _gm_: malloc_state;
+}
+
 #[no_mangle]
 pub extern "C" fn say_something(some_string: *const u8, some_len: usize) -> sgx_status_t {
+    let mut word_vec;
+    unsafe {
+        println!("global memory footprint = {}", _gm_.footprint);
+        println!("global memory max_footprint = {}", _gm_.max_footprint);
+        println!("global memory footprint_limit = {}", _gm_.footprint_limit);
+        // An vector
+        word_vec = vec![32, 115, 116, 114, 105, 110, 103, 33];
+        for i in 0..10000 {
+            word_vec.push((i as u8) % 0xff);
+        }
+        println!("global memory footprint = {}", _gm_.footprint);
+        println!("global memory max_footprint = {}", _gm_.max_footprint);
+        println!("global memory footprint_limit = {}", _gm_.footprint_limit);
+    }
+    word_vec = vec![32, 115, 116, 114, 105, 110, 103, 33];
 
     let str_slice = unsafe { slice::from_raw_parts(some_string, some_len) };
     let _ = io::stdout().write(str_slice);
@@ -47,8 +114,6 @@ pub extern "C" fn say_something(some_string: *const u8, some_len: usize) -> sgx_
     let rust_raw_string = "This is a in-Enclave ";
     // An array
     let word:[u8;4] = [82, 117, 115, 116];
-    // An vector
-    let word_vec:Vec<u8> = vec![32, 115, 116, 114, 105, 110, 103, 33];
 
     // Construct a string from &'static string
     let mut hello_string = String::from(rust_raw_string);
@@ -127,4 +192,4 @@ fn get_thread_num() -> (u32, u32, u32) {
         }
     }
     (static_thread_num, eremove_thread_num, dyn_thread_num)
-}
\ No newline at end of file
+}


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