Support get return value for SGX os_printf/os_vprintf (#1387)

Fix the issue reported in #1359, change the implementation of
os_printf/os_vprintf for Intel SGX to get the actual bytes written.
This commit is contained in:
Wenyong Huang
2022-08-16 14:23:34 +08:00
committed by GitHub
parent aa7d447ee5
commit 6caa6b1d73
6 changed files with 31 additions and 22 deletions

View File

@ -13,14 +13,19 @@
#include "bh_platform.h"
extern "C" {
typedef void (*os_print_function_t)(const char *message);
typedef int (*os_print_function_t)(const char *message);
extern void
os_set_print_function(os_print_function_t pf);
void
int
enclave_print(const char *message)
{
ocall_print(message);
int bytes_written = 0;
if (SGX_SUCCESS != ocall_print(&bytes_written, message))
return 0;
return bytes_written;
}
}
@ -589,16 +594,16 @@ ecall_iwasm_main(uint8_t *wasm_file_buf, uint32_t wasm_file_size)
/* initialize runtime environment */
if (!wasm_runtime_full_init(&init_args)) {
ocall_print("Init runtime environment failed.");
ocall_print("\n");
enclave_print("Init runtime environment failed.");
enclave_print("\n");
return;
}
/* load WASM module */
if (!(wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size,
error_buf, sizeof(error_buf)))) {
ocall_print(error_buf);
ocall_print("\n");
enclave_print(error_buf);
enclave_print("\n");
goto fail1;
}
@ -606,16 +611,16 @@ ecall_iwasm_main(uint8_t *wasm_file_buf, uint32_t wasm_file_size)
if (!(wasm_module_inst =
wasm_runtime_instantiate(wasm_module, 16 * 1024, 16 * 1024,
error_buf, sizeof(error_buf)))) {
ocall_print(error_buf);
ocall_print("\n");
enclave_print(error_buf);
enclave_print("\n");
goto fail2;
}
/* execute the main function of wasm app */
wasm_application_execute_main(wasm_module_inst, 0, NULL);
if ((exception = wasm_runtime_get_exception(wasm_module_inst))) {
ocall_print(exception);
ocall_print("\n");
enclave_print(exception);
enclave_print("\n");
}
/* destroy the module instance */