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

Intel SGX, sgx_create_enclave() never returns if called from dllmain()

mingbo_z_1
Beginner
1,946 Views

Hello,

SGX API works fine if it's called from a process. I can create an enclave successfully.

But when sgx_create_enclave() is called from dllmain(), it never returns. It eventually calls WaitForSingleObject() and wait there. 

No matter the dll is injected into a process or load by a process.

Thanks :)
uty

0 Kudos
1 Solution
Francisco_C_Intel
1,947 Views

I believe this is due to:

Dynamic-Link Library Best Practices https://msdn.microsoft.com/en-us/library/windows/desktop/dn633971(v=vs.85).aspx

"You should never perform the following tasks from within DllMain:
*  Call LoadLibrary or LoadLibraryEx (either directly or indirectly). This can cause a deadlock or a crash."

(edited to fix link)

View solution in original post

0 Kudos
3 Replies
Mingbo_Z_
Beginner
1,947 Views

I installed the latest version of SDK, still got the same problem.

0 Kudos
Francisco_C_Intel
1,948 Views

I believe this is due to:

Dynamic-Link Library Best Practices https://msdn.microsoft.com/en-us/library/windows/desktop/dn633971(v=vs.85).aspx

"You should never perform the following tasks from within DllMain:
*  Call LoadLibrary or LoadLibraryEx (either directly or indirectly). This can cause a deadlock or a crash."

(edited to fix link)

0 Kudos
Mingbo_Z_
Beginner
1,947 Views

FRANCISCO C. (Intel) wrote:

I believe this is due to:

Dynamic-Link Library Best Practices https://msdn.microsoft.com/en-us/library/windows/desktop/dn633971(v=vs.85).aspx

"You should never perform the following tasks from within DllMain:
*  Call LoadLibrary or LoadLibraryEx (either directly or indirectly). This can cause a deadlock or a crash."

(edited to fix link)

Thanks for the reply and link :)

I know sgx_create_enclave()  will load xxx.signed.dll at some point.   I want use sgx in some processes which I don't have source code. I guess I have to use sgx_create_enclave() lazily (The first time I need to use enclave).

Thanks :)

0 Kudos
Reply