Why in SGX enclave string argument has to be used with [in] attribute

Viewed 805

Using OCALL, I want to get a copy of C string that is dynamically created in untrusted memory into my enclave. Thus, I have to use [out, string] attribute.

However, I cannot do that because I have to add [in] attribute as well. The problem is that I really don't know the size of string and I don't want an overhead (that comes with [in]) from unnecessary copying of string from enclave to untrusted memory every time I make OCALL.

My edl file:

enclave {
    trusted {
        public void ecall_open(void);
    };
    untrusted {
        void ocall_get_string([out, string] char* str);
    };
};

error: string/wstring/sizefunc should be used with an 'in' attribute

Why do I have to add [in] attribute?

For performance reasons is there a way to avoid this overhead?

2 Answers

Maybe you should try this:

void ocall_get_string([out, size=sz] char* str, size_t sz);

size=sz means the size of the str that will be copied back to Enclave automatically. If you don't specify size, then only one char will be copied back to Enclave.

Related