加载 Enclave 时出错:无法使用 CreateFile() 打开文件
Error Loading Enclave: Couldn't open file with CreateFile()
我正在尝试编写一个简单的 SGX 项目作为开始。所以我有这个主要的主机应用程序例程,我几乎从 Lars Richter's blog:
复制了它
#define ENCLAVE_FILE _T("Enclave.signed.dll")
#include <tchar.h>
#include <cstdio>
#include "sgx_urts.h"
#include "Enclave_u.h"
int main()
{
sgx_enclave_id_t eid;
sgx_status_t ret = SGX_SUCCESS;
sgx_launch_token_t token = { 0 };
int updated = 0;
ret = sgx_create_enclave(ENCLAVE_FILE, SGX_DEBUG_FLAG, &token, &updated, &eid, NULL);
if (ret != SGX_SUCCESS) {
printf("\nApp: error %#x, failed to create enclave.\n", ret);
}
scanf("\n");
return 0;
}
它编译得很好(我使用的是英特尔 C++ 17.0 编译器和 Visual Studio 2015)但它没有加载 enclave。我收到以下错误消息:
[sgx_create_enclavew ..\urts\win\urts.cpp:195] Couldn't open file with CreateFile()
App: error 0x200f, failed to create enclave.
正如 Neil 所指出的,sgx_create_enclave 在 Visual Studio 的调试器中 运行 程序时找不到 dll。当我直接 运行 "Debug" 文件夹中的可执行文件时,它工作正常。
因此,要使其在两种设置下都有效,一个简单的技巧是执行以下操作:
#define ENCLAVE_FILE _T("../Debug/Enclave.signed.dll")
转到app_test_save项目设置。在 Debugging 下,将 working directory 更改为 $(SolutionDir)Debug。这个答案假设这两个项目 app_test_save 和 enclave_test_save 属于同一个解决方案。
根据这个:https://software.intel.com/en-us/forums/intel-software-guard-extensions-intel-sgx/topic/623738
如果您使用本地 SGX 调试器,请确保将 "current working directory" 指向 $(OutDir) 而不是 $(ProjectDir)。
配置属性 --> 调试 --> 工作目录 --> $(OutDir)。
错误基本上意味着它无法找到您的 .dll 文件。
执行 dir /a/s 找到 Enclave.signed.dll 然后适当地更改名称。
当您创建 enclave 时,它将生成 signed.dll 文件。如果您的 enclave 名称是 Enclave12,则 DLL 名称是 Enclave12.signed.dll。你解决了这个问题就可以开始了。
我正在尝试编写一个简单的 SGX 项目作为开始。所以我有这个主要的主机应用程序例程,我几乎从 Lars Richter's blog:
复制了它#define ENCLAVE_FILE _T("Enclave.signed.dll")
#include <tchar.h>
#include <cstdio>
#include "sgx_urts.h"
#include "Enclave_u.h"
int main()
{
sgx_enclave_id_t eid;
sgx_status_t ret = SGX_SUCCESS;
sgx_launch_token_t token = { 0 };
int updated = 0;
ret = sgx_create_enclave(ENCLAVE_FILE, SGX_DEBUG_FLAG, &token, &updated, &eid, NULL);
if (ret != SGX_SUCCESS) {
printf("\nApp: error %#x, failed to create enclave.\n", ret);
}
scanf("\n");
return 0;
}
它编译得很好(我使用的是英特尔 C++ 17.0 编译器和 Visual Studio 2015)但它没有加载 enclave。我收到以下错误消息:
[sgx_create_enclavew ..\urts\win\urts.cpp:195] Couldn't open file with CreateFile()
App: error 0x200f, failed to create enclave.
正如 Neil 所指出的,sgx_create_enclave 在 Visual Studio 的调试器中 运行 程序时找不到 dll。当我直接 运行 "Debug" 文件夹中的可执行文件时,它工作正常。
因此,要使其在两种设置下都有效,一个简单的技巧是执行以下操作:
#define ENCLAVE_FILE _T("../Debug/Enclave.signed.dll")
转到app_test_save项目设置。在 Debugging 下,将 working directory 更改为 $(SolutionDir)Debug。这个答案假设这两个项目 app_test_save 和 enclave_test_save 属于同一个解决方案。
根据这个:https://software.intel.com/en-us/forums/intel-software-guard-extensions-intel-sgx/topic/623738
如果您使用本地 SGX 调试器,请确保将 "current working directory" 指向 $(OutDir) 而不是 $(ProjectDir)。
配置属性 --> 调试 --> 工作目录 --> $(OutDir)。
错误基本上意味着它无法找到您的 .dll 文件。 执行 dir /a/s 找到 Enclave.signed.dll 然后适当地更改名称。 当您创建 enclave 时,它将生成 signed.dll 文件。如果您的 enclave 名称是 Enclave12,则 DLL 名称是 Enclave12.signed.dll。你解决了这个问题就可以开始了。