飞地字段不工作,但没有错误

Enclave field not working, but there is no error

我正在尝试让简单的代码调用飞地字段并仅添加 1。

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

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

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

app.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;
}

Enclave1.edl

飞地{ 从 "sgx_tstdc.edl" 导入 *;

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

untrusted {
    /* define OCALLs here. */

};

};

Enclave1.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, .........

我错过了什么?

我解决了这个问题。

  1. foo 需要 [out] 而不是 [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 文件未在调试文件夹中更新。所以我尝试重建项目并更新它。我意识到这个文件本身就是 enclave 字段

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