Intel® Software Guard Extensions (Intel® SGX)
Discussion board focused on hardware-based isolation and memory encryption to provide extended code protection in solutions.

Allocating a buffer inside an Enclave

Meysam_t_
Beginner
537 Views

Hello,

I am trying to allocate a buffer inside an enclave by using new in an ecall function as follows 

This is what I have in Enclave.edl        

public int buffer_allocator([out, size=len] char * buffer, size_t len);

And this is what I defined in Enclave.cpp

// to allocate a buffer in EPC

// to allocate a buffer in EPC 
int buffer_allocator(char * buffer, size_t len)
{
    buffer = new char[len];
    if (!buffer)
        return (1);
    else
        return(0);    
    
 }

However, when I am running it, it returns 0 meaning that it fails to allocate memory. The question is how to allocate a buffer inside the enclave? 

 

 


 

0 Kudos
1 Reply
Scott_R_Intel
Employee
537 Views

Hello.

That will allocate the buffer just fine, provided you have set up enough enclave heap size in the Enclave.config.xml for the length of buffer you're trying to allocate.

I think the problem is that you have your null check logic (or return values) backward, which is why you are getting a zero returned...  It should be "if (buffer) return 1;" or "if (!buffer) return 0;".

Regards.

Scott

0 Kudos
Reply