[hyper mode] Support ms buffer for deep copy hostfile
This commit is contained in:
parent
036eb08193
commit
0182c097dd
@ -167,8 +167,6 @@ int occlum_pal_kill(int pid, int sig);
|
||||
*/
|
||||
int occlum_pal_destroy(void);
|
||||
|
||||
void free_host_file_buffer_t(struct host_file_buffer_t file_buffer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -112,9 +112,9 @@ int occlum_pal_init(const struct occlum_pal_attr *attr) {
|
||||
load_file_t hosts_ptr = {0, NULL};
|
||||
load_file_t resolv_conf_ptr = {0, NULL};
|
||||
|
||||
pal_load_file("/etc/hostname", &hostname_ptr);
|
||||
pal_load_file("/etc/hosts", &hosts_ptr);
|
||||
pal_load_file("/etc/resolv.conf", &resolv_conf_ptr);
|
||||
pal_load_file(eid, "/etc/hostname", &hostname_ptr);
|
||||
pal_load_file(eid, "/etc/hosts", &hosts_ptr);
|
||||
pal_load_file(eid, "/etc/resolv.conf", &resolv_conf_ptr);
|
||||
|
||||
struct host_file_buffer_t file_buffer = {
|
||||
.hostname_buf = hostname_ptr.buffer,
|
||||
@ -125,15 +125,10 @@ int occlum_pal_init(const struct occlum_pal_attr *attr) {
|
||||
.resolv_conf_buf_size = resolv_conf_ptr.size,
|
||||
};
|
||||
|
||||
const struct host_file_buffer_t *file_buffer_ptr = &file_buffer;
|
||||
|
||||
sgx_status_t ecall_status = occlum_ecall_init(eid, &ecall_ret, attr->log_level,
|
||||
resolved_path, file_buffer_ptr);
|
||||
resolved_path, &file_buffer);
|
||||
|
||||
free_host_file_buffer_t(file_buffer);
|
||||
hostname_ptr.buffer = NULL;
|
||||
hosts_ptr.buffer = NULL;
|
||||
resolv_conf_ptr.buffer = NULL;
|
||||
free_host_file_buffer(eid, &file_buffer);
|
||||
|
||||
if (ecall_status != SGX_SUCCESS) {
|
||||
const char *sgx_err = pal_get_sgx_error_msg(ecall_status);
|
||||
@ -295,17 +290,6 @@ int occlum_pal_destroy(void) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
void free_host_file_buffer_t(struct host_file_buffer_t file_buffer) {
|
||||
free((void *)file_buffer.hostname_buf);
|
||||
file_buffer.hostname_buf = NULL;
|
||||
|
||||
free((void *)file_buffer.hosts_buf);
|
||||
file_buffer.hosts_buf = NULL;
|
||||
|
||||
free((void *)file_buffer.resolv_conf_buf);
|
||||
file_buffer.resolv_conf_buf = NULL;
|
||||
}
|
||||
|
||||
int pal_get_version(void) __attribute__((weak, alias ("occlum_pal_get_version")));
|
||||
|
||||
int pal_init(const struct occlum_pal_attr *attr)\
|
||||
|
@ -1,9 +1,14 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "Enclave_u.h"
|
||||
#include "pal_log.h"
|
||||
#include "pal_load_file.h"
|
||||
|
||||
void pal_load_file(const char *filename, load_file_t *load_file) {
|
||||
void pal_load_file(const sgx_enclave_id_t eid, const char *filename,
|
||||
load_file_t *load_file) {
|
||||
#ifndef SGX_MODE_HYPER
|
||||
UNUSED(eid);
|
||||
#endif
|
||||
FILE *fp = fopen(filename, "rb");
|
||||
|
||||
if (fp == NULL) {
|
||||
@ -14,7 +19,11 @@ void pal_load_file(const char *filename, load_file_t *load_file) {
|
||||
long fsize = ftell(fp);
|
||||
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
#ifndef SGX_MODE_HYPER
|
||||
load_file->buffer = malloc(fsize + 1);
|
||||
#else
|
||||
load_file->buffer = sgx_ecall_ms_buffer_alloc(eid, fsize + 1);
|
||||
#endif
|
||||
if (load_file->buffer == NULL) {
|
||||
PAL_WARN("Warning: Failed to malloc buffer for file: %s", filename);
|
||||
return;
|
||||
@ -25,3 +34,35 @@ void pal_load_file(const char *filename, load_file_t *load_file) {
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
void free_host_file_buffer(const sgx_enclave_id_t eid,
|
||||
struct host_file_buffer_t *file_buffer) {
|
||||
#ifndef SGX_MODE_HYPER
|
||||
UNUSED(eid);
|
||||
if (file_buffer->hostname_buf) {
|
||||
free((void *)file_buffer->hostname_buf);
|
||||
}
|
||||
if (file_buffer->hosts_buf) {
|
||||
free((void *)file_buffer->hosts_buf);
|
||||
}
|
||||
if (file_buffer->resolv_conf_buf) {
|
||||
free((void *)file_buffer->resolv_conf_buf);
|
||||
}
|
||||
#else
|
||||
if (file_buffer->hostname_buf) {
|
||||
sgx_ecall_ms_buffer_free(eid);
|
||||
}
|
||||
if (file_buffer->hosts_buf) {
|
||||
sgx_ecall_ms_buffer_free(eid);
|
||||
}
|
||||
if (file_buffer->resolv_conf_buf) {
|
||||
sgx_ecall_ms_buffer_free(eid);
|
||||
}
|
||||
#endif
|
||||
file_buffer->hostname_buf = NULL;
|
||||
file_buffer->hostname_buf_size = 0;
|
||||
file_buffer->hosts_buf = NULL;
|
||||
file_buffer->hosts_buf_size = 0;
|
||||
file_buffer->resolv_conf_buf = NULL;
|
||||
file_buffer->resolv_conf_buf_size = 0;
|
||||
}
|
||||
|
@ -1,11 +1,17 @@
|
||||
#ifndef __PAL_LOAD_FILE_H__
|
||||
#define __PAL_LOAD_FILE_H__
|
||||
#include <sgx_eid.h>
|
||||
|
||||
#define UNUSED(val) (void)(val)
|
||||
|
||||
typedef struct {
|
||||
unsigned int size;
|
||||
char *buffer;
|
||||
} load_file_t;
|
||||
|
||||
void pal_load_file(const char *filename, load_file_t *load_file);
|
||||
void pal_load_file(const sgx_enclave_id_t eid, const char *filename,
|
||||
load_file_t *load_file);
|
||||
void free_host_file_buffer(const sgx_enclave_id_t eid,
|
||||
struct host_file_buffer_t *file_buffer);
|
||||
|
||||
#endif /* __PAL_LOAD_FILE_H__ */
|
||||
|
Loading…
Reference in New Issue
Block a user