簡體   English   中英

飛地不工作,但沒有錯誤

[英]Enclave field not working, but there is no error

我正在嘗試使簡單的代碼稱為安全區域,只需添加1。

我正在引用此站點: https : //software.intel.com/zh-cn/articles/getting-started-with-sgx-sdk-f ...

完成后,沒有錯誤,但是安全區代碼不起作用。

這是我的Visual Studio 2017的project.zip代碼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需要[in]的[out] instad,因此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 (*ptr == 1) *ptr = 43971;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM