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

template class usage in Intel SGX

MoonHasSevenColor
859 Views

Dear Intel Community,

 

  Hope the message finds you well. May I ask a question related Intel SGX. Recently I need use C++'s template class in Intel SGX, and referred from SGX developer guide, the C++ template class should has been enabled in the latest versions. But when I try to use the template class in Intel SGX, it always exits and reports error: Invalid token: <

 

  The function at Enclave.edl is: 

 

 template<typename T>

    public void template_test_sgx(int a);

  

And the function at Enclave.cpp is:

 

 

 template<typename T>

void template_test_sgx(int a){

    printf("Here is template usage in SGX\n");

}

 

 

 

Thank you for your help! Have a nice day!

 

 

 

Best Regards,

Jin Xin

0 Kudos
4 Replies
Iffa_Intel
Moderator
831 Views

A general valid cpp syntax doesn't have "<>" symbol in the declaration of variables. That is why you were getting "Invalid token: <" error.

 

From the documentation that you share, the template is an illustration of how you can use a cpp function in Intel SGX.

 

template< class T, std::size_t A, std::size_t... OLs> is equivalent to creating a function like this in cpp (The class template can’t be used in pure cpp code):

 

Typedef struct {

size_t offset; size_t len;

} align_req_t;

 

void *sgx_get_aligned_ptr(void *raw, size_t raw_size, size_t allocate_size, size_t alignment, align_req_t *data, size_t count); 

 

 

 

You may refer to this;

  1. Intel SGX Get Started official page
  2. Intel SGX sample code



Cordially,

Iffa


0 Kudos
MoonHasSevenColor
810 Views

Dear lffa,

 

  Thank you for your nice reply! I'm not sure if your misunderstand the usage of C++'s "<template>", it is a kind of Generic programming method instead of how to use cpp in SGX. If there are any misunderstanding from my side, feel free to indicate Thank you!

 

 

Best Regards,

Jin Xin

0 Kudos
Iffa_Intel
Moderator
760 Views

Hi,

 

as mentioned before (mentioned in the official SGX documentation shared by you), the class template can’t be used in pure cpp code, hence, the function below is used:

 

Typedef struct {

size_t offset; size_t len;

} align_req_t;

 

void *sgx_get_aligned_ptr(void *raw, size_t raw_size, size_t allocate_size, size_t alignment, align_req_t *data, size_t count); 

 

We highly recommend that you refer to these Official Intel SGX sample codes that are officially validated.

 

Cordially,

Iffa

 

0 Kudos
Iffa_Intel
Moderator
668 Views

Hi


Intel will no longer monitor this thread since we have provided a solution. If you need any additional information from Intel, please submit a new question. 


Cordially,

Iffa


0 Kudos
Reply