Is there a clean way to detect at runtime if code is executing inside an SGX enclave?

Viewed 133

I'm writing some code that has to be well behaved both inside and outside an SGX enclave. To that end, it would be useful to have some way to determine at runtime whether or not the code is executing inside an enclave or not. Unfortunately, after searching the documentation, I haven't been able to find a way to do this.

TL:DR; I'm looking for a bool in_sgx_context() function which I can use to steer application behaviour depending on whether or not my code is running inside a secure enclave or not.

1 Answers

You should be able to use #ifdef SGX_HW_SIM. If not, define it as a compile flag.

Related