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

@ -52,7 +52,7 @@ typedef pthread_mutex_t korp_mutex;
typedef pthread_cond_t korp_cond;
typedef unsigned int korp_sem;
typedef void (*os_print_function_t)(const char *message);
typedef int (*os_print_function_t)(const char *message);
void
os_set_print_function(os_print_function_t pf);

View File

@ -7,8 +7,6 @@
#include "platform_api_extension.h"
#include "sgx_rsrv_mem_mngr.h"
#define FIXED_BUFFER_SIZE (1 << 9)
static os_print_function_t print_function = NULL;
int
@ -57,31 +55,37 @@ os_set_print_function(os_print_function_t pf)
print_function = pf;
}
#define FIXED_BUFFER_SIZE 4096
int
os_printf(const char *message, ...)
{
int bytes_written = 0;
if (print_function != NULL) {
char msg[FIXED_BUFFER_SIZE] = { '\0' };
va_list ap;
va_start(ap, message);
vsnprintf(msg, FIXED_BUFFER_SIZE, message, ap);
va_end(ap);
print_function(msg);
bytes_written += print_function(msg);
}
return 0;
return bytes_written;
}
int
os_vprintf(const char *format, va_list arg)
{
int bytes_written = 0;
if (print_function != NULL) {
char msg[FIXED_BUFFER_SIZE] = { '\0' };
vsnprintf(msg, FIXED_BUFFER_SIZE, format, arg);
print_function(msg);
bytes_written += print_function(msg);
}
return 0;
return bytes_written;
}
char *