Add macro to exclude sgx wasi/pthread ocalls if not needed (#384)

This commit is contained in:
Xu Jun
2020-09-15 15:49:09 +08:00
committed by GitHub
parent 2499e1ec4b
commit 547298d4e7
14 changed files with 412 additions and 4 deletions

View File

@ -7,6 +7,8 @@
#include "sgx_error.h"
#include "sgx_file.h"
#ifndef SGX_DISABLE_WASI
#define TRACE_FUNC() os_printf("undefined %s\n", __FUNCTION__)
#define TRACE_OCALL_FAIL() os_printf("ocall %s failed!\n", __FUNCTION__)
@ -830,3 +832,6 @@ int get_errno(void)
}
return ret;
}
#endif

View File

@ -7,6 +7,8 @@
#include "sgx_pthread.h"
#include "sgx_error.h"
#ifndef SGX_DISABLE_WASI
#define TRACE_FUNC() os_printf("undefined %s\n", __FUNCTION__)
#define TRACE_OCALL_FAIL() os_printf("ocall %s failed!\n", __FUNCTION__)
@ -73,3 +75,5 @@ int pthread_rwlock_unlock(pthread_rwlock_t *rwlock)
return ret;
}
#endif

View File

@ -5,6 +5,8 @@
#include "platform_api_vmcore.h"
#ifndef SGX_DISABLE_WASI
#define TRACE_OCALL_FAIL() os_printf("ocall %s failed!\n", __FUNCTION__)
int ocall_raise(int *p_ret, int sig);
@ -24,3 +26,5 @@ int raise(int sig)
return ret;
}
#endif

View File

@ -5,8 +5,9 @@
#include "platform_api_vmcore.h"
#define TRACE_OCALL_FAIL() os_printf("ocall %s failed!\n", __FUNCTION__)
#ifndef SGX_DISABLE_WASI
#define TRACE_OCALL_FAIL() os_printf("ocall %s failed!\n", __FUNCTION__)
int ocall_socket(int *p_ret, int domain, int type, int protocol);
int ocall_getsockopt(int *p_ret, int sockfd, int level, int optname,
@ -216,3 +217,6 @@ int shutdown(int sockfd, int how)
return ret;
}
#endif

View File

@ -6,6 +6,7 @@
#include "platform_api_vmcore.h"
#include "platform_api_extension.h"
#ifndef SGX_DISABLE_PTHREAD
typedef struct {
thread_start_routine_t start;
void *arg;
@ -52,56 +53,79 @@ int os_thread_create(korp_tid *tid, thread_start_routine_t start, void *arg,
return os_thread_create_with_prio(tid, start, arg, stack_size,
BH_THREAD_DEFAULT_PRIORITY);
}
#endif
korp_tid os_self_thread()
{
#ifndef SGX_DISABLE_PTHREAD
return pthread_self();
#else
return 0;
#endif
}
int os_mutex_init(korp_mutex *mutex)
{
#ifndef SGX_DISABLE_PTHREAD
pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
*mutex = m;
#endif
return BHT_OK;
}
int os_mutex_destroy(korp_mutex *mutex)
{
#ifndef SGX_DISABLE_PTHREAD
pthread_mutex_destroy(mutex);
#endif
return BHT_OK;
}
int os_mutex_lock(korp_mutex *mutex)
{
#ifndef SGX_DISABLE_PTHREAD
return pthread_mutex_lock(mutex);
#else
return 0;
#endif
}
int os_mutex_unlock(korp_mutex *mutex)
{
#ifndef SGX_DISABLE_PTHREAD
return pthread_mutex_unlock(mutex);
#else
return 0;
#endif
}
int os_cond_init(korp_cond *cond)
{
#ifndef SGX_DISABLE_PTHREAD
pthread_cond_t c = PTHREAD_COND_INITIALIZER;
*cond = c;
#endif
return BHT_OK;
}
int os_cond_destroy(korp_cond *cond)
{
#ifndef SGX_DISABLE_PTHREAD
pthread_cond_destroy(cond);
#endif
return BHT_OK;
}
int os_cond_wait(korp_cond *cond, korp_mutex *mutex)
{
#ifndef SGX_DISABLE_PTHREAD
assert(cond);
assert(mutex);
if (pthread_cond_wait(cond, mutex) != BHT_OK)
return BHT_ERROR;
#endif
return BHT_OK;
}
@ -114,17 +138,23 @@ int os_cond_reltimedwait(korp_cond *cond, korp_mutex *mutex, int useconds)
int os_cond_signal(korp_cond *cond)
{
#ifndef SGX_DISABLE_PTHREAD
assert(cond);
if (pthread_cond_signal(cond) != BHT_OK)
return BHT_ERROR;
#endif
return BHT_OK;
}
int os_thread_join(korp_tid thread, void **value_ptr)
{
#ifndef SGX_DISABLE_PTHREAD
return pthread_join(thread, value_ptr);
#else
return 0;
#endif
}
int os_thread_detach(korp_tid thread)
@ -135,7 +165,11 @@ int os_thread_detach(korp_tid thread)
void os_thread_exit(void *retval)
{
return pthread_exit(retval);
#ifndef SGX_DISABLE_PTHREAD
pthread_exit(retval);
#else
return;
#endif
}
uint8 *os_thread_get_stack_boundary()

View File

@ -28,6 +28,8 @@ os_time_get_boot_microsecond()
return 0;
}
#ifndef SGX_DISABLE_WASI
int clock_getres(int clock_id, struct timespec *res)
{
int ret;
@ -113,3 +115,6 @@ int clock_nanosleep(clockid_t clock_id, int flags,
return ret;
}
#endif

View File

@ -20,6 +20,14 @@ if (NOT BUILD_UNTRUST_PART EQUAL 1)
${SGX_SDK_DIR}/include/libcxx)
endif ()
if (NOT WAMR_BUILD_LIBC_WASI EQUAL 1)
add_definitions(-DSGX_DISABLE_WASI)
endif ()
if (NOT WAMR_BUILD_THREAD_MGR EQUAL 1)
add_definitions(-DSGX_DISABLE_PTHREAD)
endif ()
file (GLOB source_all ${PLATFORM_SHARED_DIR}/*.c)
file (GLOB source_all_untrusted ${PLATFORM_SHARED_DIR}/untrusted/*.c)