問題描述
飛地字段不工作,但沒有錯誤 (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.
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. */ }; };
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
IF state grammar is wrong. it should be
if (*ptr == 1) *ptr = 43971;
(by user10865941、user10865941)