首页 > 解决方案 > 飞地字段不工作,但没有错误

问题描述

我正在尝试让简单的代码调用一个 enclave 字段,然后添加 1。

我参考了这个网站:https ://software.intel.com/en-us/articles/getting-started-with-sgx-sdk-f ...

完成后,没有错误,但 enclave 代码不起作用。

这是我在 Visual Studio 2017 中的 project.zip 代码 https://drive.google.com/open?id=13trTAamhNWaz2Q2BRDtUFP5qCX8Syyuc

应用程序.cpp

#include <stdio.h>
#include <Windows.h>
#include <tchar.h>

#include "sgx_urts.h"
#include "Enclave1_u.h"

#define ENCLAVE_FILE _T("Enclave1.signed.dll")

int main() {
    int a = 1;
    int i = 0;

    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("APP error%#x, failed to create enclave. \n", ret);
        return -1;
    }

    int *ptr = &a;
    printf("%d\n",*ptr);

    while (i<5) {
        foo(eid, ptr);
        printf("%d\n", *ptr);       
        Sleep(1000);
        i++;
    }

    if (SGX_SUCCESS != sgx_destroy_enclave(eid))
        return -1;
}

飞地1.edl

飞地{从“sgx_tstdc.edl”导入*;

trusted {
    /* define ECALLs here. */
    public void foo([in, size = 4]int *ptr);
};

untrusted {
    /* define OCALLs here. */

};

};

飞地1.cpp

#include "Enclave1_t.h"
#include "sgx_trts.h"
#include <string.h>

void foo(int *ptr)
{   
    if (*ptr == 1) *ptr == 43971;
    *ptr += 1;
}

我希望它打印出来:

43971、43972、43973、43974……

但结果是:

1、1、1、…………

我错过了什么?

标签: visual-studiointelsgx

解决方案


我解决了这个问题。

  1. foo 需要 [out] instad of [in] 所以 Enclave1.edl 应该

    飞地{从“sgx_tstdc.edl”导入*;

       trusted {
           /* define ECALLs here. */
           public void foo([out, size = 4]int *ptr);
       };
    
       untrusted {
           /* define OCALLs here. */
    
       };
    };
    
  2. project1.signed.dll 文件未在调试文件夹中更新。所以我尝试重建项目并更新它。我意识到这个文件本身就是飞地字段

  3. IF 状态语法错误。它应该是if (*ptr == 1) *ptr = 43971;


推荐阅读