38 Star 90 Fork 103

openEuler/secGear

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.c 25.45 KB
一键复制 编辑 原始数据 按行查看 历史
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
* secGear is licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
*/
#include <stdio.h>
#include <unistd.h>
#include <stdbool.h>
#include <linux/limits.h>
#include "enclave.h"
#include "switchless_u.h"
#include "string.h"
#include "secgear_uswitchless.h"
#include "secgear_shared_memory.h"
#include <sys/time.h>
cc_enclave_t g_enclave;
bool init_enclave(enclave_features_t *features)
{
char *path = PATH;
cc_enclave_result_t ret;
char real_p[PATH_MAX];
/* check file exists, if not exist then use absolute path */
if (realpath(path, real_p) == NULL) {
if (getcwd(real_p, sizeof(real_p)) == NULL) {
printf("Cannot find enclave.sign.so");
return false;
}
if (PATH_MAX - strlen(real_p) <= strlen("/enclave.signed.so")) {
printf("Failed to strcat enclave.sign.so path");
return false;
}
(void)strcat(real_p, "/enclave.signed.so");
}
ret = cc_enclave_create(real_p, AUTO_ENCLAVE_TYPE, 0, SECGEAR_DEBUG_FLAG, features, 1, &g_enclave);
if (ret != CC_SUCCESS) {
printf("Create enclave error: %d\n", ret);
return false;
}
return true;
}
void fini_enclave(cc_enclave_t *enclave)
{
cc_enclave_result_t ret = cc_enclave_destroy(enclave);
if (ret != CC_SUCCESS) {
printf("Error: destroy enclave failed: %x\n", ret);
}
}
void benchmark_ecall_empty(bool is_switchless, unsigned long nrepeats)
{
struct timeval tval_before;
struct timeval tval_after;
struct timeval duration;
cc_enclave_result_t(*ecall_fn)(cc_enclave_t *) = is_switchless ? ecall_empty_switchless : ecall_empty;
gettimeofday(&tval_before, NULL);
unsigned long tmp_nrepeats = nrepeats;
while (tmp_nrepeats--) {
ecall_fn(&g_enclave);
}
gettimeofday(&tval_after, NULL);
timersub(&tval_after, &tval_before, &duration);
printf("Repeating an %s empty ecall for %lu times takes %ld.%06lds\n",
is_switchless ? "[switchless]" : "[ ordinary ]", nrepeats, (long)duration.tv_sec, (long)duration.tv_usec);
}
/* ecall_empty_switchless */
void benchmark_ecall_empty_sl_async(unsigned long nrepeats)
{
cc_enclave_result_t ret_code;
cc_enclave_result_t ret;
struct timeval tval_before;
struct timeval tval_after;
struct timeval duration;
int processed_cursor = 0;
int retry_count = 0;
int *arr = (int *)calloc(nrepeats, sizeof(int));
if (arr == NULL) {
return;
}
// BEGIN
gettimeofday(&tval_before, NULL);
for (int i = 0; i < nrepeats; ++i) {
ret_code = ecall_empty_switchless_async(&g_enclave, &arr[i]);
if (ret_code != CC_SUCCESS) {
if (ret_code == CC_ERROR_SWITCHLESS_TASK_POOL_FULL) {
// The task pool is full. You should try again later.
--i;
++retry_count;
} else {
// Asynchronous invocation failed
printf("Asynchronous invocation failed, ret=%x\n", ret_code);
}
}
ret = cc_sl_get_async_result(&g_enclave, arr[processed_cursor], NULL);
if (ret == CC_ERROR_SWITCHLESS_ASYNC_TASK_UNFINISHED) {
// Invoking processing
} else if (ret == CC_SUCCESS) {
// Obtaining the result succeeded
processed_cursor++;
} else {
// Failed to obtain the result
processed_cursor++;
}
}
while (processed_cursor < nrepeats) {
ret = cc_sl_get_async_result(&g_enclave, arr[processed_cursor], NULL);
if (ret == CC_ERROR_SWITCHLESS_ASYNC_TASK_UNFINISHED) {
// Invoking processing
continue;
} else if (ret == CC_SUCCESS) {
// Obtaining the result succeeded
processed_cursor++;
} else {
// Failed to obtain the result
processed_cursor++;
}
}
// END
gettimeofday(&tval_after, NULL);
timersub(&tval_after, &tval_before, &duration);
free(arr);
printf("retry_count:%d, processed_cursor:%d\n", retry_count, processed_cursor);
printf("Repeating an empty sl async ecall for %lu times takes %ld.%06lds\n", nrepeats,
(long int)duration.tv_sec, (long int)duration.tv_usec);
}
void benchmark_ecall_empty_sl_async_rollback(unsigned long nrepeats)
{
cc_enclave_result_t ret_code;
cc_enclave_result_t ret;
struct timeval tval_before;
struct timeval tval_after;
struct timeval duration;
int processed_cursor = 0;
int rollback_count = 0;
unsigned long tmp_nrepeats = nrepeats;
int *arr = (int *)calloc(nrepeats, sizeof(int));
if (arr == NULL) {
return;
}
// BEGIN
gettimeofday(&tval_before, NULL);
for (int i = 0; i < tmp_nrepeats; ++i) {
ret_code = ecall_empty_switchless_async(&g_enclave, &arr[i]);
if (ret_code == CC_SUCCESS) {
if (arr[i] == -1) {
// rollback to common invoking when asynchronous switchless fails, and the common call is successful now
--i;
--tmp_nrepeats;
rollback_count++;
}
} else {
// Asynchronous invocation failed
printf("Asynchronous invocation failed, ret=%x\n", ret_code);
}
ret = cc_sl_get_async_result(&g_enclave, arr[processed_cursor], NULL);
if (ret == CC_ERROR_SWITCHLESS_ASYNC_TASK_UNFINISHED) {
// Invoking processing
} else if (ret == CC_SUCCESS) {
// Obtaining the result succeeded
processed_cursor++;
} else {
// Failed to obtain the result
processed_cursor++;
}
}
while (processed_cursor < tmp_nrepeats) {
ret = cc_sl_get_async_result(&g_enclave, arr[processed_cursor], NULL);
if (ret == CC_ERROR_SWITCHLESS_ASYNC_TASK_UNFINISHED) {
// Invoking processing
continue;
} else if (ret == CC_SUCCESS) {
// Obtaining the result succeeded
processed_cursor++;
} else {
// Failed to obtain the result
processed_cursor++;
}
}
// END
gettimeofday(&tval_after, NULL);
timersub(&tval_after, &tval_before, &duration);
free(arr);
printf("rollback_count:%d, processed_cursor:%d\n", rollback_count, processed_cursor);
printf("Repeating an empty sl async ecall rollback for %lu times takes %ld.%06lds\n", nrepeats,
(long int)duration.tv_sec, (long int)duration.tv_usec);
}
/* ecall_empty_switchless1 */
void benchmark_ecall_empty_sl_async1(unsigned long nrepeats)
{
cc_enclave_result_t ret_code;
cc_enclave_result_t ret;
struct timeval tval_before;
struct timeval tval_after;
struct timeval duration;
int processed_cursor = 0;
int retry_count = 0;
int one_share_buf_len = 32;
int retval;
int *arr = (int *)calloc(nrepeats, sizeof(int));
if (arr == NULL) {
return;
}
char *sharebuf = (char *)cc_malloc_shared_memory(&g_enclave, nrepeats * one_share_buf_len);
if (sharebuf == NULL) {
free(arr);
printf("Error: malloc shared memory failed.\n");
return;
}
// BEGIN
gettimeofday(&tval_before, NULL);
for (int i = 0; i < nrepeats; ++i) {
strcpy(sharebuf + i * one_share_buf_len, "aAbBcCdD");
ret_code = ecall_empty_switchless1_async(&g_enclave, &arr[i], NULL, sharebuf + i * one_share_buf_len,
sizeof("aAbBcCdD"));
if (ret_code != CC_SUCCESS) {
if (ret_code == CC_ERROR_SWITCHLESS_TASK_POOL_FULL) {
// The task pool is full. You should try again later.
--i;
++retry_count;
} else {
// Asynchronous invocation failed
printf("Asynchronous invocation failed, ret=%x\n", ret_code);
}
}
ret = cc_sl_get_async_result(&g_enclave, arr[processed_cursor], &retval);
if (ret == CC_ERROR_SWITCHLESS_ASYNC_TASK_UNFINISHED) {
// Invoking processing
} else if (ret == CC_SUCCESS) {
// Obtaining the result succeeded, and check the execution result.
if (retval != 1) {
printf("get result retval err:%d, index:%d\n", retval, processed_cursor);
}
if (strcmp("AABBCCDD", sharebuf + processed_cursor * one_share_buf_len)) {
printf("get result buffer err:%s, index:%d\n", sharebuf + processed_cursor * one_share_buf_len,
processed_cursor);
}
processed_cursor++;
} else {
// Failed to obtain the result
processed_cursor++;
}
}
while (processed_cursor < nrepeats) {
ret = cc_sl_get_async_result(&g_enclave, arr[processed_cursor], &retval);
if (ret == CC_ERROR_SWITCHLESS_ASYNC_TASK_UNFINISHED) {
// Invoking processing
continue;
} else if (ret == CC_SUCCESS) {
// Obtaining the result succeeded, and check the execution result.
if (retval != 1) {
printf("get result retval err:%d, index:%d\n", retval, processed_cursor);
}
if (strcmp("AABBCCDD", sharebuf + processed_cursor * one_share_buf_len)) {
printf("get result buffer err:%s, index:%d\n", sharebuf + processed_cursor * one_share_buf_len,
processed_cursor);
}
processed_cursor++;
} else {
// Failed to obtain the result
processed_cursor++;
}
}
// END
gettimeofday(&tval_after, NULL);
timersub(&tval_after, &tval_before, &duration);
free(arr);
ret = cc_free_shared_memory(&g_enclave, sharebuf);
if (ret != CC_SUCCESS) {
printf("Error: free shared memory failed:%x.\n", ret);
}
printf("retry_count:%d, processed_cursor:%d\n", retry_count, processed_cursor);
printf("Repeating an empty sl async ecall [1] for %lu times takes %ld.%06lds\n", nrepeats,
(long int)duration.tv_sec, (long int)duration.tv_usec);
}
void benchmark_ecall_empty_sl_async_rollback1(unsigned long nrepeats)
{
cc_enclave_result_t ret_code;
cc_enclave_result_t ret;
struct timeval tval_before;
struct timeval tval_after;
struct timeval duration;
int processed_cursor = 0;
int one_share_buf_len = 32;
int rollback_count = 0;
int retval;
unsigned long tmp_nrepeats = nrepeats;
int *arr = (int *)calloc(nrepeats, sizeof(int));
if (arr == NULL) {
return;
}
char *sharebuf = (char *)cc_malloc_shared_memory(&g_enclave, nrepeats * one_share_buf_len);
if (sharebuf == NULL) {
free(arr);
printf("Error: malloc shared memory failed.\n");
return;
}
// BEGIN
gettimeofday(&tval_before, NULL);
for (int i = 0; i < tmp_nrepeats; ++i) {
strcpy(sharebuf + i * one_share_buf_len, "aAbBcCdD");
ret_code = ecall_empty_switchless1_async(&g_enclave, &arr[i], &retval, sharebuf + i * one_share_buf_len,
sizeof("aAbBcCdD"));
if (ret_code == CC_SUCCESS) {
if (arr[i] == -1) {
/*
* rollback to common invoking when asynchronous switchless fails, and the common call
* is successful now, check the execution result.
*/
if (retval != 1) {
printf("get result retval err:%d, index:%d\n", retval, i);
}
if (strcmp("AABBCCDD", sharebuf + i * one_share_buf_len)) {
printf("get result buffer err:%s, index:%d\n", sharebuf + i * one_share_buf_len, i);
}
--i;
--tmp_nrepeats;
rollback_count++;
}
} else {
// Asynchronous invocation failed
printf("Asynchronous invocation failed, ret=%x\n", ret_code);
}
ret = cc_sl_get_async_result(&g_enclave, arr[processed_cursor], &retval);
if (ret == CC_ERROR_SWITCHLESS_ASYNC_TASK_UNFINISHED) {
// Invoking processing
} else if (ret == CC_SUCCESS) {
// Obtaining the result succeeded, check the execution result.
if (retval != 1) {
printf("get result retval err:%d, index:%d\n", retval, processed_cursor);
}
if (strcmp("AABBCCDD", sharebuf + processed_cursor * one_share_buf_len)) {
printf("get result buffer err:%s, index:%d\n", sharebuf + processed_cursor * one_share_buf_len,
processed_cursor);
}
processed_cursor++;
} else {
// Failed to obtain the result
processed_cursor++;
}
}
while (processed_cursor < tmp_nrepeats) {
ret = cc_sl_get_async_result(&g_enclave, arr[processed_cursor], &retval);
if (ret == CC_ERROR_SWITCHLESS_ASYNC_TASK_UNFINISHED) {
// Invoking processing
continue;
} else if (ret == CC_SUCCESS) {
// Obtaining the result succeeded, check the execution result.
if (retval != 1) {
printf("get result retval err:%d, index:%d\n", retval, processed_cursor);
}
if (strcmp("AABBCCDD", sharebuf + processed_cursor * one_share_buf_len)) {
printf("get result buffer err:%s, index:%d\n", sharebuf + processed_cursor * one_share_buf_len,
processed_cursor);
}
processed_cursor++;
} else {
// Failed to obtain the result
processed_cursor++;
}
}
// END
gettimeofday(&tval_after, NULL);
timersub(&tval_after, &tval_before, &duration);
free(arr);
ret = cc_free_shared_memory(&g_enclave, sharebuf);
if (ret != CC_SUCCESS) {
printf("Error: free shared memory failed:%x.\n", ret);
}
printf("rollback_count:%d, processed_cursor:%d\n", rollback_count, processed_cursor);
printf("Repeating an empty sl async ecall rollback [1] for %lu times takes %ld.%06lds\n", nrepeats,
(long int)duration.tv_sec, (long int)duration.tv_usec);
}
/* ecall_empty_switchless2 */
void benchmark_ecall_empty_sl_async2(unsigned long nrepeats)
{
cc_enclave_result_t ret_code;
cc_enclave_result_t ret;
struct timeval tval_before;
struct timeval tval_after;
struct timeval duration;
int processed_cursor = 0;
int retry_count = 0;
int one_share_buf_len = 32;
int half_one_share_buf_len = 16;
int retval;
int *arr = (int *)calloc(nrepeats, sizeof(int));
if (arr == NULL) {
return;
}
char *sharebuf = (char *)cc_malloc_shared_memory(&g_enclave, nrepeats * one_share_buf_len);
if (sharebuf == NULL) {
free(arr);
printf("Error: malloc shared memory failed.\n");
return;
}
memset(sharebuf, 0, nrepeats * one_share_buf_len);
// BEGIN
gettimeofday(&tval_before, NULL);
for (int i = 0; i < nrepeats; ++i) {
strcpy(sharebuf + i * one_share_buf_len, "aAbBcCdD");
ret_code = ecall_empty_switchless2_async(&g_enclave, &arr[i], NULL, sharebuf + i * one_share_buf_len,
sizeof("aAbBcCdD"), sharebuf + i * one_share_buf_len + half_one_share_buf_len, sizeof("aAbBcCdD"));
if (ret_code != CC_SUCCESS) {
if (ret_code == CC_ERROR_SWITCHLESS_TASK_POOL_FULL) {
// The task pool is full. You should try again later.
--i;
++retry_count;
} else {
// Asynchronous invocation failed
printf("Asynchronous invocation failed, ret=%x\n", ret_code);
}
}
ret = cc_sl_get_async_result(&g_enclave, arr[processed_cursor], &retval);
if (ret == CC_ERROR_SWITCHLESS_ASYNC_TASK_UNFINISHED) {
// Invoking processing
} else if (ret == CC_SUCCESS) {
// Obtaining the result succeeded, check the execution result.
if (retval != 2) {
printf("get result retval err:%d, index:%d\n", retval, processed_cursor);
}
if (strcmp("AABBCCDD", sharebuf + processed_cursor * one_share_buf_len + half_one_share_buf_len)) {
printf("get result buffer err:%s, index:%d\n",
sharebuf + processed_cursor * one_share_buf_len + half_one_share_buf_len, processed_cursor);
}
processed_cursor++;
} else {
// Failed to obtain the result
processed_cursor++;
}
}
while (processed_cursor < nrepeats) {
ret = cc_sl_get_async_result(&g_enclave, arr[processed_cursor], &retval);
if (ret == CC_ERROR_SWITCHLESS_ASYNC_TASK_UNFINISHED) {
// Invoking processing
continue;
} else if (ret == CC_SUCCESS) {
// Obtaining the result succeeded, check the execution result.
if (retval != 2) {
printf("get result retval err:%d, index:%d\n", retval, processed_cursor);
}
if (strcmp("AABBCCDD", sharebuf + processed_cursor * one_share_buf_len + half_one_share_buf_len)) {
printf("get result buffer err:%s, index:%d\n",
sharebuf + processed_cursor * one_share_buf_len + half_one_share_buf_len, processed_cursor);
}
processed_cursor++;
} else {
// Failed to obtain the result
processed_cursor++;
}
}
// END
gettimeofday(&tval_after, NULL);
timersub(&tval_after, &tval_before, &duration);
free(arr);
ret = cc_free_shared_memory(&g_enclave, sharebuf);
if (ret != CC_SUCCESS) {
printf("Error: free shared memory failed:%x.\n", ret);
}
printf("retry_count:%d, processed_cursor:%d\n", retry_count, processed_cursor);
printf("Repeating an empty sl async ecall [2] for %lu times takes %ld.%06lds\n", nrepeats,
(long int)duration.tv_sec, (long int)duration.tv_usec);
}
void benchmark_ecall_empty_sl_async_rollback2(unsigned long nrepeats)
{
cc_enclave_result_t ret_code;
cc_enclave_result_t ret;
struct timeval tval_before;
struct timeval tval_after;
struct timeval duration;
int processed_cursor = 0;
int one_share_buf_len = 32;
int half_one_share_buf_len = 16;
int rollback_count = 0;
int retval;
unsigned long tmp_nrepeats = nrepeats;
int *arr = (int *)calloc(nrepeats, sizeof(int));
if (arr == NULL) {
return;
}
char *sharebuf = (char *)cc_malloc_shared_memory(&g_enclave, nrepeats * one_share_buf_len);
if (sharebuf == NULL) {
free(arr);
printf("Error: malloc shared memory failed.\n");
return;
}
// BEGIN
gettimeofday(&tval_before, NULL);
for (int i = 0; i < tmp_nrepeats; ++i) {
strcpy(sharebuf + i * one_share_buf_len, "aAbBcCdD");
ret_code = ecall_empty_switchless2_async(&g_enclave, &arr[i], &retval, sharebuf + i * one_share_buf_len,
sizeof("aAbBcCdD"), sharebuf + i * one_share_buf_len + half_one_share_buf_len, sizeof("aAbBcCdD"));
if (ret_code == CC_SUCCESS) {
if (arr[i] == -1) {
/*
* rollback to common invoking when asynchronous switchless fails, and the common call
* is successful now, check the execution result.
*/
if (retval != 2) {
printf("get result retval err:%d, index:%d\n", retval, i);
}
if (strcmp("AABBCCDD", sharebuf + i * one_share_buf_len + half_one_share_buf_len)) {
printf("get result buffer err:%s, index:%d\n",
sharebuf + i * one_share_buf_len + half_one_share_buf_len, i);
}
--i;
--tmp_nrepeats;
rollback_count++;
}
} else {
// Asynchronous invocation failed
printf("Asynchronous invocation failed, ret=%x\n", ret_code);
}
ret = cc_sl_get_async_result(&g_enclave, arr[processed_cursor], &retval);
if (ret == CC_ERROR_SWITCHLESS_ASYNC_TASK_UNFINISHED) {
// Invoking processing
} else if (ret == CC_SUCCESS) {
// Obtaining the result succeeded, check the execution result.
if (retval != 2) {
printf("get result retval err:%d, index:%d\n", retval, processed_cursor);
}
if (strcmp("AABBCCDD", sharebuf + processed_cursor * one_share_buf_len + half_one_share_buf_len)) {
printf("get result buffer err:%s, index:%d\n",
sharebuf + processed_cursor * one_share_buf_len + half_one_share_buf_len, processed_cursor);
}
processed_cursor++;
} else {
// Failed to obtain the result
processed_cursor++;
}
}
while (processed_cursor < tmp_nrepeats) {
ret = cc_sl_get_async_result(&g_enclave, arr[processed_cursor], &retval);
if (ret == CC_ERROR_SWITCHLESS_ASYNC_TASK_UNFINISHED) {
// Invoking processing
continue;
} else if (ret == CC_SUCCESS) {
// Obtaining the result succeeded, check the execution result.
if (retval != 2) {
printf("get result retval err:%d, index:%d\n", retval, processed_cursor);
}
if (strcmp("AABBCCDD", sharebuf + processed_cursor * one_share_buf_len + half_one_share_buf_len)) {
printf("get result buffer err:%s, index:%d\n",
sharebuf + processed_cursor * one_share_buf_len + half_one_share_buf_len, processed_cursor);
}
processed_cursor++;
} else {
// Failed to obtain the result
processed_cursor++;
}
}
// END
gettimeofday(&tval_after, NULL);
timersub(&tval_after, &tval_before, &duration);
free(arr);
ret = cc_free_shared_memory(&g_enclave, sharebuf);
if (ret != CC_SUCCESS) {
printf("Error: free shared memory failed:%x.\n", ret);
}
printf("rollback_count:%d, processed_cursor:%d\n", rollback_count, processed_cursor);
printf("Repeating an empty sl async ecall rollback [2] for %lu times takes %ld.%06lds\n", nrepeats,
(long int)duration.tv_sec, (long int)duration.tv_usec);
}
#define TEST_STR "switchless"
void transfer_data_using_shared_memory()
{
cc_enclave_result_t ret;
int len = 32;
char *buf = (char *)cc_malloc_shared_memory(&g_enclave, len);
if (buf == NULL) {
printf("Error: malloc shared memory failed.\n");
return;
}
(void)strcpy(buf, TEST_STR);
printf("before test_toupper, buf=%s\n", buf);
test_toupper(&g_enclave, buf, strlen(TEST_STR));
printf("after test_toupper, buf=%s\n\n", buf);
ret = cc_free_shared_memory(&g_enclave, buf);
if (ret != CC_SUCCESS) {
printf("Error: free shared memory failed:%x.\n", ret);
}
}
void onetime_normal(void)
{
cc_enclave_result_t ret;
int retval;
char buf[] = "aAbBcCdD";
ret = ecall_empty1(&g_enclave, &retval, buf, sizeof(buf));
if (ret != CC_SUCCESS) {
printf("Error: ecall_empty1, ret:%x.\n", ret);
return;
}
printf("buf:%s, retval:%d\n", buf, retval);
char buf1[] = "aAbBcCdD";
char buf2[32] = {0};
ret = ecall_empty2(&g_enclave, &retval, buf1, sizeof(buf1), buf2, sizeof(buf1) - 3);
if (ret != CC_SUCCESS) {
printf("Error: ecall_empty2, ret:%x.\n", ret);
return;
}
printf("buf2:%s, retval:%d\n", buf2, retval);
}
int main(void)
{
cc_sl_config_t sl_cfg = CC_USWITCHLESS_CONFIG_INITIALIZER;
sl_cfg.num_tworkers = 2; /* 2 tworkers */
sl_cfg.sl_call_pool_size_qwords = 8; /* 2 * 64 tasks */
sl_cfg.rollback_to_common = false;
enclave_features_t features = {ENCLAVE_FEATURE_SWITCHLESS, (void *)&sl_cfg};
if (!init_enclave(&features)) {
printf("Error: init enclave failed\n");
return -1;
}
printf("\n1. Running a benchmark that compares [ordinary] and [switchless] ecall\n");
unsigned long nrepeats = 10000;
benchmark_ecall_empty(false, nrepeats);
benchmark_ecall_empty(true, nrepeats);
benchmark_ecall_empty_sl_async(nrepeats);
benchmark_ecall_empty_sl_async1(nrepeats);
benchmark_ecall_empty_sl_async2(nrepeats);
printf("\n2. Transfer data using shared memory\n");
transfer_data_using_shared_memory();
printf("\n3. normal ecall\n");
onetime_normal();
fini_enclave(&g_enclave);
#if 1
printf("\n=================================================\n");
sl_cfg.rollback_to_common = true;
if (!init_enclave(&features)) {
printf("Error: init enclave failed\n");
return -1;
}
printf("\n1. Running a benchmark that compares [ordinary] and [switchless] ecall\n");
benchmark_ecall_empty(false, nrepeats);
benchmark_ecall_empty(true, nrepeats);
benchmark_ecall_empty_sl_async_rollback(nrepeats);
benchmark_ecall_empty_sl_async_rollback1(nrepeats);
benchmark_ecall_empty_sl_async_rollback2(nrepeats);
printf("\n2. Transfer data using shared memory\n");
transfer_data_using_shared_memory();
printf("\n3. normal ecall\n");
onetime_normal();
fini_enclave(&g_enclave);
#endif
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/openeuler/secGear.git
git@gitee.com:openeuler/secGear.git
openeuler
secGear
secGear
master

搜索帮助