我正在尝试运行以下代码以在我的机器中启用 SGX(BIOS:软件控制):
//enable_device.c
#include "stdio.h"
#include "sgx_capable.h"
#include "sgx_eid.h"
#include "sgx_urts.h"
#include "sgx_error.h"
int main(void) {
sgx_device_status_t sgx_device_status;
sgx_status_t ret;
ret = sgx_cap_enable_device(&sgx_device_status);
if(ret == SGX_SUCCESS) {
switch(sgx_device_status) {
case SGX_ENABLED:
printf("The platform is enabled for Intel SGX.\n$
break;
case SGX_DISABLED_REBOOT_REQUIRED:
printf("This platform is disabled for Intel SGX.$
break;
case SGX_DISABLED_MANUAL_ENABLE:
printf("The platform is disabled for Intel SGX b$
break;
// case SGX_DISABLED_HYPERV_ENABLED:
// printf("The detected version of Windows* 10 is i$
// break;
case SGX_DISABLED_LEGACY_OS:
printf("The operating system does not support UE$
break;
case SGX_DISABLED_UNSUPPORTED_CPU:
printf("Intel SGX is not supported by this proce$
break;
case SGX_DISABLED:
printf("This platform is disabled for Intel SGX.$
break;
default:
printf("UNKNOWN RESPONSE\n");
}
} else {
switch(ret) {
case SGX_ERROR_INVALID_PARAMETER:
printf("The sgx_device_status pointer is invalid$
break;
case SGX_ERROR_NO_PRIVILEGE:
printf("The application does not have the requir$
break;
// case SGX_ERROR_HYPERV_ENABLED:
// printf("The detected version of Windows* 10 is i$
// break;
default:
printf("An unexpected error is detected.\n");
}
}
return 0;
}
这是我正在使用的 Makefile:
######### SGX TOOLS ######################
SGX_SDK := /usr/local/lib/intel/sgxsdk
SGX_LIBRARY_PATH := $(SGX_SDK)/lib64
######## App Settings ########
App_C_Files := enable_device.c
App_C_Flags := -fPIC -Wno-attributes -IInclude -IApp -I$(SGX_SDK)/include
App_Cpp_Flags := $(App_C_Flags) -std=c++11
App_Link_Flags := -L$(SGX_LIBRARY_PATH) -lsgx_capable
App_C_Objects := $(App_C_Files:.c=.o)
App_Name := app
.PHONY: all run
all: $(App_Name)
run: all
######## App Objects ########
enable_device.o: enable_device.c
@$(CC) $(App_C_Flags) -c $< -o $@
$(App_Name): enable_device.o
@$(CC) $^ -o $@ $(App_Link_Flags)
.PHONY: clean
clean:
@rm -f $(App_Name) $(App_C_Objects)
当我运行应用程序时,我收到以下消息:
应用程序没有读取 EFI 变量所需的权限。以管理员权限运行应用程序以启用英特尔 SGX 设备状态。
然后,我运行sudo ./app
并收到以下错误:
./app:加载共享库时出错:libsgx_capable.so:无法打开共享对象文件:没有这样的文件或目录
奇怪的是编译的时候没有找到这个库:
$ldd app
linux-vdso.so.1 (0x00007ffe065bc000)
libsgx_capable.so => not found
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f15a060d000)
/lib64/ld-linux-x86-64.so.2 (0x00007f15a0c01000)
然后,我使用:
export LD_LIBRARY_PATH=/usr/local/lib/intel/sgxsdk/lib64/
我再次运行并返回相同的错误消息。谁能告诉我我错过了什么?