I have a untrusted function declared as below:
```
 int ocall_call(
            [in, count=en_req_size] const uint8_t* en_req,
            size_t en_req_size,
            [out] void** output,
            [out] size_t* output_size
        ) ;
```
and defined as below:
```
#[no_mangle]
pub extern "C" fn ocall_call(
    en_req: *const u8,
    en_req_size: usize,
    output: *mut *mut libc::c_void,
    output_size: *mut usize,
) -> sgx_status_t {
    let en_req_slice = unsafe { slice::from_raw_parts(en_req, en_req_size) };

    // ... here omits the step to get res from en_req_slice, which works well.

    let s = serde_json::to_string(&res).unwrap();
    unsafe {
        *output = libc::malloc(s.len());
        //TODO 判断malloc是否成功,参考: 
https://github.com/apache/incubator-teaclave-sgx-sdk/blob/e60e5adfadcbe4b34913d1c82cd5f7ac021fc3cf/sgx_urts/src/mem.rs#L22
        std::ptr::copy_nonoverlapping(s.as_ptr(), *(output as *mut *mut u8), 
s.len());
        *output_size = s.len();
    }
    sgx_status_t::SGX_SUCCESS
}
```
everything works well now.  Then I try free the memory allocated in ocall_call 
by:
1. calling libc::free in TEE,  core dumpped raised without any tips.
2. ocall_free(p *mut libc::c_void) { libc::free(p) } ,  core dumped with tip 
`munmap_chunk(): invalid pointer `, then I print the address p  before and 
after ocall_free,  get the different value.  

neither of that does work.  

plz help, thanks.

Bing 



-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/apache/incubator-teaclave-sgx-sdk/issues/251

Reply via email to