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

HELP! Maybe something wrong in defining struct in Enclave.

Li__Xiaoguo
Beginner
524 Views
##  types.h  ##

struct Node;

typedef union {
        char *value;
        Node *next;
} child_t;

struct Node
{
        int type;
        int *key;
        child_t *child;
        
        Node()
        {
                key = new int[FAN_OUT];
                child = new child_t[FAN_OUT];
        }
};
##   Enclave.edl  ##

include "types.h"

trusted {
        public void ecall_printf_node([in] struct Node *root);
};

I want to pass a node of B+ Tree to the enclave from an outsider app. However, it reports the following error:

GEN  =>  App/Enclave_u.c
In file included from App/Enclave_u.h:10:0,
                 from App/Enclave_u.c:1:
Include/types.hpp:23:9: error: unknown type name ‘Node’
         Node *next;
         ^~~~
Include/types.hpp:33:9: error: expected specifier-qualifier-list before ‘Node’
         Node()
         ^~~~
Makefile:178: recipe for target 'App/Enclave_u.o' failed.

Three questions:

1) In the enclave, does it supports a forward declaration of a class or struct? such as   "struct Node"   as above;

2) In the enclave, should the struct have a constructor?   such as  the function  "Node()"   as above;

3) if not, how should I achieve above?

0 Kudos
1 Solution
JesusG_Intel
Moderator
524 Views

Hello Xiaoguo,

The problem is that constructors in structs are allowed in C++ but are now allowed in C. The Edger8r tool will create bridge functions for your ecalls and ocalls in C, as you see in Enclave_u.c.  You can call C++ class methods in your enclave but the enclave interface functions, i.e. e-calls, must be written in C. See the SGX Developer Reference Guide table 7 or 8, titled Summary of Intel SGX Rules and Limitations for more information.

A similar question has been addressed here.

Regards,

Jesus

View solution in original post

0 Kudos
1 Reply
JesusG_Intel
Moderator
525 Views

Hello Xiaoguo,

The problem is that constructors in structs are allowed in C++ but are now allowed in C. The Edger8r tool will create bridge functions for your ecalls and ocalls in C, as you see in Enclave_u.c.  You can call C++ class methods in your enclave but the enclave interface functions, i.e. e-calls, must be written in C. See the SGX Developer Reference Guide table 7 or 8, titled Summary of Intel SGX Rules and Limitations for more information.

A similar question has been addressed here.

Regards,

Jesus

0 Kudos
Reply