飛地字段不工作,但沒有錯誤 (Enclave field not working, but there is no error)


問題描述

飛地字段不工作,但沒有錯誤 (Enclave field not working, but there is no error)

我正在嘗試讓簡單的代碼調用一個 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

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

enclave { 來自“sgx_tstdc.edl" import *;

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:

i solved this problem.

  1. foo needs [out] instad of [in] so Enclave1.edl should

    enclave { from "sgx_tstdc.edl" import *;

       trusted {
           /* define ECALLs here. */
           public void foo([out, size = 4]int *ptr);
       };
    
       untrusted {
           /* define OCALLs here. */
    
       };
    };
    
  2. project1.signed.dll file is not updated on debug folder. so i try rebuild project and it updated. I'm realized this file is enclave field itself

  3. IF state grammar is wrong. it should be if (*ptr == 1) *ptr = 43971;

(by user10865941user10865941)

參考文件

  1. Enclave field not working, but there is no error (CC BY‑SA 2.5/3.0/4.0)

#visual-studio #intel #sgx






相關問題

如何在 C# 中使用帶有動態參數的 INSERT INTO SQL 查詢? (How to use a INSERT INTO SQL Query with Dynamic parameters in C#?)

擴展 SSRS 中的圖表功能 (Extending chart functionality in SSRS)

如何將 MVC 5 項目模板添加到 VS 2012? (How can I add the MVC 5 project template to VS 2012?)

Visual Studio - 將按鈕/複選框添加到工具欄以切換只讀文件屬性, (Visual Studio - Add a button/checkbox to a toolbar to switch the readonly file property,)

在 Javascript/Jquery Ajax 調用中使用 WCF 服務 (Consuming WCF service in Javascript/Jquery Ajax call)

Visual Basic 2013 - 控制台輸入令牌? (Visual Basic 2013 - Console Input Tokens?)

您是否知道用於編輯/翻譯資源(.rc)文件的好的程序? (Do you know of a good program for editing/translating resource (.rc) files?)

ADODB.Recordset 數據無法綁定到 datagridview (ADODB.Recordset data cannot bind into datagridview)

Reporting Services - 對數據源視圖 (DSV) 的報表模型 (SDML) 引用 (Reporting Services - Report Model (SDML) reference to Data Source View (DSV))

從 Visual Studio 2005 遷移到 2008 時要注意什麼? (What to look out for when moving from Visual Studio 2005 to 2008?)

動態改變另一個類的標籤值 (Dynamically changing the value of a label from another class)

在同一文件夾中為 .NET 5 和 .NET 6 Preview 3 構建 WebAssembly 項目 (Building WebAssembly project for both .NET 5 and .NET 6 Preview 3 in same folder)







留言討論