Skip to content

Remove vestigial OE types #7122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions include/ccf/pal/mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ namespace ccf::pal
size_t peak_allocated_heap_size = 0;
};

#if !defined(INSIDE_ENCLAVE) || defined(VIRTUAL_ENCLAVE)

static inline void* safe_memcpy(void* dest, const void* src, size_t count)
{
return ::memcpy(dest, src, count);
Expand Down Expand Up @@ -63,27 +61,4 @@ namespace ccf::pal

return true;
}

#else

static inline void* safe_memcpy(void* dest, const void* src, size_t count)
{
return oe_memcpy_with_barrier(dest, src, count);
}

static bool get_mallinfo(MallocInfo& info)
{
oe_mallinfo_t oe_info;
auto rc = oe_allocator_mallinfo(&oe_info);
if (rc != OE_OK)
{
return false;
}
info.max_total_heap_size = oe_info.max_total_heap_size;
info.current_allocated_heap_size = oe_info.current_allocated_heap_size;
info.peak_allocated_heap_size = oe_info.peak_allocated_heap_size;
return true;
}

#endif
}
48 changes: 6 additions & 42 deletions src/enclave/virtual_enclave.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,11 @@ T get_enclave_exported_function(
return (T)sym;
}

// If this build does not also include OE definitions, then recreate them here.
// It should not matter if these do not match precisely OE's, so long as they
// can be used consistently by the virtual build.
using oe_result_t = int;
constexpr oe_result_t OE_OK = 0;
constexpr oe_result_t OE_FAILURE = 1;

using oe_enclave_t = void;
using oe_log_level_t = size_t;

enum oe_enclave_type_t
{
OE_ENCLAVE_TYPE_SGX = 2,
};

#define oe_result_str(x) x

#ifdef __cplusplus
extern "C"
{
#endif

typedef void (*oe_ocall_func_t)(
const uint8_t* input_buffer,
size_t input_buffer_size,
uint8_t* output_buffer,
size_t output_buffer_size,
size_t* output_bytes_written);

/*ocall function table*/
static oe_ocall_func_t __ccf_ocall_function_table[] = {nullptr};

inline void* load_virtual_enclave(const char* path)
{
auto virtual_enclave_handle = dlopen(
Expand Down Expand Up @@ -91,9 +64,8 @@ extern "C"
}
}

inline oe_result_t virtual_create_node(
inline CreateNodeStatus virtual_create_node(
void* virtual_enclave_handle,
CreateNodeStatus* status,
void* enclave_config,
uint8_t* ccf_config,
size_t ccf_config_size,
Expand Down Expand Up @@ -139,7 +111,7 @@ extern "C"
get_enclave_exported_function<create_node_func_t>(
virtual_enclave_handle, "enclave_create_node");

*status = create_node_func(
CreateNodeStatus status = create_node_func(
enclave_config,
ccf_config,
ccf_config_size,
Expand All @@ -160,26 +132,18 @@ extern "C"
time_location,
work_beacon);

// Only return OE_OK when the error isn't OE related
switch (*status)
{
case CreateNodeStatus::EnclaveInitFailed:
case CreateNodeStatus::MemoryNotOutsideEnclave:
return OE_FAILURE;
default:
return OE_OK;
}
return status;
}

inline oe_result_t virtual_run(void* virtual_enclave_handle, bool* _retval)
inline bool virtual_run(void* virtual_enclave_handle)
{
using run_func_t = bool (*)();

static run_func_t run_func = get_enclave_exported_function<run_func_t>(
virtual_enclave_handle, "enclave_run");

*_retval = run_func();
return *_retval ? OE_OK : OE_FAILURE;
bool retval = run_func();
return retval;
}

#ifdef __cplusplus
Expand Down
18 changes: 7 additions & 11 deletions src/host/enclave.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,21 @@ namespace host
auto config_s = nlohmann::json(ccf_config).dump();

#define CREATE_NODE_ARGS \
&status, (void*)&enclave_config, (uint8_t*)config_s.data(), config_s.size(), \
(void*)&enclave_config, (uint8_t*)config_s.data(), config_s.size(), \
startup_snapshot.data(), startup_snapshot.size(), node_cert.data(), \
node_cert.size(), &node_cert_len, service_cert.data(), \
service_cert.size(), &service_cert_len, enclave_version_buf.data(), \
enclave_version_buf.size(), &enclave_version_len, start_type, log_level, \
num_worker_thread, time_location, work_beacon

oe_result_t err = OE_FAILURE;

// Assume that constructor correctly set the appropriate field, and call
// appropriate function
if (virtual_handle != nullptr)
{
err = virtual_create_node(virtual_handle, CREATE_NODE_ARGS);
status = virtual_create_node(virtual_handle, CREATE_NODE_ARGS);
}

if (err != OE_OK || status != CreateNodeStatus::OK)
if (status != CreateNodeStatus::OK)
{
// Logs have described the errors already, we just need to allow the
// host to read them (via read_all()).
Expand Down Expand Up @@ -171,18 +169,16 @@ namespace host
// from a thread
bool run()
{
bool ret = true;
oe_result_t err = OE_FAILURE;
bool ret = false;

if (virtual_handle != nullptr)
{
err = virtual_run(virtual_handle, &ret);
ret = virtual_run(virtual_handle);
}

if (err != OE_OK)
if (!ret)
{
throw std::logic_error(
fmt::format("Failed to call in enclave_run: {}", oe_result_str(err)));
throw std::logic_error(fmt::format("Failure in virtual_run"));
}

return ret;
Expand Down
13 changes: 0 additions & 13 deletions tests/infra/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,6 @@ def get_result(self, line_count):
return self._get_perf(result)


CCF_TO_OE_LOG_LEVEL = {
"trace": "VERBOSE",
"debug": "INFO",
"info": "WARNING",
"fail": "ERROR",
"fatal": "FATAL",
}


class CCFRemote(object):
BIN = "cchost"
TEMPLATE_CONFIGURATION_FILE = "config.jinja"
Expand Down Expand Up @@ -361,10 +352,6 @@ def __init__(
snp_uvm_security_context_dir
)

oe_log_level = CCF_TO_OE_LOG_LEVEL.get(kwargs.get("log_level"))
if oe_log_level:
env["OE_LOG_LEVEL"] = oe_log_level

self.name = f"{label}_{local_node_id}"
self.start_type = start_type
self.local_node_id = local_node_id
Expand Down