提交 97699bdc 编写于 作者: jia zhang's avatar jia zhang

rune/libenclave/skeleton: Support fork-test argument

This argument is used to test whether enclave share mapping between
parent and child process is usable.
Signed-off-by: jia zhang's avatarJia Zhang <zhang.jia@linux.alibaba.com>
上级 c007aaa2
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#else #else
#include <sys/sysmacros.h> #include <sys/sysmacros.h>
#endif #endif
#include <sys/wait.h>
#include "defines.h" #include "defines.h"
#include "sgx_call.h" #include "sgx_call.h"
...@@ -36,11 +37,13 @@ static bool initialized = false; ...@@ -36,11 +37,13 @@ static bool initialized = false;
static char *sgx_dev_path; static char *sgx_dev_path;
static bool is_oot_driver; static bool is_oot_driver;
static bool no_sgx_flc = false; static bool no_sgx_flc = false;
static bool fork_test = false;
/* /*
* For SGX in-tree driver, dev_fd cannot be closed until an enclave instance * For SGX in-tree driver, dev_fd cannot be closed until an enclave instance
* intends to exit. * intends to exit.
*/ */
static int enclave_fd = -1; static int enclave_fd = -1;
void *tcs_busy;
static bool is_sgx_device(const char *dev) static bool is_sgx_device(const char *dev)
{ {
...@@ -368,6 +371,8 @@ static void check_opts(const char *opt) ...@@ -368,6 +371,8 @@ static void check_opts(const char *opt)
{ {
if (!strcmp(opt, "no-sgx-flc")) if (!strcmp(opt, "no-sgx-flc"))
no_sgx_flc = true; no_sgx_flc = true;
else if (!strcmp(opt, "fork-test"))
fork_test = true;
} }
static void parse_args(const char *args) static void parse_args(const char *args)
...@@ -416,6 +421,12 @@ int pal_init(pal_attr_t *attr) ...@@ -416,6 +421,12 @@ int pal_init(pal_attr_t *attr)
detect_driver_type(); detect_driver_type();
tcs_busy = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
if (tcs_busy == MAP_FAILED)
return -EINVAL;
*(uint8_t *)tcs_busy = 0;
if (!encl_data_map(IMAGE, &bin, &bin_size)) if (!encl_data_map(IMAGE, &bin, &bin_size))
return -ENOENT; return -ENOENT;
...@@ -450,6 +461,25 @@ int pal_exec(char *path, char *argv[], pal_stdio_fds *stdio, ...@@ -450,6 +461,25 @@ int pal_exec(char *path, char *argv[], pal_stdio_fds *stdio,
return -1; return -1;
} }
bool is_child = false;
if (fork_test) {
switch (fork()) {
case -1:
fprintf(fp, "fork(), errno = %d\n", errno);
fclose(fp);
return -1;
case 0:
fprintf(fp, "run in child process, pid = %d\n", (int)getpid());
is_child = true;
break;
default:
wait(NULL);
fprintf(fp, "run in parent process, pid = %d\n", (int)getpid());
break;
}
}
uint64_t result = 0; uint64_t result = 0;
int ret = SGX_ENTER_1_ARG(ECALL_MAGIC, (void *)secs.base, &result); int ret = SGX_ENTER_1_ARG(ECALL_MAGIC, (void *)secs.base, &result);
if (ret) { if (ret) {
...@@ -466,6 +496,9 @@ int pal_exec(char *path, char *argv[], pal_stdio_fds *stdio, ...@@ -466,6 +496,9 @@ int pal_exec(char *path, char *argv[], pal_stdio_fds *stdio,
fprintf(fp, "Enclave runtime skeleton initialization succeeded\n"); fprintf(fp, "Enclave runtime skeleton initialization succeeded\n");
fclose(fp); fclose(fp);
if (fork_test && is_child)
exit(0);
*exit_code = 0; *exit_code = 0;
return 0; return 0;
......
...@@ -14,7 +14,12 @@ ...@@ -14,7 +14,12 @@
.global sgx_ecall .global sgx_ecall
.type sgx_ecall, @function .type sgx_ecall, @function
sgx_ecall: sgx_ecall:
mov $1, %rax
push %rbx push %rbx
mov tcs_busy(%rip), %rbx
xchgb (%rbx), %al
cmpb $1, %al
jz busy_err
push %rbp push %rbp
push %rdi push %rdi
push %rsi push %rsi
...@@ -33,6 +38,9 @@ sgx_ecall: ...@@ -33,6 +38,9 @@ sgx_ecall:
lea sgx_async_exit(%rip), %rcx lea sgx_async_exit(%rip), %rcx
sgx_async_exit: sgx_async_exit:
ENCLU ENCLU
xor %rax, %rax
mov tcs_busy(%rip), %rbx
movb %al, (%rbx)
# Return value is saved in RAX. # Return value is saved in RAX.
mov %rdx, %rax mov %rdx, %rax
pop %r15 pop %r15
...@@ -42,5 +50,6 @@ sgx_async_exit: ...@@ -42,5 +50,6 @@ sgx_async_exit:
pop %rsi pop %rsi
pop %rdi pop %rdi
pop %rbp pop %rbp
busy_err:
pop %rbx pop %rbx
ret ret
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册