Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
15 Views

Allocating a buffer inside an Enclave

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? 

 

 


 

Tags (1)
0 Kudos
1 Reply
Highlighted
Employee
15 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