[hyper mode] Support ms buffer for pal
This commit is contained in:
parent
bec8aa1c38
commit
0b7b384241
@ -9,6 +9,9 @@
|
||||
#include "pal_syscall.h"
|
||||
#include "pal_thread_counter.h"
|
||||
#include "pal_check_fsgsbase.h"
|
||||
#ifdef SGX_MODE_HYPER
|
||||
#include "pal_ms_buffer.h"
|
||||
#endif
|
||||
#include "errno2str.h"
|
||||
#include <linux/limits.h>
|
||||
|
||||
@ -153,8 +156,26 @@ int occlum_pal_create_process(struct occlum_pal_create_process_args *args) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifndef SGX_MODE_HYPER
|
||||
sgx_status_t ecall_status = occlum_ecall_new_process(eid, &ecall_ret, args->path,
|
||||
args->argv, args->env, args->stdio);
|
||||
#else
|
||||
const char **ms_buffer_argv = ms_buffer_convert_string_array(eid, args->argv);
|
||||
const char **ms_buffer_env = ms_buffer_convert_string_array(eid, args->env);
|
||||
if ((!args->argv != !ms_buffer_argv) || (!args->env != !ms_buffer_env)) {
|
||||
PAL_ERROR("Marshal buffer size is not enough");
|
||||
return -1;
|
||||
}
|
||||
sgx_status_t ecall_status = occlum_ecall_new_process(
|
||||
eid,
|
||||
&ecall_ret,
|
||||
args->path,
|
||||
ms_buffer_argv,
|
||||
ms_buffer_env,
|
||||
args->stdio);
|
||||
ms_buffer_string_array_free(eid, ms_buffer_argv);
|
||||
ms_buffer_string_array_free(eid, ms_buffer_env);
|
||||
#endif
|
||||
if (ecall_status != SGX_SUCCESS) {
|
||||
const char *sgx_err = pal_get_sgx_error_msg(ecall_status);
|
||||
PAL_ERROR("Failed to do ECall with error code 0x%x: %s", ecall_status, sgx_err);
|
||||
|
68
src/pal/src/pal_ms_buffer.c
Normal file
68
src/pal/src/pal_ms_buffer.c
Normal file
@ -0,0 +1,68 @@
|
||||
#ifdef SGX_MODE_HYPER
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sgx_eid.h>
|
||||
|
||||
#include "Enclave_u.h"
|
||||
#include "pal_ms_buffer.h"
|
||||
|
||||
void ms_buffer_string_array_free(sgx_enclave_id_t eid, const char **str_array) {
|
||||
if (!str_array) {
|
||||
return;
|
||||
}
|
||||
|
||||
const char *string = *str_array;
|
||||
int array_size = 0;
|
||||
|
||||
while (string) {
|
||||
sgx_ecall_ms_buffer_free(eid);
|
||||
array_size++;
|
||||
string = str_array[array_size];
|
||||
}
|
||||
sgx_ecall_ms_buffer_free(eid);
|
||||
}
|
||||
|
||||
const char **ms_buffer_convert_string_array(sgx_enclave_id_t eid,
|
||||
const char **str_array) {
|
||||
if (str_array == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int string_len = 0;
|
||||
const char *string = *str_array;
|
||||
int array_size = 0;
|
||||
|
||||
while (string) {
|
||||
array_size++;
|
||||
string = str_array[array_size];
|
||||
}
|
||||
|
||||
const char **ms_buf_str_array = (const char **)sgx_ecall_ms_buffer_alloc(eid,
|
||||
sizeof(char *) * (array_size + 1));
|
||||
|
||||
if (!ms_buf_str_array) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (int i = 0; i < array_size; ++i) {
|
||||
ms_buf_str_array[i] = NULL;
|
||||
string = str_array[i];
|
||||
string_len = strlen(string);
|
||||
|
||||
char *ms_parameter = (char *)sgx_ecall_ms_buffer_alloc(eid, string_len + 1);
|
||||
|
||||
if (!ms_parameter) {
|
||||
ms_buffer_string_array_free(eid, ms_buf_str_array);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memcpy(ms_parameter, string, string_len);
|
||||
ms_parameter[string_len] = 0;
|
||||
|
||||
ms_buf_str_array[i] = ms_parameter;
|
||||
}
|
||||
|
||||
ms_buf_str_array[array_size] = NULL;
|
||||
return ms_buf_str_array;
|
||||
}
|
||||
#endif //SGX_MODE_HYPER
|
11
src/pal/src/pal_ms_buffer.h
Normal file
11
src/pal/src/pal_ms_buffer.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef __PAL_MS_BUFFER_H__
|
||||
#define __PAL_MS_BUFFER_H__
|
||||
|
||||
#ifdef SGX_MODE_HYPER
|
||||
#include <sgx_eid.h>
|
||||
|
||||
const char **ms_buffer_convert_string_array(sgx_enclave_id_t eid, const char **str_array);
|
||||
void ms_buffer_string_array_free(sgx_enclave_id_t eid, const char **str_array);
|
||||
#endif
|
||||
|
||||
#endif /* __PAL_MS_BUFFER_H__ */
|
Loading…
Reference in New Issue
Block a user