Apply clang-format for core/shared and product-mini files (#785)
Apply clang-format for core/shared and product-mini files
This commit is contained in:
@ -38,8 +38,7 @@ os_realloc(void *ptr, unsigned size)
|
||||
|
||||
void
|
||||
os_free(void *ptr)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
void *
|
||||
os_mmap(void *hint, size_t size, int prot, int flags)
|
||||
@ -63,5 +62,4 @@ os_mprotect(void *addr, size_t size, int prot)
|
||||
|
||||
void
|
||||
os_dcache_flush()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
@ -6,14 +6,16 @@
|
||||
#include "platform_api_vmcore.h"
|
||||
#include "platform_api_extension.h"
|
||||
|
||||
/* clang-format off */
|
||||
#define bh_assert(v) do { \
|
||||
if (!(v)) { \
|
||||
printf("\nASSERTION FAILED: %s, at %s, line %d\n", \
|
||||
#v, __FILE__, __LINE__); \
|
||||
aos_reboot(); \
|
||||
while (1); \
|
||||
} \
|
||||
} while (0)
|
||||
if (!(v)) { \
|
||||
printf("\nASSERTION FAILED: %s, at %s, line %d\n", \
|
||||
#v, __FILE__, __LINE__); \
|
||||
aos_reboot(); \
|
||||
while (1); \
|
||||
} \
|
||||
} while (0)
|
||||
/* clang-format on */
|
||||
|
||||
struct os_thread_data;
|
||||
typedef struct os_thread_wait_node {
|
||||
@ -138,8 +140,8 @@ os_thread_wrapper(void *arg)
|
||||
}
|
||||
|
||||
int
|
||||
os_thread_create(korp_tid *p_tid, thread_start_routine_t start,
|
||||
void *arg, unsigned int stack_size)
|
||||
os_thread_create(korp_tid *p_tid, thread_start_routine_t start, void *arg,
|
||||
unsigned int stack_size)
|
||||
{
|
||||
return os_thread_create_with_prio(p_tid, start, arg, stack_size,
|
||||
BH_THREAD_DEFAULT_PRIORITY);
|
||||
@ -170,13 +172,12 @@ os_thread_create_with_prio(korp_tid *p_tid, thread_start_routine_t start,
|
||||
if (aos_mutex_new(&thread_data->wait_list_lock))
|
||||
goto fail2;
|
||||
|
||||
snprintf(thread_name, sizeof(thread_name), "%s%d",
|
||||
"wasm-thread-", ++thread_name_index);
|
||||
snprintf(thread_name, sizeof(thread_name), "%s%d", "wasm-thread-",
|
||||
++thread_name_index);
|
||||
|
||||
/* Create the thread */
|
||||
if (aos_task_new_ext((aos_task_t*)thread_data, thread_name,
|
||||
os_thread_wrapper, thread_data,
|
||||
stack_size, prio))
|
||||
if (aos_task_new_ext((aos_task_t *)thread_data, thread_name,
|
||||
os_thread_wrapper, thread_data, stack_size, prio))
|
||||
goto fail3;
|
||||
|
||||
aos_msleep(10);
|
||||
@ -199,7 +200,7 @@ os_self_thread()
|
||||
}
|
||||
|
||||
int
|
||||
os_thread_join (korp_tid thread, void **value_ptr)
|
||||
os_thread_join(korp_tid thread, void **value_ptr)
|
||||
{
|
||||
(void)value_ptr;
|
||||
os_thread_data *thread_data, *curr_thread_data;
|
||||
@ -209,7 +210,7 @@ os_thread_join (korp_tid thread, void **value_ptr)
|
||||
curr_thread_data->wait_node.next = NULL;
|
||||
|
||||
/* Get thread data */
|
||||
thread_data = (os_thread_data*)thread;
|
||||
thread_data = (os_thread_data *)thread;
|
||||
|
||||
aos_mutex_lock(&thread_data->wait_list_lock, AOS_WAIT_FOREVER);
|
||||
if (!thread_data->thread_wait_list)
|
||||
@ -272,8 +273,8 @@ os_cond_destroy(korp_cond *cond)
|
||||
}
|
||||
|
||||
static int
|
||||
os_cond_wait_internal(korp_cond *cond, korp_mutex *mutex,
|
||||
bool timed, uint32 mills)
|
||||
os_cond_wait_internal(korp_cond *cond, korp_mutex *mutex, bool timed,
|
||||
uint32 mills)
|
||||
{
|
||||
os_thread_wait_node *node = &thread_data_current()->wait_node;
|
||||
|
||||
@ -352,9 +353,9 @@ os_cond_signal(korp_cond *cond)
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
uint8 *os_thread_get_stack_boundary()
|
||||
uint8 *
|
||||
os_thread_get_stack_boundary()
|
||||
{
|
||||
/* TODO: get alios stack boundary */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@ -10,4 +10,3 @@ os_time_get_boot_microsecond()
|
||||
{
|
||||
return (uint64)aos_now_ms() * 1000;
|
||||
}
|
||||
|
||||
|
||||
@ -34,13 +34,14 @@ typedef aos_mutex_t korp_mutex;
|
||||
struct os_thread_wait_node;
|
||||
typedef struct os_thread_wait_node *os_thread_wait_list;
|
||||
typedef struct korp_cond {
|
||||
aos_mutex_t wait_list_lock;
|
||||
os_thread_wait_list thread_wait_list;
|
||||
aos_mutex_t wait_list_lock;
|
||||
os_thread_wait_list thread_wait_list;
|
||||
} korp_cond;
|
||||
|
||||
#define os_printf printf
|
||||
#define os_printf printf
|
||||
#define os_vprintf vprintf
|
||||
|
||||
/* clang-format off */
|
||||
/* math functions which are not provided by os*/
|
||||
double sqrt(double x);
|
||||
double floor(double x);
|
||||
@ -58,6 +59,6 @@ float rintf(float x);
|
||||
float truncf(float x);
|
||||
int signbit(double x);
|
||||
int isnan(double x);
|
||||
/* clang-format on */
|
||||
|
||||
#endif /* end of _BH_PLATFORM_H */
|
||||
|
||||
|
||||
@ -19,10 +19,10 @@ bh_platform_init()
|
||||
|
||||
void
|
||||
bh_platform_destroy()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
int os_printf(const char *fmt, ...)
|
||||
int
|
||||
os_printf(const char *fmt, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
@ -34,14 +34,16 @@ int os_printf(const char *fmt, ...)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int os_vprintf(const char *fmt, va_list ap)
|
||||
int
|
||||
os_vprintf(const char *fmt, va_list ap)
|
||||
{
|
||||
return __android_log_vprint(ANDROID_LOG_INFO, "wasm_runtime::", fmt, ap);
|
||||
}
|
||||
|
||||
#if __ANDROID_API__ < 19
|
||||
|
||||
int futimens(int __dir_fd, const struct timespec __times[2])
|
||||
int
|
||||
futimens(int __dir_fd, const struct timespec __times[2])
|
||||
{
|
||||
API_NOT_SUPPORT_ERROR(futimens, 19);
|
||||
return -1;
|
||||
@ -51,32 +53,37 @@ int futimens(int __dir_fd, const struct timespec __times[2])
|
||||
|
||||
#if __ANDROID_API__ < 21
|
||||
|
||||
int posix_fallocate(int __fd, off_t __offset, off_t __length)
|
||||
int
|
||||
posix_fallocate(int __fd, off_t __offset, off_t __length)
|
||||
{
|
||||
API_NOT_SUPPORT_ERROR(posix_fallocate, 21);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int posix_fadvise(int fd, off_t offset, off_t len, int advice)
|
||||
int
|
||||
posix_fadvise(int fd, off_t offset, off_t len, int advice)
|
||||
{
|
||||
API_NOT_SUPPORT_ERROR(posix_fadvise, 21);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int linkat(int __old_dir_fd, const char *__old_path,
|
||||
int __new_dir_fd, const char *__new_path, int __flags)
|
||||
int
|
||||
linkat(int __old_dir_fd, const char *__old_path, int __new_dir_fd,
|
||||
const char *__new_path, int __flags)
|
||||
{
|
||||
API_NOT_SUPPORT_ERROR(linkat, 21);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int symlinkat(const char *__old_path, int __new_dir_fd, const char *__new_path)
|
||||
int
|
||||
symlinkat(const char *__old_path, int __new_dir_fd, const char *__new_path)
|
||||
{
|
||||
API_NOT_SUPPORT_ERROR(symlinkat, 21);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssize_t readlinkat(int __dir_fd, const char *__path, char *__buf, size_t __buf_size)
|
||||
ssize_t
|
||||
readlinkat(int __dir_fd, const char *__path, char *__buf, size_t __buf_size)
|
||||
{
|
||||
API_NOT_SUPPORT_ERROR(readlinkat, 21);
|
||||
return -1;
|
||||
@ -86,13 +93,15 @@ ssize_t readlinkat(int __dir_fd, const char *__path, char *__buf, size_t __buf_s
|
||||
|
||||
#if __ANDROID_API__ < 23
|
||||
|
||||
long telldir(DIR *__dir)
|
||||
long
|
||||
telldir(DIR *__dir)
|
||||
{
|
||||
API_NOT_SUPPORT_ERROR(telldir, 23);
|
||||
return -1;
|
||||
}
|
||||
|
||||
void seekdir(DIR *__dir, long __location)
|
||||
void
|
||||
seekdir(DIR *__dir, long __location)
|
||||
{
|
||||
API_NOT_SUPPORT_ERROR(seekdir, 23);
|
||||
}
|
||||
@ -101,13 +110,15 @@ void seekdir(DIR *__dir, long __location)
|
||||
|
||||
#if __ANDROID_API__ < 24
|
||||
|
||||
ssize_t preadv(int __fd, const struct iovec *__iov, int __count, off_t __offset)
|
||||
ssize_t
|
||||
preadv(int __fd, const struct iovec *__iov, int __count, off_t __offset)
|
||||
{
|
||||
API_NOT_SUPPORT_ERROR(preadv, 24);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssize_t pwritev(int __fd, const struct iovec *__iov, int __count, off_t __offset)
|
||||
ssize_t
|
||||
pwritev(int __fd, const struct iovec *__iov, int __count, off_t __offset)
|
||||
{
|
||||
API_NOT_SUPPORT_ERROR(pwritev, 24);
|
||||
return -1;
|
||||
|
||||
@ -59,10 +59,8 @@ typedef pthread_t korp_thread;
|
||||
#define os_thread_local_attribute __thread
|
||||
|
||||
#if WASM_DISABLE_HW_BOUND_CHECK == 0
|
||||
#if defined(BUILD_TARGET_X86_64) \
|
||||
|| defined(BUILD_TARGET_AMD_64) \
|
||||
|| defined(BUILD_TARGET_AARCH64) \
|
||||
|| defined(BUILD_TARGET_RISCV64_LP64D) \
|
||||
#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64) \
|
||||
|| defined(BUILD_TARGET_AARCH64) || defined(BUILD_TARGET_RISCV64_LP64D) \
|
||||
|| defined(BUILD_TARGET_RISCV64_LP64)
|
||||
|
||||
#include <setjmp.h>
|
||||
@ -79,15 +77,20 @@ typedef jmp_buf korp_jmpbuf;
|
||||
|
||||
typedef void (*os_signal_handler)(void *sig_addr);
|
||||
|
||||
int os_thread_signal_init(os_signal_handler handler);
|
||||
int
|
||||
os_thread_signal_init(os_signal_handler handler);
|
||||
|
||||
void os_thread_signal_destroy();
|
||||
void
|
||||
os_thread_signal_destroy();
|
||||
|
||||
bool os_thread_signal_inited();
|
||||
bool
|
||||
os_thread_signal_inited();
|
||||
|
||||
void os_signal_unmask();
|
||||
void
|
||||
os_signal_unmask();
|
||||
|
||||
void os_sigreturn();
|
||||
void
|
||||
os_sigreturn();
|
||||
#endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64/RISCV64 */
|
||||
#endif /* end of WASM_DISABLE_HW_BOUND_CHECK */
|
||||
|
||||
@ -95,38 +98,48 @@ typedef long int __syscall_slong_t;
|
||||
|
||||
#if __ANDROID_API__ < 19
|
||||
|
||||
int futimens(int __dir_fd, const struct timespec __times[2]);
|
||||
int
|
||||
futimens(int __dir_fd, const struct timespec __times[2]);
|
||||
|
||||
#endif
|
||||
|
||||
#if __ANDROID_API__ < 21
|
||||
|
||||
int posix_fallocate(int __fd, off_t __offset, off_t __length);
|
||||
int
|
||||
posix_fallocate(int __fd, off_t __offset, off_t __length);
|
||||
|
||||
int posix_fadvise(int fd, off_t offset, off_t len, int advice);
|
||||
int
|
||||
posix_fadvise(int fd, off_t offset, off_t len, int advice);
|
||||
|
||||
int linkat(int __old_dir_fd, const char *__old_path,
|
||||
int __new_dir_fd, const char *__new_path, int __flags);
|
||||
int
|
||||
linkat(int __old_dir_fd, const char *__old_path, int __new_dir_fd,
|
||||
const char *__new_path, int __flags);
|
||||
|
||||
int symlinkat(const char *__old_path, int __new_dir_fd, const char *__new_path);
|
||||
int
|
||||
symlinkat(const char *__old_path, int __new_dir_fd, const char *__new_path);
|
||||
|
||||
ssize_t readlinkat(int __dir_fd, const char *__path, char *__buf, size_t __buf_size);
|
||||
ssize_t
|
||||
readlinkat(int __dir_fd, const char *__path, char *__buf, size_t __buf_size);
|
||||
|
||||
#endif
|
||||
|
||||
#if __ANDROID_API__ < 23
|
||||
|
||||
long telldir(DIR *__dir);
|
||||
long
|
||||
telldir(DIR *__dir);
|
||||
|
||||
void seekdir(DIR *__dir, long __location);
|
||||
void
|
||||
seekdir(DIR *__dir, long __location);
|
||||
|
||||
#endif
|
||||
|
||||
#if __ANDROID_API__ < 24
|
||||
|
||||
ssize_t preadv(int __fd, const struct iovec *__iov, int __count, off_t __offset);
|
||||
ssize_t
|
||||
preadv(int __fd, const struct iovec *__iov, int __count, off_t __offset);
|
||||
|
||||
ssize_t pwritev(int __fd, const struct iovec *__iov, int __count, off_t __offset);
|
||||
ssize_t
|
||||
pwritev(int __fd, const struct iovec *__iov, int __count, off_t __offset);
|
||||
|
||||
#endif
|
||||
|
||||
@ -135,4 +148,3 @@ ssize_t pwritev(int __fd, const struct iovec *__iov, int __count, off_t __offset
|
||||
#endif
|
||||
|
||||
#endif /* end of _PLATFORM_INTERNAL_H */
|
||||
|
||||
|
||||
@ -5,7 +5,6 @@
|
||||
|
||||
#include "platform_api_vmcore.h"
|
||||
|
||||
|
||||
void *
|
||||
os_malloc(unsigned size)
|
||||
{
|
||||
@ -20,6 +19,4 @@ os_realloc(void *ptr, unsigned size)
|
||||
|
||||
void
|
||||
os_free(void *ptr)
|
||||
{
|
||||
}
|
||||
|
||||
{}
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
#include "platform_api_vmcore.h"
|
||||
#include "platform_api_extension.h"
|
||||
|
||||
/* clang-format off */
|
||||
#define bh_assert(v) do { \
|
||||
if (!(v)) { \
|
||||
int _count = 1; \
|
||||
@ -15,7 +16,8 @@
|
||||
os_printf("%d\n", _count / (_count - 1)); \
|
||||
while (1); \
|
||||
} \
|
||||
} while (0)
|
||||
} while (0)
|
||||
/* clang-format on */
|
||||
|
||||
struct os_thread_data;
|
||||
typedef struct os_thread_wait_node {
|
||||
@ -56,7 +58,8 @@ static os_thread_data supervisor_thread_data;
|
||||
/* Thread name index */
|
||||
static int thread_name_index;
|
||||
|
||||
static void thread_data_list_add(os_thread_data *thread_data)
|
||||
static void
|
||||
thread_data_list_add(os_thread_data *thread_data)
|
||||
{
|
||||
xSemaphoreTake(thread_data_lock, portMAX_DELAY);
|
||||
if (!thread_data_list)
|
||||
@ -79,7 +82,8 @@ static void thread_data_list_add(os_thread_data *thread_data)
|
||||
xSemaphoreGive(thread_data_lock);
|
||||
}
|
||||
|
||||
static void thread_data_list_remove(os_thread_data *thread_data)
|
||||
static void
|
||||
thread_data_list_remove(os_thread_data *thread_data)
|
||||
{
|
||||
xSemaphoreTake(thread_data_lock, portMAX_DELAY);
|
||||
if (thread_data_list) {
|
||||
@ -204,15 +208,17 @@ os_thread_wrapper(void *arg)
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
int os_thread_create(korp_tid *p_tid, thread_start_routine_t start, void *arg,
|
||||
unsigned int stack_size)
|
||||
int
|
||||
os_thread_create(korp_tid *p_tid, thread_start_routine_t start, void *arg,
|
||||
unsigned int stack_size)
|
||||
{
|
||||
return os_thread_create_with_prio(p_tid, start, arg, stack_size,
|
||||
BH_THREAD_DEFAULT_PRIORITY);
|
||||
}
|
||||
|
||||
int os_thread_create_with_prio(korp_tid *p_tid, thread_start_routine_t start,
|
||||
void *arg, unsigned int stack_size, int prio)
|
||||
int
|
||||
os_thread_create_with_prio(korp_tid *p_tid, thread_start_routine_t start,
|
||||
void *arg, unsigned int stack_size, int prio)
|
||||
{
|
||||
os_thread_data *thread_data;
|
||||
char thread_name[32];
|
||||
@ -235,13 +241,13 @@ int os_thread_create_with_prio(korp_tid *p_tid, thread_start_routine_t start,
|
||||
if (!(thread_data->wait_list_lock = xSemaphoreCreateMutex()))
|
||||
goto fail2;
|
||||
|
||||
snprintf(thread_name, sizeof(thread_name), "%s%d",
|
||||
"wasm-thread-", ++thread_name_index);
|
||||
snprintf(thread_name, sizeof(thread_name), "%s%d", "wasm-thread-",
|
||||
++thread_name_index);
|
||||
|
||||
/* Create the thread */
|
||||
if (pdPASS != xTaskCreate(os_thread_wrapper, thread_name,
|
||||
stack_size / 4, thread_data,
|
||||
prio, &thread_data->handle))
|
||||
if (pdPASS
|
||||
!= xTaskCreate(os_thread_wrapper, thread_name, stack_size / 4,
|
||||
thread_data, prio, &thread_data->handle))
|
||||
goto fail3;
|
||||
|
||||
thread_data_list_add(thread_data);
|
||||
@ -257,12 +263,14 @@ fail1:
|
||||
return BHT_ERROR;
|
||||
}
|
||||
|
||||
korp_tid os_self_thread()
|
||||
korp_tid
|
||||
os_self_thread()
|
||||
{
|
||||
return xTaskGetCurrentTaskHandle();
|
||||
}
|
||||
|
||||
int os_thread_join(korp_tid thread, void **value_ptr)
|
||||
int
|
||||
os_thread_join(korp_tid thread, void **value_ptr)
|
||||
{
|
||||
os_thread_data *thread_data, *curr_thread_data;
|
||||
TaskHandle_t handle = thread;
|
||||
@ -293,7 +301,8 @@ int os_thread_join(korp_tid thread, void **value_ptr)
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int os_mutex_init(korp_mutex *mutex)
|
||||
int
|
||||
os_mutex_init(korp_mutex *mutex)
|
||||
{
|
||||
SemaphoreHandle_t semaphore;
|
||||
|
||||
@ -304,7 +313,8 @@ int os_mutex_init(korp_mutex *mutex)
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int os_recursive_mutex_init(korp_mutex *mutex)
|
||||
int
|
||||
os_recursive_mutex_init(korp_mutex *mutex)
|
||||
{
|
||||
SemaphoreHandle_t semaphore;
|
||||
|
||||
@ -315,13 +325,15 @@ int os_recursive_mutex_init(korp_mutex *mutex)
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int os_mutex_destroy(korp_mutex *mutex)
|
||||
int
|
||||
os_mutex_destroy(korp_mutex *mutex)
|
||||
{
|
||||
vSemaphoreDelete(mutex->sem);
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int os_mutex_lock(korp_mutex *mutex)
|
||||
int
|
||||
os_mutex_lock(korp_mutex *mutex)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
@ -332,7 +344,8 @@ int os_mutex_lock(korp_mutex *mutex)
|
||||
return ret == pdPASS ? BHT_OK : BHT_ERROR;
|
||||
}
|
||||
|
||||
int os_mutex_unlock(korp_mutex *mutex)
|
||||
int
|
||||
os_mutex_unlock(korp_mutex *mutex)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
@ -343,7 +356,8 @@ int os_mutex_unlock(korp_mutex *mutex)
|
||||
return ret == pdPASS ? BHT_OK : BHT_ERROR;
|
||||
}
|
||||
|
||||
int os_cond_init(korp_cond *cond)
|
||||
int
|
||||
os_cond_init(korp_cond *cond)
|
||||
{
|
||||
if (!(cond->wait_list_lock = xSemaphoreCreateMutex()))
|
||||
return BHT_ERROR;
|
||||
@ -352,15 +366,15 @@ int os_cond_init(korp_cond *cond)
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int os_cond_destroy(korp_cond *cond)
|
||||
int
|
||||
os_cond_destroy(korp_cond *cond)
|
||||
{
|
||||
vSemaphoreDelete(cond->wait_list_lock);
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
os_cond_wait_internal(korp_cond *cond, korp_mutex *mutex,
|
||||
bool timed, int mills)
|
||||
os_cond_wait_internal(korp_cond *cond, korp_mutex *mutex, bool timed, int mills)
|
||||
{
|
||||
os_thread_wait_node *node = &thread_data_current()->wait_node;
|
||||
|
||||
@ -399,12 +413,14 @@ os_cond_wait_internal(korp_cond *cond, korp_mutex *mutex,
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int os_cond_wait(korp_cond *cond, korp_mutex *mutex)
|
||||
int
|
||||
os_cond_wait(korp_cond *cond, korp_mutex *mutex)
|
||||
{
|
||||
return os_cond_wait_internal(cond, mutex, false, 0);
|
||||
}
|
||||
|
||||
int os_cond_reltimedwait(korp_cond *cond, korp_mutex *mutex, uint64 useconds)
|
||||
int
|
||||
os_cond_reltimedwait(korp_cond *cond, korp_mutex *mutex, uint64 useconds)
|
||||
{
|
||||
if (useconds == BHT_WAIT_FOREVER) {
|
||||
return os_cond_wait_internal(cond, mutex, false, 0);
|
||||
@ -425,7 +441,8 @@ int os_cond_reltimedwait(korp_cond *cond, korp_mutex *mutex, uint64 useconds)
|
||||
}
|
||||
}
|
||||
|
||||
int os_cond_signal(korp_cond *cond)
|
||||
int
|
||||
os_cond_signal(korp_cond *cond)
|
||||
{
|
||||
/* Signal the head wait node of wait list */
|
||||
xSemaphoreTake(cond->wait_list_lock, portMAX_DELAY);
|
||||
@ -435,4 +452,3 @@ int os_cond_signal(korp_cond *cond)
|
||||
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
|
||||
@ -11,4 +11,3 @@ os_time_get_boot_microsecond()
|
||||
TickType_t ticks = xTaskGetTickCount();
|
||||
return (uint64)1000 * 1000 / configTICK_RATE_HZ * ticks;
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -22,6 +22,3 @@ os_free(void *ptr)
|
||||
{
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -50,21 +50,19 @@ os_mmap(void *hint, size_t size, int prot, int flags)
|
||||
* (mmap's first argument) to meet the requirement.
|
||||
*/
|
||||
if (!hint && !(flags & MMAP_MAP_FIXED) && (flags & MMAP_MAP_32BIT)) {
|
||||
uint8 *stack_addr = (uint8*)&map_prot;
|
||||
uint8 *text_addr = (uint8*)os_mmap;
|
||||
uint8 *stack_addr = (uint8 *)&map_prot;
|
||||
uint8 *text_addr = (uint8 *)os_mmap;
|
||||
/* hint address begins with 1MB */
|
||||
static uint8 *hint_addr = (uint8 *)(uintptr_t)BH_MB;
|
||||
|
||||
if ((hint_addr - text_addr >= 0
|
||||
&& hint_addr - text_addr < 100 * BH_MB)
|
||||
if ((hint_addr - text_addr >= 0 && hint_addr - text_addr < 100 * BH_MB)
|
||||
|| (text_addr - hint_addr >= 0
|
||||
&& text_addr - hint_addr < 100 * BH_MB)) {
|
||||
/* hint address is possibly in text section, skip it */
|
||||
hint_addr += 100 * BH_MB;
|
||||
}
|
||||
|
||||
if ((hint_addr - stack_addr >= 0
|
||||
&& hint_addr - stack_addr < 8 * BH_MB)
|
||||
if ((hint_addr - stack_addr >= 0 && hint_addr - stack_addr < 8 * BH_MB)
|
||||
|| (stack_addr - hint_addr >= 0
|
||||
&& stack_addr - hint_addr < 8 * BH_MB)) {
|
||||
/* hint address is possibly in native stack area, skip it */
|
||||
@ -72,8 +70,7 @@ os_mmap(void *hint, size_t size, int prot, int flags)
|
||||
}
|
||||
|
||||
/* try 10 times, step with 1MB each time */
|
||||
for (i = 0;
|
||||
i < 10 && hint_addr < (uint8 *)(uintptr_t)(2ULL * BH_GB);
|
||||
for (i = 0; i < 10 && hint_addr < (uint8 *)(uintptr_t)(2ULL * BH_GB);
|
||||
i++) {
|
||||
addr = mmap(hint_addr, request_size, map_prot, map_flags, -1, 0);
|
||||
if (addr != MAP_FAILED) {
|
||||
@ -114,7 +111,7 @@ os_munmap(void *addr, size_t size)
|
||||
|
||||
if (addr) {
|
||||
if (munmap(addr, request_size)) {
|
||||
os_printf("os_munmap error addr:%p, size:0x%"PRIx64", errno:%d\n",
|
||||
os_printf("os_munmap error addr:%p, size:0x%" PRIx64 ", errno:%d\n",
|
||||
addr, request_size, errno);
|
||||
}
|
||||
}
|
||||
@ -144,5 +141,4 @@ os_mprotect(void *addr, size_t size, int prot)
|
||||
|
||||
void
|
||||
os_dcache_flush(void)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
@ -22,7 +22,8 @@ typedef struct {
|
||||
static os_thread_local_attribute os_signal_handler signal_handler;
|
||||
#endif
|
||||
|
||||
static void *os_thread_wrapper(void *arg)
|
||||
static void *
|
||||
os_thread_wrapper(void *arg)
|
||||
{
|
||||
thread_wrapper_arg *targ = arg;
|
||||
thread_start_routine_t start_func = targ->start;
|
||||
@ -44,8 +45,9 @@ static void *os_thread_wrapper(void *arg)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int os_thread_create_with_prio(korp_tid *tid, thread_start_routine_t start,
|
||||
void *arg, unsigned int stack_size, int prio)
|
||||
int
|
||||
os_thread_create_with_prio(korp_tid *tid, thread_start_routine_t start,
|
||||
void *arg, unsigned int stack_size, int prio)
|
||||
{
|
||||
pthread_attr_t tattr;
|
||||
thread_wrapper_arg *targ;
|
||||
@ -63,7 +65,7 @@ int os_thread_create_with_prio(korp_tid *tid, thread_start_routine_t start,
|
||||
return BHT_ERROR;
|
||||
}
|
||||
|
||||
targ = (thread_wrapper_arg*) BH_MALLOC(sizeof(*targ));
|
||||
targ = (thread_wrapper_arg *)BH_MALLOC(sizeof(*targ));
|
||||
if (!targ) {
|
||||
pthread_attr_destroy(&tattr);
|
||||
return BHT_ERROR;
|
||||
@ -85,24 +87,28 @@ int os_thread_create_with_prio(korp_tid *tid, thread_start_routine_t start,
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int os_thread_create(korp_tid *tid, thread_start_routine_t start, void *arg,
|
||||
unsigned int stack_size)
|
||||
int
|
||||
os_thread_create(korp_tid *tid, thread_start_routine_t start, void *arg,
|
||||
unsigned int stack_size)
|
||||
{
|
||||
return os_thread_create_with_prio(tid, start, arg, stack_size,
|
||||
BH_THREAD_DEFAULT_PRIORITY);
|
||||
}
|
||||
|
||||
korp_tid os_self_thread()
|
||||
korp_tid
|
||||
os_self_thread()
|
||||
{
|
||||
return (korp_tid) pthread_self();
|
||||
return (korp_tid)pthread_self();
|
||||
}
|
||||
|
||||
int os_mutex_init(korp_mutex *mutex)
|
||||
int
|
||||
os_mutex_init(korp_mutex *mutex)
|
||||
{
|
||||
return pthread_mutex_init(mutex, NULL) == 0 ? BHT_OK : BHT_ERROR;
|
||||
}
|
||||
|
||||
int os_recursive_mutex_init(korp_mutex *mutex)
|
||||
int
|
||||
os_recursive_mutex_init(korp_mutex *mutex)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -120,7 +126,8 @@ int os_recursive_mutex_init(korp_mutex *mutex)
|
||||
return ret == 0 ? BHT_OK : BHT_ERROR;
|
||||
}
|
||||
|
||||
int os_mutex_destroy(korp_mutex *mutex)
|
||||
int
|
||||
os_mutex_destroy(korp_mutex *mutex)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -130,7 +137,8 @@ int os_mutex_destroy(korp_mutex *mutex)
|
||||
return ret == 0 ? BHT_OK : BHT_ERROR;
|
||||
}
|
||||
|
||||
int os_mutex_lock(korp_mutex *mutex)
|
||||
int
|
||||
os_mutex_lock(korp_mutex *mutex)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -140,7 +148,8 @@ int os_mutex_lock(korp_mutex *mutex)
|
||||
return ret == 0 ? BHT_OK : BHT_ERROR;
|
||||
}
|
||||
|
||||
int os_mutex_unlock(korp_mutex *mutex)
|
||||
int
|
||||
os_mutex_unlock(korp_mutex *mutex)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -150,7 +159,8 @@ int os_mutex_unlock(korp_mutex *mutex)
|
||||
return ret == 0 ? BHT_OK : BHT_ERROR;
|
||||
}
|
||||
|
||||
int os_cond_init(korp_cond *cond)
|
||||
int
|
||||
os_cond_init(korp_cond *cond)
|
||||
{
|
||||
assert(cond);
|
||||
|
||||
@ -160,7 +170,8 @@ int os_cond_init(korp_cond *cond)
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int os_cond_destroy(korp_cond *cond)
|
||||
int
|
||||
os_cond_destroy(korp_cond *cond)
|
||||
{
|
||||
assert(cond);
|
||||
|
||||
@ -170,7 +181,8 @@ int os_cond_destroy(korp_cond *cond)
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int os_cond_wait(korp_cond *cond, korp_mutex *mutex)
|
||||
int
|
||||
os_cond_wait(korp_cond *cond, korp_mutex *mutex)
|
||||
{
|
||||
assert(cond);
|
||||
assert(mutex);
|
||||
@ -181,7 +193,8 @@ int os_cond_wait(korp_cond *cond, korp_mutex *mutex)
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
static void msec_nsec_to_abstime(struct timespec *ts, uint64 usec)
|
||||
static void
|
||||
msec_nsec_to_abstime(struct timespec *ts, uint64 usec)
|
||||
{
|
||||
struct timeval tv;
|
||||
time_t tv_sec_new;
|
||||
@ -201,8 +214,7 @@ static void msec_nsec_to_abstime(struct timespec *ts, uint64 usec)
|
||||
}
|
||||
|
||||
tv_nsec_new = (long int)(tv.tv_usec * 1000 + (usec % 1000000) * 1000);
|
||||
if (tv.tv_usec * 1000 >= tv.tv_usec
|
||||
&& tv_nsec_new >= tv.tv_usec * 1000) {
|
||||
if (tv.tv_usec * 1000 >= tv.tv_usec && tv_nsec_new >= tv.tv_usec * 1000) {
|
||||
ts->tv_nsec = tv_nsec_new;
|
||||
}
|
||||
else {
|
||||
@ -218,7 +230,8 @@ static void msec_nsec_to_abstime(struct timespec *ts, uint64 usec)
|
||||
}
|
||||
}
|
||||
|
||||
int os_cond_reltimedwait(korp_cond *cond, korp_mutex *mutex, uint64 useconds)
|
||||
int
|
||||
os_cond_reltimedwait(korp_cond *cond, korp_mutex *mutex, uint64 useconds)
|
||||
{
|
||||
int ret;
|
||||
struct timespec abstime;
|
||||
@ -236,7 +249,8 @@ int os_cond_reltimedwait(korp_cond *cond, korp_mutex *mutex, uint64 useconds)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int os_cond_signal(korp_cond *cond)
|
||||
int
|
||||
os_cond_signal(korp_cond *cond)
|
||||
{
|
||||
assert(cond);
|
||||
|
||||
@ -246,17 +260,20 @@ int os_cond_signal(korp_cond *cond)
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int os_thread_join(korp_tid thread, void **value_ptr)
|
||||
int
|
||||
os_thread_join(korp_tid thread, void **value_ptr)
|
||||
{
|
||||
return pthread_join(thread, value_ptr);
|
||||
}
|
||||
|
||||
int os_thread_detach(korp_tid thread)
|
||||
int
|
||||
os_thread_detach(korp_tid thread)
|
||||
{
|
||||
return pthread_detach(thread);
|
||||
}
|
||||
|
||||
void os_thread_exit(void *retval)
|
||||
void
|
||||
os_thread_exit(void *retval)
|
||||
{
|
||||
#ifdef OS_ENABLE_HW_BOUND_CHECK
|
||||
os_thread_signal_destroy();
|
||||
@ -268,7 +285,8 @@ void os_thread_exit(void *retval)
|
||||
static os_thread_local_attribute uint8 *thread_stack_boundary = NULL;
|
||||
#endif
|
||||
|
||||
uint8 *os_thread_get_stack_boundary()
|
||||
uint8 *
|
||||
os_thread_get_stack_boundary()
|
||||
{
|
||||
pthread_t self;
|
||||
#ifdef __linux__
|
||||
@ -286,15 +304,15 @@ uint8 *os_thread_get_stack_boundary()
|
||||
|
||||
page_size = getpagesize();
|
||||
self = pthread_self();
|
||||
max_stack_size = (size_t)(APP_THREAD_STACK_SIZE_MAX + page_size - 1)
|
||||
& ~(page_size - 1);
|
||||
max_stack_size =
|
||||
(size_t)(APP_THREAD_STACK_SIZE_MAX + page_size - 1) & ~(page_size - 1);
|
||||
|
||||
if (max_stack_size < APP_THREAD_STACK_SIZE_DEFAULT)
|
||||
max_stack_size = APP_THREAD_STACK_SIZE_DEFAULT;
|
||||
|
||||
#ifdef __linux__
|
||||
if (pthread_getattr_np(self, &attr) == 0) {
|
||||
pthread_attr_getstack(&attr, (void**)&addr, &stack_size);
|
||||
pthread_attr_getstack(&attr, (void **)&addr, &stack_size);
|
||||
pthread_attr_getguardsize(&attr, &guard_size);
|
||||
pthread_attr_destroy(&attr);
|
||||
if (stack_size > max_stack_size)
|
||||
@ -306,7 +324,7 @@ uint8 *os_thread_get_stack_boundary()
|
||||
}
|
||||
(void)stack_size;
|
||||
#elif defined(__APPLE__) || defined(__NuttX__)
|
||||
if ((addr = (uint8*)pthread_get_stackaddr_np(self))) {
|
||||
if ((addr = (uint8 *)pthread_get_stackaddr_np(self))) {
|
||||
stack_size = pthread_get_stacksize_np(self);
|
||||
if (stack_size > max_stack_size)
|
||||
addr -= max_stack_size;
|
||||
@ -349,8 +367,7 @@ touch_pages(uint8 *stack_min_addr, uint32 page_size)
|
||||
{
|
||||
uint8 sum = 0;
|
||||
while (1) {
|
||||
volatile uint8 *touch_addr =
|
||||
(volatile uint8*)os_alloca(page_size / 2);
|
||||
volatile uint8 *touch_addr = (volatile uint8 *)os_alloca(page_size / 2);
|
||||
if (touch_addr < stack_min_addr + page_size) {
|
||||
sum += *(stack_min_addr + page_size - 1);
|
||||
break;
|
||||
@ -378,7 +395,8 @@ init_stack_guard_pages()
|
||||
(void)touch_pages(stack_min_addr, page_size);
|
||||
/* First time to call aot function, protect guard pages */
|
||||
if (os_mprotect(stack_min_addr, page_size * guard_page_count,
|
||||
MMAP_PROT_NONE) != 0) {
|
||||
MMAP_PROT_NONE)
|
||||
!= 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -413,8 +431,7 @@ signal_callback(int sig_num, siginfo_t *sig_info, void *sig_ucontext)
|
||||
|
||||
mask_signals(SIG_BLOCK);
|
||||
|
||||
if (signal_handler
|
||||
&& (sig_num == SIGSEGV || sig_num == SIGBUS)) {
|
||||
if (signal_handler && (sig_num == SIGSEGV || sig_num == SIGBUS)) {
|
||||
signal_handler(sig_addr);
|
||||
}
|
||||
|
||||
@ -427,8 +444,7 @@ signal_callback(int sig_num, siginfo_t *sig_info, void *sig_ucontext)
|
||||
os_printf("unhandled SIGBUS, si_addr: %p\n", sig_addr);
|
||||
break;
|
||||
default:
|
||||
os_printf("unhandle signal %d, si_addr: %p\n",
|
||||
sig_num, sig_addr);
|
||||
os_printf("unhandle signal %d, si_addr: %p\n", sig_num, sig_addr);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -452,8 +468,7 @@ os_thread_signal_init(os_signal_handler handler)
|
||||
}
|
||||
|
||||
/* Initialize memory for signal alternate stack of current thread */
|
||||
if (!(map_addr = os_mmap(NULL, map_size,
|
||||
MMAP_PROT_READ | MMAP_PROT_WRITE,
|
||||
if (!(map_addr = os_mmap(NULL, map_size, MMAP_PROT_READ | MMAP_PROT_WRITE,
|
||||
MMAP_MAP_NONE))) {
|
||||
os_printf("Failed to mmap memory for alternate stack\n");
|
||||
goto fail1;
|
||||
@ -533,7 +548,7 @@ void
|
||||
os_sigreturn()
|
||||
{
|
||||
#if defined(__APPLE__)
|
||||
#define UC_RESET_ALT_STACK 0x80000000
|
||||
#define UC_RESET_ALT_STACK 0x80000000
|
||||
extern int __sigreturn(void *, int);
|
||||
|
||||
/* It's necessary to call __sigreturn to restore the sigaltstack state
|
||||
@ -542,4 +557,3 @@ os_sigreturn()
|
||||
#endif
|
||||
}
|
||||
#endif /* end of OS_ENABLE_HW_BOUND_CHECK */
|
||||
|
||||
|
||||
@ -13,6 +13,5 @@ os_time_get_boot_microsecond()
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ((uint64) ts.tv_sec) * 1000 * 1000 + ((uint64)ts.tv_nsec) / 1000;
|
||||
return ((uint64)ts.tv_sec) * 1000 * 1000 + ((uint64)ts.tv_nsec) / 1000;
|
||||
}
|
||||
|
||||
|
||||
@ -13,8 +13,7 @@ bh_platform_init()
|
||||
|
||||
void
|
||||
bh_platform_destroy()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
int
|
||||
os_printf(const char *format, ...)
|
||||
@ -42,4 +41,3 @@ os_vprintf(const char *format, va_list ap)
|
||||
return BH_VPRINTF(format, ap);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -60,10 +60,8 @@ typedef pthread_t korp_thread;
|
||||
#define os_thread_local_attribute __thread
|
||||
|
||||
#if WASM_DISABLE_HW_BOUND_CHECK == 0
|
||||
#if defined(BUILD_TARGET_X86_64) \
|
||||
|| defined(BUILD_TARGET_AMD_64) \
|
||||
|| defined(BUILD_TARGET_AARCH64) \
|
||||
|| defined(BUILD_TARGET_RISCV64_LP64D) \
|
||||
#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64) \
|
||||
|| defined(BUILD_TARGET_AARCH64) || defined(BUILD_TARGET_RISCV64_LP64D) \
|
||||
|| defined(BUILD_TARGET_RISCV64_LP64)
|
||||
|
||||
#include <setjmp.h>
|
||||
@ -80,15 +78,20 @@ typedef jmp_buf korp_jmpbuf;
|
||||
|
||||
typedef void (*os_signal_handler)(void *sig_addr);
|
||||
|
||||
int os_thread_signal_init(os_signal_handler handler);
|
||||
int
|
||||
os_thread_signal_init(os_signal_handler handler);
|
||||
|
||||
void os_thread_signal_destroy();
|
||||
void
|
||||
os_thread_signal_destroy();
|
||||
|
||||
bool os_thread_signal_inited();
|
||||
bool
|
||||
os_thread_signal_inited();
|
||||
|
||||
void os_signal_unmask();
|
||||
void
|
||||
os_signal_unmask();
|
||||
|
||||
void os_sigreturn();
|
||||
void
|
||||
os_sigreturn();
|
||||
#endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64/RISCV64 */
|
||||
#endif /* end of WASM_DISABLE_HW_BOUND_CHECK */
|
||||
|
||||
@ -97,4 +100,3 @@ void os_sigreturn();
|
||||
#endif
|
||||
|
||||
#endif /* end of _PLATFORM_INTERNAL_H */
|
||||
|
||||
|
||||
@ -6,7 +6,6 @@
|
||||
#include "platform_api_vmcore.h"
|
||||
#include "platform_api_extension.h"
|
||||
|
||||
|
||||
int errno = 0;
|
||||
|
||||
int
|
||||
@ -27,7 +26,8 @@ bh_platform_destroy()
|
||||
os_thread_sys_destroy();
|
||||
}
|
||||
|
||||
int os_printf(const char *format, ...)
|
||||
int
|
||||
os_printf(const char *format, ...)
|
||||
{
|
||||
int ret = 0;
|
||||
va_list ap;
|
||||
@ -66,8 +66,7 @@ os_mprotect(void *addr, size_t size, int prot)
|
||||
|
||||
void
|
||||
os_dcache_flush()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
int
|
||||
atoi(const char *nptr)
|
||||
@ -112,11 +111,10 @@ memmove(void *dest, const void *src, size_t n)
|
||||
*d++ = *s++;
|
||||
}
|
||||
else {
|
||||
const char *lasts = s + (n-1);
|
||||
char *lastd = d + (n-1);
|
||||
const char *lasts = s + (n - 1);
|
||||
char *lastd = d + (n - 1);
|
||||
while (n--)
|
||||
*lastd-- = *lasts--;
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
||||
@ -6,9 +6,9 @@
|
||||
#include "platform_api_vmcore.h"
|
||||
#include "platform_api_extension.h"
|
||||
|
||||
uint8 *os_thread_get_stack_boundary()
|
||||
uint8 *
|
||||
os_thread_get_stack_boundary()
|
||||
{
|
||||
/* TODO: implement os_thread_get_stack_boundary */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@ -45,9 +45,12 @@ typedef struct korp_cond {
|
||||
os_thread_wait_list thread_wait_list;
|
||||
} korp_cond;
|
||||
|
||||
int os_printf(const char *format, ...);
|
||||
int os_vprintf(const char *format, va_list ap);
|
||||
int
|
||||
os_printf(const char *format, ...);
|
||||
int
|
||||
os_vprintf(const char *format, va_list ap);
|
||||
|
||||
/* clang-format off */
|
||||
/* math functions which are not provided by os */
|
||||
double sqrt(double x);
|
||||
double floor(double x);
|
||||
@ -93,5 +96,6 @@ uint32_t htonl(uint32_t hostlong);
|
||||
uint16_t htons(uint16_t hostshort);
|
||||
uint32_t ntohl(uint32_t netlong);
|
||||
uint16_t ntohs(uint16_t netshort);
|
||||
/* clang-format on */
|
||||
|
||||
#endif
|
||||
|
||||
@ -30,7 +30,6 @@ extern "C" {
|
||||
* 2. To build the app-mgr and app-framework, you must implement it
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Ceates a thread
|
||||
*
|
||||
@ -41,8 +40,9 @@ extern "C" {
|
||||
*
|
||||
* @return 0 if success.
|
||||
*/
|
||||
int os_thread_create(korp_tid *p_tid, thread_start_routine_t start, void *arg,
|
||||
unsigned int stack_size);
|
||||
int
|
||||
os_thread_create(korp_tid *p_tid, thread_start_routine_t start, void *arg,
|
||||
unsigned int stack_size);
|
||||
|
||||
/**
|
||||
* Creates a thread with priority
|
||||
@ -55,8 +55,9 @@ int os_thread_create(korp_tid *p_tid, thread_start_routine_t start, void *arg,
|
||||
*
|
||||
* @return 0 if success.
|
||||
*/
|
||||
int os_thread_create_with_prio(korp_tid *p_tid, thread_start_routine_t start,
|
||||
void *arg, unsigned int stack_size, int prio);
|
||||
int
|
||||
os_thread_create_with_prio(korp_tid *p_tid, thread_start_routine_t start,
|
||||
void *arg, unsigned int stack_size, int prio);
|
||||
|
||||
/**
|
||||
* Waits for the thread specified by thread to terminate
|
||||
@ -66,7 +67,8 @@ int os_thread_create_with_prio(korp_tid *p_tid, thread_start_routine_t start,
|
||||
*
|
||||
* @return return 0 if success
|
||||
*/
|
||||
int os_thread_join(korp_tid thread, void **retval);
|
||||
int
|
||||
os_thread_join(korp_tid thread, void **retval);
|
||||
|
||||
/**
|
||||
* Detach the thread specified by thread
|
||||
@ -82,7 +84,8 @@ int os_thread_detach(korp_tid);
|
||||
*
|
||||
* @param retval the return value of the current thread
|
||||
*/
|
||||
void os_thread_exit(void *retval);
|
||||
void
|
||||
os_thread_exit(void *retval);
|
||||
|
||||
/**
|
||||
* Initialize current thread environment if current thread
|
||||
@ -90,12 +93,14 @@ void os_thread_exit(void *retval);
|
||||
*
|
||||
* @return 0 if success, -1 otherwise
|
||||
*/
|
||||
int os_thread_env_init();
|
||||
int
|
||||
os_thread_env_init();
|
||||
|
||||
/**
|
||||
* Destroy current thread environment
|
||||
*/
|
||||
void os_thread_env_destroy();
|
||||
void
|
||||
os_thread_env_destroy();
|
||||
|
||||
/**
|
||||
* Suspend execution of the calling thread for (at least)
|
||||
@ -103,7 +108,8 @@ void os_thread_env_destroy();
|
||||
*
|
||||
* @return 0 if success, -1 otherwise
|
||||
*/
|
||||
int os_usleep(uint32 usec);
|
||||
int
|
||||
os_usleep(uint32 usec);
|
||||
|
||||
/**
|
||||
* Creates a recursive mutex
|
||||
@ -112,7 +118,8 @@ int os_usleep(uint32 usec);
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int os_recursive_mutex_init(korp_mutex *mutex);
|
||||
int
|
||||
os_recursive_mutex_init(korp_mutex *mutex);
|
||||
|
||||
/**
|
||||
* This function creates a condition variable
|
||||
@ -121,7 +128,8 @@ int os_recursive_mutex_init(korp_mutex *mutex);
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int os_cond_init(korp_cond *cond);
|
||||
int
|
||||
os_cond_init(korp_cond *cond);
|
||||
|
||||
/**
|
||||
* This function destroys condition variable
|
||||
@ -130,7 +138,8 @@ int os_cond_init(korp_cond *cond);
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int os_cond_destroy(korp_cond *cond);
|
||||
int
|
||||
os_cond_destroy(korp_cond *cond);
|
||||
|
||||
/**
|
||||
* Wait a condition variable.
|
||||
@ -140,7 +149,8 @@ int os_cond_destroy(korp_cond *cond);
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int os_cond_wait(korp_cond *cond, korp_mutex *mutex);
|
||||
int
|
||||
os_cond_wait(korp_cond *cond, korp_mutex *mutex);
|
||||
|
||||
/**
|
||||
* Wait a condition varible or return if time specified passes.
|
||||
@ -151,7 +161,8 @@ int os_cond_wait(korp_cond *cond, korp_mutex *mutex);
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int os_cond_reltimedwait(korp_cond *cond, korp_mutex *mutex, uint64 useconds);
|
||||
int
|
||||
os_cond_reltimedwait(korp_cond *cond, korp_mutex *mutex, uint64 useconds);
|
||||
|
||||
/**
|
||||
* Signals the condition variable
|
||||
@ -160,7 +171,8 @@ int os_cond_reltimedwait(korp_cond *cond, korp_mutex *mutex, uint64 useconds);
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int os_cond_signal(korp_cond *cond);
|
||||
int
|
||||
os_cond_signal(korp_cond *cond);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@ -25,23 +25,28 @@ extern "C" {
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int bh_platform_init(void);
|
||||
int
|
||||
bh_platform_init(void);
|
||||
|
||||
/**
|
||||
* Destroy the platform internal resources if needed,
|
||||
* this function is called by wasm_runtime_destroy()
|
||||
*/
|
||||
void bh_platform_destroy(void);
|
||||
void
|
||||
bh_platform_destroy(void);
|
||||
|
||||
/**
|
||||
******** memory allocator APIs **********
|
||||
*/
|
||||
|
||||
void *os_malloc(unsigned size);
|
||||
void *
|
||||
os_malloc(unsigned size);
|
||||
|
||||
void *os_realloc(void *ptr, unsigned size);
|
||||
void *
|
||||
os_realloc(void *ptr, unsigned size);
|
||||
|
||||
void os_free(void *ptr);
|
||||
void
|
||||
os_free(void *ptr);
|
||||
|
||||
/**
|
||||
* Note: the above APIs can simply return NULL if wasm runtime
|
||||
@ -49,28 +54,32 @@ void os_free(void *ptr);
|
||||
* Refer to wasm_runtime_full_init().
|
||||
*/
|
||||
|
||||
int
|
||||
os_printf(const char *format, ...);
|
||||
|
||||
int os_printf(const char *format, ...);
|
||||
|
||||
int os_vprintf(const char *format, va_list ap);
|
||||
int
|
||||
os_vprintf(const char *format, va_list ap);
|
||||
|
||||
/**
|
||||
* Get microseconds after boot.
|
||||
*/
|
||||
uint64 os_time_get_boot_microsecond(void);
|
||||
uint64
|
||||
os_time_get_boot_microsecond(void);
|
||||
|
||||
/**
|
||||
* Get current thread id.
|
||||
* Implementation optional: Used by runtime for logging only.
|
||||
*/
|
||||
korp_tid os_self_thread(void);
|
||||
korp_tid
|
||||
os_self_thread(void);
|
||||
|
||||
/**
|
||||
* Get current thread's stack boundary address, used for runtime
|
||||
* to check the native stack overflow. Return NULL if it is not
|
||||
* easy to implement, but may have potential issue.
|
||||
*/
|
||||
uint8 *os_thread_get_stack_boundary(void);
|
||||
uint8 *
|
||||
os_thread_get_stack_boundary(void);
|
||||
|
||||
/**
|
||||
************** mutext APIs ***********
|
||||
@ -78,14 +87,17 @@ uint8 *os_thread_get_stack_boundary(void);
|
||||
* app-mgr: Must be implemented
|
||||
*/
|
||||
|
||||
int os_mutex_init(korp_mutex *mutex);
|
||||
int
|
||||
os_mutex_init(korp_mutex *mutex);
|
||||
|
||||
int os_mutex_destroy(korp_mutex *mutex);
|
||||
int
|
||||
os_mutex_destroy(korp_mutex *mutex);
|
||||
|
||||
int os_mutex_lock(korp_mutex *mutex);
|
||||
|
||||
int os_mutex_unlock(korp_mutex *mutex);
|
||||
int
|
||||
os_mutex_lock(korp_mutex *mutex);
|
||||
|
||||
int
|
||||
os_mutex_unlock(korp_mutex *mutex);
|
||||
|
||||
/**************************************************
|
||||
* Section 2 *
|
||||
@ -110,9 +122,12 @@ enum {
|
||||
MMAP_MAP_FIXED = 2
|
||||
};
|
||||
|
||||
void *os_mmap(void *hint, size_t size, int prot, int flags);
|
||||
void os_munmap(void *addr, size_t size);
|
||||
int os_mprotect(void *addr, size_t size, int prot);
|
||||
void *
|
||||
os_mmap(void *hint, size_t size, int prot, int flags);
|
||||
void
|
||||
os_munmap(void *addr, size_t size);
|
||||
int
|
||||
os_mprotect(void *addr, size_t size, int prot);
|
||||
|
||||
/**
|
||||
* Flush cpu data cache, in some CPUs, after applying relocation to the
|
||||
@ -120,7 +135,8 @@ int os_mprotect(void *addr, size_t size, int prot);
|
||||
* which may cause unexpected behaviour when executing the AOT code.
|
||||
* Implement this function if required, or just leave it empty.
|
||||
*/
|
||||
void os_dcache_flush(void);
|
||||
void
|
||||
os_dcache_flush(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@ -42,24 +42,27 @@ extern "C" {
|
||||
__declspec(dllexport) void *BH_MALLOC(unsigned int size);
|
||||
__declspec(dllexport) void BH_FREE(void *ptr);
|
||||
#else
|
||||
__declspec(dllimport) void* BH_MALLOC(unsigned int size);
|
||||
__declspec(dllimport) void BH_FREE(void* ptr);
|
||||
__declspec(dllimport) void *BH_MALLOC(unsigned int size);
|
||||
__declspec(dllimport) void BH_FREE(void *ptr);
|
||||
#endif
|
||||
#else
|
||||
void *BH_MALLOC(unsigned int size);
|
||||
void BH_FREE(void *ptr);
|
||||
void *
|
||||
BH_MALLOC(unsigned int size);
|
||||
void
|
||||
BH_FREE(void *ptr);
|
||||
#endif
|
||||
|
||||
#if defined(BH_VPRINTF)
|
||||
#if defined(MSVC)
|
||||
__declspec(dllimport) int BH_VPRINTF(const char *format, va_list ap);
|
||||
#else
|
||||
int BH_VPRINTF(const char *format, va_list ap);
|
||||
int
|
||||
BH_VPRINTF(const char *format, va_list ap);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL (void*)0
|
||||
#define NULL (void *)0
|
||||
#endif
|
||||
|
||||
#ifndef __cplusplus
|
||||
@ -99,8 +102,7 @@ typedef double float64;
|
||||
typedef uint64_t uint64;
|
||||
typedef int64_t int64;
|
||||
|
||||
typedef void* (*thread_start_routine_t)(void*);
|
||||
|
||||
typedef void *(*thread_start_routine_t)(void *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ extern "C" {
|
||||
#define _STACK_SIZE_ADJUSTMENT (32 * 1024)
|
||||
|
||||
/* Stack size of applet threads's native part. */
|
||||
#define BH_APPLET_PRESERVED_STACK_SIZE (8 * 1024 + _STACK_SIZE_ADJUSTMENT)
|
||||
#define BH_APPLET_PRESERVED_STACK_SIZE (8 * 1024 + _STACK_SIZE_ADJUSTMENT)
|
||||
|
||||
/* Default thread priority */
|
||||
#define BH_THREAD_DEFAULT_PRIORITY 0
|
||||
@ -50,14 +50,15 @@ typedef pthread_t korp_tid;
|
||||
typedef pthread_mutex_t korp_mutex;
|
||||
typedef pthread_cond_t korp_cond;
|
||||
|
||||
typedef void (*os_print_function_t)(const char* message);
|
||||
void os_set_print_function(os_print_function_t pf);
|
||||
typedef void (*os_print_function_t)(const char *message);
|
||||
void
|
||||
os_set_print_function(os_print_function_t pf);
|
||||
|
||||
char *strcpy(char *dest, const char *src);
|
||||
char *
|
||||
strcpy(char *dest, const char *src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* end of _PLATFORM_INTERNAL_H */
|
||||
|
||||
|
||||
@ -13,97 +13,129 @@
|
||||
#define TRACE_OCALL_FAIL() os_printf("ocall %s failed!\n", __FUNCTION__)
|
||||
|
||||
/** fd **/
|
||||
int ocall_open(int *p_fd, const char *pathname, int flags,
|
||||
bool has_mode, unsigned mode);
|
||||
int
|
||||
ocall_open(int *p_fd, const char *pathname, int flags, bool has_mode,
|
||||
unsigned mode);
|
||||
|
||||
int ocall_openat(int *p_fd, int dirfd, const char *pathname, int flags,
|
||||
bool has_mode, unsigned mode);
|
||||
int
|
||||
ocall_openat(int *p_fd, int dirfd, const char *pathname, int flags,
|
||||
bool has_mode, unsigned mode);
|
||||
|
||||
int ocall_read(ssize_t *p_ret, int fd, void *buf, size_t read_size);
|
||||
int
|
||||
ocall_read(ssize_t *p_ret, int fd, void *buf, size_t read_size);
|
||||
|
||||
int ocall_close(int *p_ret, int fd);
|
||||
int
|
||||
ocall_close(int *p_ret, int fd);
|
||||
|
||||
int ocall_lseek(off_t *p_ret, int fd, off_t offset, int whence);
|
||||
int
|
||||
ocall_lseek(off_t *p_ret, int fd, off_t offset, int whence);
|
||||
|
||||
int ocall_ftruncate(int *p_ret, int fd, off_t length);
|
||||
int
|
||||
ocall_ftruncate(int *p_ret, int fd, off_t length);
|
||||
|
||||
int ocall_fsync(int *p_ret, int fd);
|
||||
int
|
||||
ocall_fsync(int *p_ret, int fd);
|
||||
|
||||
int ocall_fdatasync(int *p_ret, int fd);
|
||||
int
|
||||
ocall_fdatasync(int *p_ret, int fd);
|
||||
|
||||
int ocall_isatty(int *p_ret, int fd);
|
||||
int
|
||||
ocall_isatty(int *p_ret, int fd);
|
||||
/** fd end **/
|
||||
|
||||
/** DIR **/
|
||||
int ocall_fdopendir(int fd, void **p_dirp);
|
||||
int
|
||||
ocall_fdopendir(int fd, void **p_dirp);
|
||||
|
||||
int ocall_readdir(void **p_dirent, void *dirp);
|
||||
int
|
||||
ocall_readdir(void **p_dirent, void *dirp);
|
||||
|
||||
int ocall_rewinddir(void *dirp);
|
||||
int
|
||||
ocall_rewinddir(void *dirp);
|
||||
|
||||
int ocall_seekdir(void *dirp, long loc);
|
||||
int
|
||||
ocall_seekdir(void *dirp, long loc);
|
||||
|
||||
int ocall_telldir(long *p_dir, void *dirp);
|
||||
int
|
||||
ocall_telldir(long *p_dir, void *dirp);
|
||||
|
||||
int ocall_closedir(int *p_ret, void *dirp);
|
||||
int
|
||||
ocall_closedir(int *p_ret, void *dirp);
|
||||
/** DIR end **/
|
||||
|
||||
/** stat **/
|
||||
int ocall_stat(int *p_ret, const char *pathname,
|
||||
void *buf, unsigned int buf_len);
|
||||
int ocall_fstat(int *p_ret, int fd, void *buf, unsigned int buf_len);
|
||||
int ocall_fstatat(int *p_ret, int dirfd, const char *pathname,
|
||||
void *buf, unsigned int buf_len, int flags);
|
||||
int
|
||||
ocall_stat(int *p_ret, const char *pathname, void *buf, unsigned int buf_len);
|
||||
int
|
||||
ocall_fstat(int *p_ret, int fd, void *buf, unsigned int buf_len);
|
||||
int
|
||||
ocall_fstatat(int *p_ret, int dirfd, const char *pathname, void *buf,
|
||||
unsigned int buf_len, int flags);
|
||||
/** stat end **/
|
||||
|
||||
/** link **/
|
||||
int ocall_mkdirat(int *p_ret, int dirfd, const char * pathname,
|
||||
unsigned mode);
|
||||
int ocall_link(int *p_ret, const char *oldpath, const char *newpath);
|
||||
int ocall_linkat(int *p_ret, int olddirfd, const char *oldpath,
|
||||
int newdirfd, const char *newpath, int flags);
|
||||
int ocall_unlinkat(int *p_ret, int dirfd, const char *pathname,
|
||||
int flags);
|
||||
int ocall_readlinkat(ssize_t *p_ret, int dirfd, const char *pathname,
|
||||
char *buf, size_t bufsiz);
|
||||
int ocall_renameat(int *p_ret, int olddirfd,const char *oldpath,
|
||||
int newdirfd,const char *newpath);
|
||||
int ocall_symlinkat(int *p_ret, const char *target, int newdirfd,
|
||||
const char *linkpath);
|
||||
int
|
||||
ocall_mkdirat(int *p_ret, int dirfd, const char *pathname, unsigned mode);
|
||||
int
|
||||
ocall_link(int *p_ret, const char *oldpath, const char *newpath);
|
||||
int
|
||||
ocall_linkat(int *p_ret, int olddirfd, const char *oldpath, int newdirfd,
|
||||
const char *newpath, int flags);
|
||||
int
|
||||
ocall_unlinkat(int *p_ret, int dirfd, const char *pathname, int flags);
|
||||
int
|
||||
ocall_readlinkat(ssize_t *p_ret, int dirfd, const char *pathname, char *buf,
|
||||
size_t bufsiz);
|
||||
int
|
||||
ocall_renameat(int *p_ret, int olddirfd, const char *oldpath, int newdirfd,
|
||||
const char *newpath);
|
||||
int
|
||||
ocall_symlinkat(int *p_ret, const char *target, int newdirfd,
|
||||
const char *linkpath);
|
||||
/** link end **/
|
||||
|
||||
/** control **/
|
||||
int ocall_ioctl(int *p_ret, int fd, unsigned long request, void *arg,
|
||||
unsigned int arg_len);
|
||||
int ocall_fcntl(int *p_ret, int fd, int cmd);
|
||||
int ocall_fcntl_long(int *p_ret, int fd, int cmd, long arg);
|
||||
int
|
||||
ocall_ioctl(int *p_ret, int fd, unsigned long request, void *arg,
|
||||
unsigned int arg_len);
|
||||
int
|
||||
ocall_fcntl(int *p_ret, int fd, int cmd);
|
||||
int
|
||||
ocall_fcntl_long(int *p_ret, int fd, int cmd, long arg);
|
||||
/** control end **/
|
||||
|
||||
/** **/
|
||||
int ocall_realpath(int *p_ret, const char *path, char *buf,
|
||||
unsigned int buf_len);
|
||||
int ocall_posix_fallocate(int *p_ret, int fd, off_t offset, off_t len);
|
||||
int ocall_poll(int *p_ret, void *fds, unsigned nfds, int timeout,
|
||||
unsigned int fds_len);
|
||||
int ocall_getopt(int *p_ret, int argc, char *argv_buf,
|
||||
unsigned int argv_buf_len, const char *optstring);
|
||||
int ocall_getrandom(ssize_t *p_ret, void *buf, size_t buflen,
|
||||
unsigned int flags);
|
||||
int ocall_getentropy(int *p_ret, void *buffer, size_t length);
|
||||
int ocall_sched_yield(int *p_ret);
|
||||
int
|
||||
ocall_realpath(int *p_ret, const char *path, char *buf, unsigned int buf_len);
|
||||
int
|
||||
ocall_posix_fallocate(int *p_ret, int fd, off_t offset, off_t len);
|
||||
int
|
||||
ocall_poll(int *p_ret, void *fds, unsigned nfds, int timeout,
|
||||
unsigned int fds_len);
|
||||
int
|
||||
ocall_getopt(int *p_ret, int argc, char *argv_buf, unsigned int argv_buf_len,
|
||||
const char *optstring);
|
||||
int
|
||||
ocall_getrandom(ssize_t *p_ret, void *buf, size_t buflen, unsigned int flags);
|
||||
int
|
||||
ocall_getentropy(int *p_ret, void *buffer, size_t length);
|
||||
int
|
||||
ocall_sched_yield(int *p_ret);
|
||||
|
||||
/** struct iovec **/
|
||||
ssize_t ocall_readv(ssize_t *p_ret, int fd, char *iov_buf,
|
||||
unsigned int buf_size, int iovcnt,
|
||||
bool has_offset, off_t offset);
|
||||
ssize_t ocall_writev(ssize_t *p_ret, int fd, char *iov_buf,
|
||||
unsigned int buf_size, int iovcnt,
|
||||
bool has_offset, off_t offset);
|
||||
ssize_t
|
||||
ocall_readv(ssize_t *p_ret, int fd, char *iov_buf, unsigned int buf_size,
|
||||
int iovcnt, bool has_offset, off_t offset);
|
||||
ssize_t
|
||||
ocall_writev(ssize_t *p_ret, int fd, char *iov_buf, unsigned int buf_size,
|
||||
int iovcnt, bool has_offset, off_t offset);
|
||||
/** iovec end **/
|
||||
|
||||
int ocall_get_errno(int *p_ret);
|
||||
int
|
||||
ocall_get_errno(int *p_ret);
|
||||
|
||||
int open(const char *pathname, int flags, ...)
|
||||
int
|
||||
open(const char *pathname, int flags, ...)
|
||||
{
|
||||
int fd;
|
||||
bool has_mode = false;
|
||||
@ -130,7 +162,8 @@ int open(const char *pathname, int flags, ...)
|
||||
return fd;
|
||||
}
|
||||
|
||||
int openat(int dirfd, const char *pathname, int flags, ...)
|
||||
int
|
||||
openat(int dirfd, const char *pathname, int flags, ...)
|
||||
{
|
||||
int fd;
|
||||
bool has_mode = false;
|
||||
@ -144,8 +177,8 @@ int openat(int dirfd, const char *pathname, int flags, ...)
|
||||
has_mode = true;
|
||||
}
|
||||
|
||||
if (SGX_SUCCESS != ocall_openat(&fd, dirfd, pathname, flags,
|
||||
has_mode, mode)) {
|
||||
if (SGX_SUCCESS
|
||||
!= ocall_openat(&fd, dirfd, pathname, flags, has_mode, mode)) {
|
||||
TRACE_OCALL_FAIL();
|
||||
return -1;
|
||||
}
|
||||
@ -158,7 +191,8 @@ int openat(int dirfd, const char *pathname, int flags, ...)
|
||||
return fd;
|
||||
}
|
||||
|
||||
int close(int fd)
|
||||
int
|
||||
close(int fd)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -171,7 +205,8 @@ int close(int fd)
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t read(int fd, void *buf, size_t size)
|
||||
ssize_t
|
||||
read(int fd, void *buf, size_t size)
|
||||
{
|
||||
ssize_t ret;
|
||||
int size_read_max = 2048, size_read, total_size_read = 0, count, i;
|
||||
@ -184,9 +219,7 @@ ssize_t read(int fd, void *buf, size_t size)
|
||||
|
||||
count = (size + size_read_max - 1) / size_read_max;
|
||||
for (i = 0; i < count; i++) {
|
||||
size_read = (i < count - 1)
|
||||
? size_read_max
|
||||
: size - size_read_max * i;
|
||||
size_read = (i < count - 1) ? size_read_max : size - size_read_max * i;
|
||||
|
||||
if (ocall_read(&ret, fd, p, size_read) != SGX_SUCCESS) {
|
||||
TRACE_OCALL_FAIL();
|
||||
@ -208,7 +241,8 @@ ssize_t read(int fd, void *buf, size_t size)
|
||||
return total_size_read;
|
||||
}
|
||||
|
||||
DIR *fdopendir(int fd)
|
||||
DIR *
|
||||
fdopendir(int fd)
|
||||
{
|
||||
DIR *result = NULL;
|
||||
|
||||
@ -232,7 +266,8 @@ DIR *fdopendir(int fd)
|
||||
return result;
|
||||
}
|
||||
|
||||
struct dirent *readdir(DIR *dirp)
|
||||
struct dirent *
|
||||
readdir(DIR *dirp)
|
||||
{
|
||||
struct dirent *result;
|
||||
|
||||
@ -249,21 +284,24 @@ struct dirent *readdir(DIR *dirp)
|
||||
return result;
|
||||
}
|
||||
|
||||
void rewinddir(DIR *dirp)
|
||||
void
|
||||
rewinddir(DIR *dirp)
|
||||
{
|
||||
if (ocall_rewinddir((void *)*dirp) != SGX_SUCCESS) {
|
||||
TRACE_OCALL_FAIL();
|
||||
}
|
||||
}
|
||||
|
||||
void seekdir(DIR *dirp, long loc)
|
||||
void
|
||||
seekdir(DIR *dirp, long loc)
|
||||
{
|
||||
if (ocall_seekdir((void *)*dirp, loc) != SGX_SUCCESS) {
|
||||
TRACE_OCALL_FAIL();
|
||||
}
|
||||
}
|
||||
|
||||
long telldir(DIR *dirp)
|
||||
long
|
||||
telldir(DIR *dirp)
|
||||
{
|
||||
long ret;
|
||||
|
||||
@ -276,7 +314,8 @@ long telldir(DIR *dirp)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int closedir(DIR *dirp)
|
||||
int
|
||||
closedir(DIR *dirp)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -291,8 +330,8 @@ int closedir(DIR *dirp)
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
readv_internal(int fd, const struct iovec *iov, int iovcnt,
|
||||
bool has_offset, off_t offset)
|
||||
readv_internal(int fd, const struct iovec *iov, int iovcnt, bool has_offset,
|
||||
off_t offset)
|
||||
{
|
||||
ssize_t ret, size_left;
|
||||
struct iovec *iov1;
|
||||
@ -317,7 +356,7 @@ readv_internal(int fd, const struct iovec *iov, int iovcnt,
|
||||
|
||||
memset(iov1, 0, (uint32)total_size);
|
||||
|
||||
p = (char*)(uintptr_t)(sizeof(struct iovec) * iovcnt);
|
||||
p = (char *)(uintptr_t)(sizeof(struct iovec) * iovcnt);
|
||||
|
||||
for (i = 0; i < iovcnt; i++) {
|
||||
iov1[i].iov_len = iov[i].iov_len;
|
||||
@ -325,8 +364,9 @@ readv_internal(int fd, const struct iovec *iov, int iovcnt,
|
||||
p += iov[i].iov_len;
|
||||
}
|
||||
|
||||
if (ocall_readv(&ret, fd, (char *)iov1, (uint32)total_size,
|
||||
iovcnt, has_offset, offset) != SGX_SUCCESS) {
|
||||
if (ocall_readv(&ret, fd, (char *)iov1, (uint32)total_size, iovcnt,
|
||||
has_offset, offset)
|
||||
!= SGX_SUCCESS) {
|
||||
TRACE_OCALL_FAIL();
|
||||
BH_FREE(iov1);
|
||||
return -1;
|
||||
@ -343,8 +383,7 @@ readv_internal(int fd, const struct iovec *iov, int iovcnt,
|
||||
size_left -= iov[i].iov_len;
|
||||
}
|
||||
else {
|
||||
memcpy(iov[i].iov_base, (uintptr_t)p + (char *)iov1,
|
||||
size_left);
|
||||
memcpy(iov[i].iov_base, (uintptr_t)p + (char *)iov1, size_left);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -356,8 +395,8 @@ readv_internal(int fd, const struct iovec *iov, int iovcnt,
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
writev_internal(int fd, const struct iovec *iov, int iovcnt,
|
||||
bool has_offset, off_t offset)
|
||||
writev_internal(int fd, const struct iovec *iov, int iovcnt, bool has_offset,
|
||||
off_t offset)
|
||||
{
|
||||
ssize_t ret;
|
||||
struct iovec *iov1;
|
||||
@ -387,13 +426,13 @@ writev_internal(int fd, const struct iovec *iov, int iovcnt,
|
||||
for (i = 0; i < iovcnt; i++) {
|
||||
iov1[i].iov_len = iov[i].iov_len;
|
||||
iov1[i].iov_base = p;
|
||||
memcpy((uintptr_t)p + (char *)iov1, iov[i].iov_base,
|
||||
iov[i].iov_len);
|
||||
memcpy((uintptr_t)p + (char *)iov1, iov[i].iov_base, iov[i].iov_len);
|
||||
p += iov[i].iov_len;
|
||||
}
|
||||
|
||||
if (ocall_writev(&ret, fd, (char *)iov1, (uint32)total_size,
|
||||
iovcnt, has_offset, offset) != SGX_SUCCESS) {
|
||||
if (ocall_writev(&ret, fd, (char *)iov1, (uint32)total_size, iovcnt,
|
||||
has_offset, offset)
|
||||
!= SGX_SUCCESS) {
|
||||
TRACE_OCALL_FAIL();
|
||||
BH_FREE(iov1);
|
||||
return -1;
|
||||
@ -405,29 +444,32 @@ writev_internal(int fd, const struct iovec *iov, int iovcnt,
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t readv(int fd, const struct iovec *iov, int iovcnt)
|
||||
ssize_t
|
||||
readv(int fd, const struct iovec *iov, int iovcnt)
|
||||
{
|
||||
return readv_internal(fd, iov, iovcnt, false, 0);
|
||||
}
|
||||
|
||||
ssize_t writev(int fd, const struct iovec *iov, int iovcnt)
|
||||
ssize_t
|
||||
writev(int fd, const struct iovec *iov, int iovcnt)
|
||||
{
|
||||
return writev_internal(fd, iov, iovcnt, false, 0);
|
||||
}
|
||||
|
||||
ssize_t preadv(int fd, const struct iovec *iov, int iovcnt,
|
||||
off_t offset)
|
||||
ssize_t
|
||||
preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset)
|
||||
{
|
||||
return readv_internal(fd, iov, iovcnt, true, offset);
|
||||
}
|
||||
|
||||
ssize_t pwritev(int fd, const struct iovec *iov, int iovcnt,
|
||||
off_t offset)
|
||||
ssize_t
|
||||
pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset)
|
||||
{
|
||||
return writev_internal(fd, iov, iovcnt, true, offset);
|
||||
}
|
||||
|
||||
off_t lseek(int fd, off_t offset, int whence)
|
||||
off_t
|
||||
lseek(int fd, off_t offset, int whence)
|
||||
{
|
||||
off_t ret;
|
||||
if (ocall_lseek(&ret, fd, (long)offset, whence) != SGX_SUCCESS) {
|
||||
@ -439,7 +481,8 @@ off_t lseek(int fd, off_t offset, int whence)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ftruncate(int fd, off_t length)
|
||||
int
|
||||
ftruncate(int fd, off_t length)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -452,16 +495,16 @@ int ftruncate(int fd, off_t length)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int stat(const char *pathname, struct stat *statbuf)
|
||||
int
|
||||
stat(const char *pathname, struct stat *statbuf)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (statbuf == NULL)
|
||||
return -1;
|
||||
|
||||
if (ocall_stat(&ret, pathname,
|
||||
(void *)statbuf,
|
||||
sizeof(struct stat)) != SGX_SUCCESS) {
|
||||
if (ocall_stat(&ret, pathname, (void *)statbuf, sizeof(struct stat))
|
||||
!= SGX_SUCCESS) {
|
||||
TRACE_OCALL_FAIL();
|
||||
return -1;
|
||||
}
|
||||
@ -471,15 +514,16 @@ int stat(const char *pathname, struct stat *statbuf)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int fstat(int fd, struct stat *statbuf)
|
||||
int
|
||||
fstat(int fd, struct stat *statbuf)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (statbuf == NULL)
|
||||
return -1;
|
||||
|
||||
if (ocall_fstat(&ret, fd, (void *)statbuf,
|
||||
sizeof(struct stat)) != SGX_SUCCESS) {
|
||||
if (ocall_fstat(&ret, fd, (void *)statbuf, sizeof(struct stat))
|
||||
!= SGX_SUCCESS) {
|
||||
TRACE_OCALL_FAIL();
|
||||
return -1;
|
||||
}
|
||||
@ -489,8 +533,8 @@ int fstat(int fd, struct stat *statbuf)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int fstatat(int dirfd, const char *pathname, struct stat *statbuf,
|
||||
int flags)
|
||||
int
|
||||
fstatat(int dirfd, const char *pathname, struct stat *statbuf, int flags)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -498,7 +542,8 @@ int fstatat(int dirfd, const char *pathname, struct stat *statbuf,
|
||||
return -1;
|
||||
|
||||
if (ocall_fstatat(&ret, dirfd, pathname, (void *)statbuf,
|
||||
sizeof(struct stat), flags) != SGX_SUCCESS) {
|
||||
sizeof(struct stat), flags)
|
||||
!= SGX_SUCCESS) {
|
||||
TRACE_OCALL_FAIL();
|
||||
return -1;
|
||||
}
|
||||
@ -508,7 +553,8 @@ int fstatat(int dirfd, const char *pathname, struct stat *statbuf,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int fsync(int fd)
|
||||
int
|
||||
fsync(int fd)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -521,7 +567,8 @@ int fsync(int fd)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int fdatasync(int fd)
|
||||
int
|
||||
fdatasync(int fd)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -534,7 +581,8 @@ int fdatasync(int fd)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int mkdirat(int dirfd, const char *pathname, mode_t mode)
|
||||
int
|
||||
mkdirat(int dirfd, const char *pathname, mode_t mode)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -548,7 +596,8 @@ int mkdirat(int dirfd, const char *pathname, mode_t mode)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int link(const char *oldpath, const char *newpath)
|
||||
int
|
||||
link(const char *oldpath, const char *newpath)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -562,13 +611,14 @@ int link(const char *oldpath, const char *newpath)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int linkat(int olddirfd, const char *oldpath,
|
||||
int newdirfd, const char *newpath, int flags)
|
||||
int
|
||||
linkat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath,
|
||||
int flags)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (ocall_linkat(&ret, olddirfd, oldpath, newdirfd, newpath,
|
||||
flags) != SGX_SUCCESS) {
|
||||
if (ocall_linkat(&ret, olddirfd, oldpath, newdirfd, newpath, flags)
|
||||
!= SGX_SUCCESS) {
|
||||
TRACE_OCALL_FAIL();
|
||||
return -1;
|
||||
}
|
||||
@ -578,7 +628,8 @@ int linkat(int olddirfd, const char *oldpath,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int unlinkat(int dirfd, const char *pathname, int flags)
|
||||
int
|
||||
unlinkat(int dirfd, const char *pathname, int flags)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -592,16 +643,15 @@ int unlinkat(int dirfd, const char *pathname, int flags)
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t readlinkat(int dirfd, const char *pathname,
|
||||
char *buf, size_t bufsiz)
|
||||
ssize_t
|
||||
readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz)
|
||||
{
|
||||
ssize_t ret;
|
||||
|
||||
if (buf == NULL)
|
||||
return -1;
|
||||
|
||||
if (ocall_readlinkat(&ret, dirfd, pathname, buf,
|
||||
bufsiz) != SGX_SUCCESS) {
|
||||
if (ocall_readlinkat(&ret, dirfd, pathname, buf, bufsiz) != SGX_SUCCESS) {
|
||||
TRACE_OCALL_FAIL();
|
||||
return -1;
|
||||
}
|
||||
@ -611,12 +661,12 @@ ssize_t readlinkat(int dirfd, const char *pathname,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int symlinkat(const char *target, int newdirfd, const char *linkpath)
|
||||
int
|
||||
symlinkat(const char *target, int newdirfd, const char *linkpath)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (ocall_symlinkat(&ret, target,
|
||||
newdirfd, linkpath) != SGX_SUCCESS) {
|
||||
if (ocall_symlinkat(&ret, target, newdirfd, linkpath) != SGX_SUCCESS) {
|
||||
TRACE_OCALL_FAIL();
|
||||
return -1;
|
||||
}
|
||||
@ -626,13 +676,13 @@ int symlinkat(const char *target, int newdirfd, const char *linkpath)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int renameat(int olddirfd, const char *oldpath,
|
||||
int newdirfd, const char *newpath)
|
||||
int
|
||||
renameat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (ocall_renameat(&ret, olddirfd, oldpath,
|
||||
newdirfd, newpath) != SGX_SUCCESS) {
|
||||
if (ocall_renameat(&ret, olddirfd, oldpath, newdirfd, newpath)
|
||||
!= SGX_SUCCESS) {
|
||||
TRACE_OCALL_FAIL();
|
||||
return -1;
|
||||
}
|
||||
@ -642,7 +692,8 @@ int renameat(int olddirfd, const char *oldpath,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ioctl(int fd, unsigned long request, ...)
|
||||
int
|
||||
ioctl(int fd, unsigned long request, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list args;
|
||||
@ -651,8 +702,8 @@ int ioctl(int fd, unsigned long request, ...)
|
||||
case FIONREAD:
|
||||
va_start(args, request);
|
||||
int *arg = (int *)va_arg(args, int *);
|
||||
if (ocall_ioctl(&ret, fd, request, arg,
|
||||
sizeof(*arg)) != SGX_SUCCESS) {
|
||||
if (ocall_ioctl(&ret, fd, request, arg, sizeof(*arg))
|
||||
!= SGX_SUCCESS) {
|
||||
TRACE_OCALL_FAIL();
|
||||
va_end(args);
|
||||
return -1;
|
||||
@ -670,7 +721,8 @@ int ioctl(int fd, unsigned long request, ...)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int fcntl(int fd, int cmd, ... /* arg */ )
|
||||
int
|
||||
fcntl(int fd, int cmd, ... /* arg */)
|
||||
{
|
||||
int ret;
|
||||
va_list args;
|
||||
@ -707,7 +759,8 @@ int fcntl(int fd, int cmd, ... /* arg */ )
|
||||
return ret;
|
||||
}
|
||||
|
||||
int isatty(int fd)
|
||||
int
|
||||
isatty(int fd)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -720,7 +773,8 @@ int isatty(int fd)
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *realpath(const char *path, char *resolved_path)
|
||||
char *
|
||||
realpath(const char *path, char *resolved_path)
|
||||
{
|
||||
int ret;
|
||||
char buf[PATH_MAX] = { 0 };
|
||||
@ -746,7 +800,8 @@ char *realpath(const char *path, char *resolved_path)
|
||||
return resolved_path;
|
||||
}
|
||||
|
||||
int posix_fallocate(int fd, off_t offset, off_t len)
|
||||
int
|
||||
posix_fallocate(int fd, off_t offset, off_t len)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -758,15 +813,16 @@ int posix_fallocate(int fd, off_t offset, off_t len)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int poll(struct pollfd *fds, nfds_t nfds, int timeout)
|
||||
int
|
||||
poll(struct pollfd *fds, nfds_t nfds, int timeout)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (fds == NULL)
|
||||
return -1;
|
||||
|
||||
if (ocall_poll(&ret, fds, nfds, timeout,
|
||||
sizeof(*fds) * nfds) != SGX_SUCCESS) {
|
||||
if (ocall_poll(&ret, fds, nfds, timeout, sizeof(*fds) * nfds)
|
||||
!= SGX_SUCCESS) {
|
||||
TRACE_OCALL_FAIL();
|
||||
return -1;
|
||||
}
|
||||
@ -776,8 +832,8 @@ int poll(struct pollfd *fds, nfds_t nfds, int timeout)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int getopt(int argc, char * const argv[],
|
||||
const char *optstring)
|
||||
int
|
||||
getopt(int argc, char *const argv[], const char *optstring)
|
||||
{
|
||||
int ret;
|
||||
char **argv1;
|
||||
@ -805,8 +861,8 @@ int getopt(int argc, char * const argv[],
|
||||
p += ((uintptr_t)strlen(argv[i]) + 1);
|
||||
}
|
||||
|
||||
if (ocall_getopt(&ret, argc, (char *)argv1, total_size,
|
||||
optstring) != SGX_SUCCESS) {
|
||||
if (ocall_getopt(&ret, argc, (char *)argv1, total_size, optstring)
|
||||
!= SGX_SUCCESS) {
|
||||
TRACE_OCALL_FAIL();
|
||||
BH_FREE(argv1);
|
||||
return -1;
|
||||
@ -818,7 +874,8 @@ int getopt(int argc, char * const argv[],
|
||||
return ret;
|
||||
}
|
||||
|
||||
int sched_yield(void)
|
||||
int
|
||||
sched_yield(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -831,7 +888,8 @@ int sched_yield(void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t getrandom(void *buf, size_t buflen, unsigned int flags)
|
||||
ssize_t
|
||||
getrandom(void *buf, size_t buflen, unsigned int flags)
|
||||
{
|
||||
ssize_t ret;
|
||||
|
||||
@ -844,7 +902,8 @@ ssize_t getrandom(void *buf, size_t buflen, unsigned int flags)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int getentropy(void *buffer, size_t length)
|
||||
int
|
||||
getentropy(void *buffer, size_t length)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -857,7 +916,8 @@ int getentropy(void *buffer, size_t length)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int get_errno(void)
|
||||
int
|
||||
get_errno(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -869,4 +929,3 @@ int get_errno(void)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -12,45 +12,45 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define F_DUPFD 0
|
||||
#define F_GETFD 1
|
||||
#define F_SETFD 2
|
||||
#define F_GETFL 3
|
||||
#define F_SETFL 4
|
||||
#define F_DUPFD 0
|
||||
#define F_GETFD 1
|
||||
#define F_SETFD 2
|
||||
#define F_GETFL 3
|
||||
#define F_SETFL 4
|
||||
|
||||
#define FD_CLOEXEC 1
|
||||
|
||||
#define O_PATH 010000000
|
||||
#define O_SEARCH O_PATH
|
||||
#define O_EXEC O_PATH
|
||||
#define O_PATH 010000000
|
||||
#define O_SEARCH O_PATH
|
||||
#define O_EXEC O_PATH
|
||||
|
||||
#define O_ACCMODE (03|O_SEARCH)
|
||||
#define O_RDONLY 00
|
||||
#define O_WRONLY 01
|
||||
#define O_RDWR 02
|
||||
#define O_ACCMODE (03 | O_SEARCH)
|
||||
#define O_RDONLY 00
|
||||
#define O_WRONLY 01
|
||||
#define O_RDWR 02
|
||||
|
||||
#define O_CREAT 0100
|
||||
#define O_EXCL 0200
|
||||
#define O_NOCTTY 0400
|
||||
#define O_TRUNC 01000
|
||||
#define O_APPEND 02000
|
||||
#define O_NONBLOCK 04000
|
||||
#define O_DSYNC 010000
|
||||
#define O_SYNC 04010000
|
||||
#define O_RSYNC 04010000
|
||||
#define O_CREAT 0100
|
||||
#define O_EXCL 0200
|
||||
#define O_NOCTTY 0400
|
||||
#define O_TRUNC 01000
|
||||
#define O_APPEND 02000
|
||||
#define O_NONBLOCK 04000
|
||||
#define O_DSYNC 010000
|
||||
#define O_SYNC 04010000
|
||||
#define O_RSYNC 04010000
|
||||
#define O_DIRECTORY 0200000
|
||||
#define O_NOFOLLOW 0400000
|
||||
#define O_CLOEXEC 02000000
|
||||
#define O_NOFOLLOW 0400000
|
||||
#define O_CLOEXEC 02000000
|
||||
|
||||
#define O_ASYNC 020000
|
||||
#define O_DIRECT 040000
|
||||
#define O_LARGEFILE 0
|
||||
#define O_NOATIME 01000000
|
||||
#define O_PATH 010000000
|
||||
#define O_ASYNC 020000
|
||||
#define O_DIRECT 040000
|
||||
#define O_LARGEFILE 0
|
||||
#define O_NOATIME 01000000
|
||||
#define O_PATH 010000000
|
||||
#define O_TMPFILE 020200000
|
||||
#define O_NDELAY O_NONBLOCK
|
||||
|
||||
#define S_IFMT 0170000
|
||||
#define S_IFMT 0170000
|
||||
#define S_IFDIR 0040000
|
||||
#define S_IFCHR 0020000
|
||||
#define S_IFBLK 0060000
|
||||
@ -63,13 +63,13 @@ extern "C" {
|
||||
#define SEEK_CUR 1
|
||||
#define SEEK_END 2
|
||||
|
||||
#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
|
||||
#define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
|
||||
#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
|
||||
#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
|
||||
#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
|
||||
#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
|
||||
#define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
|
||||
#define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR)
|
||||
#define S_ISCHR(mode) (((mode)&S_IFMT) == S_IFCHR)
|
||||
#define S_ISBLK(mode) (((mode)&S_IFMT) == S_IFBLK)
|
||||
#define S_ISREG(mode) (((mode)&S_IFMT) == S_IFREG)
|
||||
#define S_ISFIFO(mode) (((mode)&S_IFMT) == S_IFIFO)
|
||||
#define S_ISLNK(mode) (((mode)&S_IFMT) == S_IFLNK)
|
||||
#define S_ISSOCK(mode) (((mode)&S_IFMT) == S_IFSOCK)
|
||||
|
||||
#define DT_UNKNOWN 0
|
||||
#define DT_FIFO 1
|
||||
@ -85,24 +85,24 @@ extern "C" {
|
||||
#define AT_REMOVEDIR 0x200
|
||||
#define AT_SYMLINK_FOLLOW 0x400
|
||||
|
||||
#define POLLIN 0x001
|
||||
#define POLLPRI 0x002
|
||||
#define POLLOUT 0x004
|
||||
#define POLLERR 0x008
|
||||
#define POLLHUP 0x010
|
||||
#define POLLNVAL 0x020
|
||||
#define POLLIN 0x001
|
||||
#define POLLPRI 0x002
|
||||
#define POLLOUT 0x004
|
||||
#define POLLERR 0x008
|
||||
#define POLLHUP 0x010
|
||||
#define POLLNVAL 0x020
|
||||
#define POLLRDNORM 0x040
|
||||
#define POLLRDBAND 0x080
|
||||
#define POLLWRNORM 0x100
|
||||
#define POLLWRBAND 0x200
|
||||
|
||||
#define FIONREAD 0x541B
|
||||
#define FIONREAD 0x541B
|
||||
|
||||
#define PATH_MAX 4096
|
||||
#define PATH_MAX 4096
|
||||
|
||||
/* Special value used to indicate openat should use the current
|
||||
working directory. */
|
||||
#define AT_FDCWD -100
|
||||
#define AT_FDCWD -100
|
||||
|
||||
typedef long __syscall_slong_t;
|
||||
|
||||
@ -138,7 +138,7 @@ struct stat {
|
||||
mode_t st_mode;
|
||||
uid_t st_uid;
|
||||
gid_t st_gid;
|
||||
unsigned int __pad0;
|
||||
unsigned int __pad0;
|
||||
dev_t st_rdev;
|
||||
off_t st_size;
|
||||
blksize_t st_blksize;
|
||||
@ -156,76 +156,108 @@ struct iovec {
|
||||
};
|
||||
|
||||
struct pollfd {
|
||||
int fd;
|
||||
short events;
|
||||
short revents;
|
||||
int fd;
|
||||
short events;
|
||||
short revents;
|
||||
};
|
||||
|
||||
int open(const char *pathname, int flags, ...);
|
||||
int openat(int dirfd, const char *pathname, int flags, ...);
|
||||
int close(int fd);
|
||||
int
|
||||
open(const char *pathname, int flags, ...);
|
||||
int
|
||||
openat(int dirfd, const char *pathname, int flags, ...);
|
||||
int
|
||||
close(int fd);
|
||||
|
||||
DIR *fdopendir(int fd);
|
||||
int closedir(DIR *dirp);
|
||||
void rewinddir(DIR *dirp);
|
||||
void seekdir(DIR *dirp, long loc);
|
||||
struct dirent *readdir(DIR *dirp);
|
||||
long telldir(DIR *dirp);
|
||||
DIR *
|
||||
fdopendir(int fd);
|
||||
int
|
||||
closedir(DIR *dirp);
|
||||
void
|
||||
rewinddir(DIR *dirp);
|
||||
void
|
||||
seekdir(DIR *dirp, long loc);
|
||||
struct dirent *
|
||||
readdir(DIR *dirp);
|
||||
long
|
||||
telldir(DIR *dirp);
|
||||
|
||||
ssize_t read(int fd, void *buf, size_t count);
|
||||
ssize_t readv(int fd, const struct iovec *iov, int iovcnt);
|
||||
ssize_t writev(int fd, const struct iovec *iov, int iovcnt);
|
||||
ssize_t preadv(int fd, const struct iovec *iov, int iovcnt,
|
||||
off_t offset);
|
||||
ssize_t pwritev(int fd, const struct iovec *iov, int iovcnt,
|
||||
off_t offset);
|
||||
ssize_t
|
||||
read(int fd, void *buf, size_t count);
|
||||
ssize_t
|
||||
readv(int fd, const struct iovec *iov, int iovcnt);
|
||||
ssize_t
|
||||
writev(int fd, const struct iovec *iov, int iovcnt);
|
||||
ssize_t
|
||||
preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset);
|
||||
ssize_t
|
||||
pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset);
|
||||
|
||||
off_t lseek(int fd, off_t offset, int whence);
|
||||
int ftruncate(int fd, off_t length);
|
||||
off_t
|
||||
lseek(int fd, off_t offset, int whence);
|
||||
int
|
||||
ftruncate(int fd, off_t length);
|
||||
|
||||
int stat(const char *pathname, struct stat *statbuf);
|
||||
int fstat(int fd, struct stat *statbuf);
|
||||
int fstatat(int dirfd, const char *pathname, struct stat *statbuf,
|
||||
int flags);
|
||||
int
|
||||
stat(const char *pathname, struct stat *statbuf);
|
||||
int
|
||||
fstat(int fd, struct stat *statbuf);
|
||||
int
|
||||
fstatat(int dirfd, const char *pathname, struct stat *statbuf, int flags);
|
||||
|
||||
int fsync(int fd);
|
||||
int fdatasync(int fd);
|
||||
int
|
||||
fsync(int fd);
|
||||
int
|
||||
fdatasync(int fd);
|
||||
|
||||
int mkdirat(int dirfd, const char *pathname, mode_t mode);
|
||||
int link(const char *oldpath, const char *newpath);
|
||||
int linkat(int olddirfd, const char *oldpath,
|
||||
int newdirfd, const char *newpath, int flags);
|
||||
int unlinkat(int dirfd, const char *pathname, int flags);
|
||||
ssize_t readlinkat(int dirfd, const char *pathname,
|
||||
char *buf, size_t bufsiz);
|
||||
int symlinkat(const char *target, int newdirfd, const char *linkpath);
|
||||
int renameat(int olddirfd, const char *oldpath,
|
||||
int newdirfd, const char *newpath);
|
||||
int
|
||||
mkdirat(int dirfd, const char *pathname, mode_t mode);
|
||||
int
|
||||
link(const char *oldpath, const char *newpath);
|
||||
int
|
||||
linkat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath,
|
||||
int flags);
|
||||
int
|
||||
unlinkat(int dirfd, const char *pathname, int flags);
|
||||
ssize_t
|
||||
readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz);
|
||||
int
|
||||
symlinkat(const char *target, int newdirfd, const char *linkpath);
|
||||
int
|
||||
renameat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath);
|
||||
|
||||
int ioctl(int fd, unsigned long request, ...);
|
||||
int fcntl(int fd, int cmd, ... /* arg */ );
|
||||
int
|
||||
ioctl(int fd, unsigned long request, ...);
|
||||
int
|
||||
fcntl(int fd, int cmd, ... /* arg */);
|
||||
|
||||
int isatty(int fd);
|
||||
int
|
||||
isatty(int fd);
|
||||
|
||||
char *realpath(const char *path, char *resolved_path);
|
||||
char *
|
||||
realpath(const char *path, char *resolved_path);
|
||||
|
||||
int posix_fallocate(int fd, off_t offset, off_t len);
|
||||
int
|
||||
posix_fallocate(int fd, off_t offset, off_t len);
|
||||
|
||||
int poll(struct pollfd *fds, nfds_t nfds, int timeout);
|
||||
int
|
||||
poll(struct pollfd *fds, nfds_t nfds, int timeout);
|
||||
|
||||
int getopt(int argc, char * const argv[],
|
||||
const char *optstring);
|
||||
int
|
||||
getopt(int argc, char *const argv[], const char *optstring);
|
||||
|
||||
int sched_yield(void);
|
||||
int
|
||||
sched_yield(void);
|
||||
|
||||
ssize_t getrandom(void *buf, size_t buflen, unsigned int flags);
|
||||
int getentropy(void *buffer, size_t length);
|
||||
ssize_t
|
||||
getrandom(void *buf, size_t buflen, unsigned int flags);
|
||||
int
|
||||
getentropy(void *buffer, size_t length);
|
||||
|
||||
int get_errno(void);
|
||||
int
|
||||
get_errno(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* end of _SGX_FILE_H */
|
||||
|
||||
|
||||
@ -7,19 +7,19 @@
|
||||
#include "platform_api_extension.h"
|
||||
#include "sgx_rsrv_mem_mngr.h"
|
||||
|
||||
#define FIXED_BUFFER_SIZE (1<<9)
|
||||
#define FIXED_BUFFER_SIZE (1 << 9)
|
||||
|
||||
static os_print_function_t print_function = NULL;
|
||||
|
||||
int bh_platform_init()
|
||||
int
|
||||
bh_platform_init()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
bh_platform_destroy()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
void *
|
||||
os_malloc(unsigned size)
|
||||
@ -39,22 +39,26 @@ os_free(void *ptr)
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
int putchar(int c)
|
||||
int
|
||||
putchar(int c)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int puts(const char *s)
|
||||
int
|
||||
puts(const char *s)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void os_set_print_function(os_print_function_t pf)
|
||||
void
|
||||
os_set_print_function(os_print_function_t pf)
|
||||
{
|
||||
print_function = pf;
|
||||
}
|
||||
|
||||
int os_printf(const char *message, ...)
|
||||
int
|
||||
os_printf(const char *message, ...)
|
||||
{
|
||||
if (print_function != NULL) {
|
||||
char msg[FIXED_BUFFER_SIZE] = { '\0' };
|
||||
@ -68,7 +72,8 @@ int os_printf(const char *message, ...)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int os_vprintf(const char * format, va_list arg)
|
||||
int
|
||||
os_vprintf(const char *format, va_list arg)
|
||||
{
|
||||
if (print_function != NULL) {
|
||||
char msg[FIXED_BUFFER_SIZE] = { '\0' };
|
||||
@ -79,20 +84,23 @@ int os_vprintf(const char * format, va_list arg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *strcpy(char *dest, const char *src)
|
||||
char *
|
||||
strcpy(char *dest, const char *src)
|
||||
{
|
||||
const unsigned char *s = src;
|
||||
unsigned char *d = dest;
|
||||
|
||||
while ((*d++ = *s++));
|
||||
while ((*d++ = *s++))
|
||||
;
|
||||
return dest;
|
||||
}
|
||||
|
||||
void* os_mmap(void *hint, size_t size, int prot, int flags)
|
||||
void *
|
||||
os_mmap(void *hint, size_t size, int prot, int flags)
|
||||
{
|
||||
int mprot = 0;
|
||||
uint64 aligned_size, page_size;
|
||||
void* ret = NULL;
|
||||
void *ret = NULL;
|
||||
sgx_status_t st = 0;
|
||||
|
||||
page_size = getpagesize();
|
||||
@ -103,8 +111,8 @@ void* os_mmap(void *hint, size_t size, int prot, int flags)
|
||||
|
||||
ret = sgx_alloc_rsrv_mem(aligned_size);
|
||||
if (ret == NULL) {
|
||||
os_printf("os_mmap(size=%u, aligned size=%lu, prot=0x%x) failed.",
|
||||
size, aligned_size, prot);
|
||||
os_printf("os_mmap(size=%u, aligned size=%lu, prot=0x%x) failed.", size,
|
||||
aligned_size, prot);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -117,8 +125,8 @@ void* os_mmap(void *hint, size_t size, int prot, int flags)
|
||||
|
||||
st = sgx_tprotect_rsrv_mem(ret, aligned_size, mprot);
|
||||
if (st != SGX_SUCCESS) {
|
||||
os_printf("os_mmap(size=%u, prot=0x%x) failed to set protect.",
|
||||
size, prot);
|
||||
os_printf("os_mmap(size=%u, prot=0x%x) failed to set protect.", size,
|
||||
prot);
|
||||
sgx_free_rsrv_mem(ret, aligned_size);
|
||||
return NULL;
|
||||
}
|
||||
@ -126,7 +134,8 @@ void* os_mmap(void *hint, size_t size, int prot, int flags)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void os_munmap(void *addr, size_t size)
|
||||
void
|
||||
os_munmap(void *addr, size_t size)
|
||||
{
|
||||
uint64 aligned_size, page_size;
|
||||
|
||||
@ -135,7 +144,8 @@ void os_munmap(void *addr, size_t size)
|
||||
sgx_free_rsrv_mem(addr, aligned_size);
|
||||
}
|
||||
|
||||
int os_mprotect(void *addr, size_t size, int prot)
|
||||
int
|
||||
os_mprotect(void *addr, size_t size, int prot)
|
||||
{
|
||||
int mprot = 0;
|
||||
sgx_status_t st = 0;
|
||||
@ -152,14 +162,12 @@ int os_mprotect(void *addr, size_t size, int prot)
|
||||
mprot |= SGX_PROT_EXEC;
|
||||
st = sgx_tprotect_rsrv_mem(addr, aligned_size, mprot);
|
||||
if (st != SGX_SUCCESS)
|
||||
os_printf("os_mprotect(addr=0x%"PRIx64", size=%u, prot=0x%x) failed.",
|
||||
os_printf("os_mprotect(addr=0x%" PRIx64 ", size=%u, prot=0x%x) failed.",
|
||||
(uintptr_t)addr, size, prot);
|
||||
|
||||
return (st == SGX_SUCCESS? 0:-1);
|
||||
return (st == SGX_SUCCESS ? 0 : -1);
|
||||
}
|
||||
|
||||
void
|
||||
os_dcache_flush(void)
|
||||
{
|
||||
}
|
||||
|
||||
{}
|
||||
|
||||
@ -15,22 +15,27 @@
|
||||
#ifndef SGX_THREAD_LOCK_INITIALIZER /* defined since sgxsdk-2.11 */
|
||||
/* sgxsdk doesn't support pthread_rwlock related APIs until
|
||||
version 2.11, we implement them by ourselves. */
|
||||
int ocall_pthread_rwlock_init(int *p_ret, void **rwlock, void *attr);
|
||||
int
|
||||
ocall_pthread_rwlock_init(int *p_ret, void **rwlock, void *attr);
|
||||
|
||||
int ocall_pthread_rwlock_destroy(int *p_ret, void **rwlock);
|
||||
int
|
||||
ocall_pthread_rwlock_destroy(int *p_ret, void **rwlock);
|
||||
|
||||
int ocall_pthread_rwlock_rdlock(int *p_ret, void **rwlock);
|
||||
int
|
||||
ocall_pthread_rwlock_rdlock(int *p_ret, void **rwlock);
|
||||
|
||||
int ocall_pthread_rwlock_wrlock(int *p_ret, void **rwlock);
|
||||
int
|
||||
ocall_pthread_rwlock_wrlock(int *p_ret, void **rwlock);
|
||||
|
||||
int ocall_pthread_rwlock_unlock(int *p_ret, void **rwlock);
|
||||
int
|
||||
ocall_pthread_rwlock_unlock(int *p_ret, void **rwlock);
|
||||
|
||||
int pthread_rwlock_init(pthread_rwlock_t *rwlock, void *attr)
|
||||
int
|
||||
pthread_rwlock_init(pthread_rwlock_t *rwlock, void *attr)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
if (ocall_pthread_rwlock_init(&ret, (void **)rwlock, NULL)
|
||||
!= SGX_SUCCESS) {
|
||||
if (ocall_pthread_rwlock_init(&ret, (void **)rwlock, NULL) != SGX_SUCCESS) {
|
||||
TRACE_OCALL_FAIL();
|
||||
return -1;
|
||||
}
|
||||
@ -38,7 +43,8 @@ int pthread_rwlock_init(pthread_rwlock_t *rwlock, void *attr)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pthread_rwlock_destroy(pthread_rwlock_t *rwlock)
|
||||
int
|
||||
pthread_rwlock_destroy(pthread_rwlock_t *rwlock)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
@ -48,31 +54,34 @@ int pthread_rwlock_destroy(pthread_rwlock_t *rwlock)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock)
|
||||
int
|
||||
pthread_rwlock_rdlock(pthread_rwlock_t *rwlock)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
if (ocall_pthread_rwlock_rdlock(&ret, (void*)*rwlock) != SGX_SUCCESS) {
|
||||
if (ocall_pthread_rwlock_rdlock(&ret, (void *)*rwlock) != SGX_SUCCESS) {
|
||||
TRACE_OCALL_FAIL();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock)
|
||||
int
|
||||
pthread_rwlock_wrlock(pthread_rwlock_t *rwlock)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
if (ocall_pthread_rwlock_wrlock(&ret, (void*)*rwlock) != SGX_SUCCESS) {
|
||||
if (ocall_pthread_rwlock_wrlock(&ret, (void *)*rwlock) != SGX_SUCCESS) {
|
||||
TRACE_OCALL_FAIL();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pthread_rwlock_unlock(pthread_rwlock_t *rwlock)
|
||||
int
|
||||
pthread_rwlock_unlock(pthread_rwlock_t *rwlock)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
if (ocall_pthread_rwlock_unlock(&ret, (void*)*rwlock) != SGX_SUCCESS) {
|
||||
if (ocall_pthread_rwlock_unlock(&ret, (void *)*rwlock) != SGX_SUCCESS) {
|
||||
TRACE_OCALL_FAIL();
|
||||
}
|
||||
return ret;
|
||||
@ -80,4 +89,3 @@ int pthread_rwlock_unlock(pthread_rwlock_t *rwlock)
|
||||
#endif /* end of SGX_THREAD_LOCK_INITIALIZER */
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -15,12 +15,17 @@ extern "C" {
|
||||
version 2.11, we implement them by ourselves. */
|
||||
typedef uintptr_t pthread_rwlock_t;
|
||||
|
||||
int pthread_rwlock_init(pthread_rwlock_t *rwlock, void *attr);
|
||||
int pthread_rwlock_destroy(pthread_rwlock_t *rwlock);
|
||||
int
|
||||
pthread_rwlock_init(pthread_rwlock_t *rwlock, void *attr);
|
||||
int
|
||||
pthread_rwlock_destroy(pthread_rwlock_t *rwlock);
|
||||
|
||||
int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);
|
||||
int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
|
||||
int pthread_rwlock_unlock(pthread_rwlock_t *rwlock);
|
||||
int
|
||||
pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);
|
||||
int
|
||||
pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
|
||||
int
|
||||
pthread_rwlock_unlock(pthread_rwlock_t *rwlock);
|
||||
#endif /* end of SGX_THREAD_LOCK_INITIALIZER */
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -28,4 +33,3 @@ int pthread_rwlock_unlock(pthread_rwlock_t *rwlock);
|
||||
#endif
|
||||
|
||||
#endif /* end of _SGX_PTHREAD_H */
|
||||
|
||||
|
||||
@ -30,7 +30,8 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is copied from https://github.com/intel/linux-sgx/blob/4589daddd58bec7367a6a9de3fe301e6de17671a/common/inc/internal/sgx_rsrv_mem_mngr.h
|
||||
* This file is copied from
|
||||
* https://github.com/intel/linux-sgx/blob/4589daddd58bec7367a6a9de3fe301e6de17671a/common/inc/internal/sgx_rsrv_mem_mngr.h
|
||||
* The reason we copied here is that the official SGX SDK release has
|
||||
* not included this header file yet.
|
||||
*/
|
||||
@ -43,48 +44,52 @@
|
||||
#include "stdint.h"
|
||||
#include "sgx_error.h"
|
||||
|
||||
#define SGX_PROT_READ 0x1 /* page can be read */
|
||||
#define SGX_PROT_WRITE 0x2 /* page can be written */
|
||||
#define SGX_PROT_EXEC 0x4 /* page can be executed */
|
||||
#define SGX_PROT_NONE 0x0 /* page can not be accessed */
|
||||
#define SGX_PROT_READ 0x1 /* page can be read */
|
||||
#define SGX_PROT_WRITE 0x2 /* page can be written */
|
||||
#define SGX_PROT_EXEC 0x4 /* page can be executed */
|
||||
#define SGX_PROT_NONE 0x0 /* page can not be accessed */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Allocate a range of EPC memory from the reserved memory area with RW permission
|
||||
*
|
||||
* Parameters:
|
||||
* Inputs: length [in]: Size of region to be allocated in bytes. Page aligned
|
||||
* Return: Starting address of the new allocated memory area on success; otherwise NULL
|
||||
*/
|
||||
void * sgx_alloc_rsrv_mem(size_t length);
|
||||
/* Allocate a range of EPC memory from the reserved memory area with RW
|
||||
* permission
|
||||
*
|
||||
* Parameters:
|
||||
* Inputs: length [in]: Size of region to be allocated in bytes. Page aligned.
|
||||
* Return: Starting address of the new allocated memory area on success;
|
||||
* otherwise NULL
|
||||
*/
|
||||
void *
|
||||
sgx_alloc_rsrv_mem(size_t length);
|
||||
|
||||
/* Free a range of EPC memory from the reserved memory area
|
||||
*
|
||||
* Parameters:
|
||||
* Inputs: addr[in]: Starting address of region to be freed. Page aligned.
|
||||
* length[in]: The length of the memory to be freed in bytes.
|
||||
* Page aligned.
|
||||
* Return: 0 on success; otherwise -1
|
||||
*/
|
||||
int
|
||||
sgx_free_rsrv_mem(void *addr, size_t length);
|
||||
|
||||
/* Free a range of EPC memory from the reserved memory area
|
||||
*
|
||||
* Parameters:
|
||||
* Inputs: addr[in]: Starting address of region to be freed. Page aligned.
|
||||
* length[in]: The length of the memory to be freed in bytes. Page aligned
|
||||
* Return: 0 on success; otherwise -1
|
||||
*/
|
||||
int sgx_free_rsrv_mem(void * addr, size_t length);
|
||||
|
||||
|
||||
/* Modify the access permissions of the pages in the reserved memory area.
|
||||
*
|
||||
* Parameters:
|
||||
* Inputs: addr[in]: Starting address of region which needs to change access permission. Page aligned.
|
||||
* length[in]: The length of the memory to be manipulated in bytes. Page aligned.
|
||||
* prot[in]: The target memory protection.
|
||||
* Return: sgx_status_t - SGX_SUCCESS or failure as defined in sgx_error.h
|
||||
*/
|
||||
sgx_status_t sgx_tprotect_rsrv_mem(void *addr, size_t len, int prot);
|
||||
|
||||
/* Modify the access permissions of the pages in the reserved memory area.
|
||||
*
|
||||
* Parameters:
|
||||
* Inputs: addr[in]: Starting address of region which needs to change access
|
||||
* permission. Page aligned.
|
||||
* length[in]: The length of the memory to be manipulated in bytes.
|
||||
* Page aligned.
|
||||
* prot[in]: The target memory protection.
|
||||
* Return: sgx_status_t - SGX_SUCCESS or failure as defined in sgx_error.h
|
||||
*/
|
||||
sgx_status_t
|
||||
sgx_tprotect_rsrv_mem(void *addr, size_t len, int prot);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -9,9 +9,11 @@
|
||||
|
||||
#define TRACE_OCALL_FAIL() os_printf("ocall %s failed!\n", __FUNCTION__)
|
||||
|
||||
int ocall_raise(int *p_ret, int sig);
|
||||
int
|
||||
ocall_raise(int *p_ret, int sig);
|
||||
|
||||
int raise(int sig)
|
||||
int
|
||||
raise(int sig)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -27,4 +29,3 @@ int raise(int sig)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -11,47 +11,47 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
/* Signals. */
|
||||
#define SIGHUP 1 /* Hangup (POSIX). */
|
||||
#define SIGINT 2 /* Interrupt (ANSI). */
|
||||
#define SIGQUIT 3 /* Quit (POSIX). */
|
||||
#define SIGILL 4 /* Illegal instruction (ANSI). */
|
||||
#define SIGTRAP 5 /* Trace trap (POSIX). */
|
||||
#define SIGABRT 6 /* Abort (ANSI). */
|
||||
#define SIGIOT 6 /* IOT trap (4.2 BSD). */
|
||||
#define SIGBUS 7 /* BUS error (4.2 BSD). */
|
||||
#define SIGFPE 8 /* Floating-point exception (ANSI). */
|
||||
#define SIGKILL 9 /* Kill, unblockable (POSIX). */
|
||||
#define SIGUSR1 10 /* User-defined signal 1 (POSIX). */
|
||||
#define SIGSEGV 11 /* Segmentation violation (ANSI). */
|
||||
#define SIGUSR2 12 /* User-defined signal 2 (POSIX). */
|
||||
#define SIGPIPE 13 /* Broken pipe (POSIX). */
|
||||
#define SIGALRM 14 /* Alarm clock (POSIX). */
|
||||
#define SIGTERM 15 /* Termination (ANSI). */
|
||||
#define SIGSTKFLT 16 /* Stack fault. */
|
||||
#define SIGCLD SIGCHLD /* Same as SIGCHLD (System V). */
|
||||
#define SIGCHLD 17 /* Child status has changed (POSIX). */
|
||||
#define SIGCONT 18 /* Continue (POSIX). */
|
||||
#define SIGSTOP 19 /* Stop, unblockable (POSIX). */
|
||||
#define SIGTSTP 20 /* Keyboard stop (POSIX). */
|
||||
#define SIGTTIN 21 /* Background read from tty (POSIX). */
|
||||
#define SIGTTOU 22 /* Background write to tty (POSIX). */
|
||||
#define SIGURG 23 /* Urgent condition on socket (4.2 BSD). */
|
||||
#define SIGXCPU 24 /* CPU limit exceeded (4.2 BSD). */
|
||||
#define SIGXFSZ 25 /* File size limit exceeded (4.2 BSD). */
|
||||
#define SIGVTALRM 26 /* Virtual alarm clock (4.2 BSD). */
|
||||
#define SIGPROF 27 /* Profiling alarm clock (4.2 BSD). */
|
||||
#define SIGWINCH 28 /* Window size change (4.3 BSD, Sun). */
|
||||
#define SIGPOLL SIGIO /* Pollable event occurred (System V). */
|
||||
#define SIGIO 29 /* I/O now possible (4.2 BSD). */
|
||||
#define SIGPWR 30 /* Power failure restart (System V). */
|
||||
#define SIGSYS 31 /* Bad system call. */
|
||||
#define SIGUNUSED 31
|
||||
#define SIGHUP 1 /* Hangup (POSIX). */
|
||||
#define SIGINT 2 /* Interrupt (ANSI). */
|
||||
#define SIGQUIT 3 /* Quit (POSIX). */
|
||||
#define SIGILL 4 /* Illegal instruction (ANSI). */
|
||||
#define SIGTRAP 5 /* Trace trap (POSIX). */
|
||||
#define SIGABRT 6 /* Abort (ANSI). */
|
||||
#define SIGIOT 6 /* IOT trap (4.2 BSD). */
|
||||
#define SIGBUS 7 /* BUS error (4.2 BSD). */
|
||||
#define SIGFPE 8 /* Floating-point exception (ANSI). */
|
||||
#define SIGKILL 9 /* Kill, unblockable (POSIX). */
|
||||
#define SIGUSR1 10 /* User-defined signal 1 (POSIX). */
|
||||
#define SIGSEGV 11 /* Segmentation violation (ANSI). */
|
||||
#define SIGUSR2 12 /* User-defined signal 2 (POSIX). */
|
||||
#define SIGPIPE 13 /* Broken pipe (POSIX). */
|
||||
#define SIGALRM 14 /* Alarm clock (POSIX). */
|
||||
#define SIGTERM 15 /* Termination (ANSI). */
|
||||
#define SIGSTKFLT 16 /* Stack fault. */
|
||||
#define SIGCLD SIGCHLD /* Same as SIGCHLD (System V). */
|
||||
#define SIGCHLD 17 /* Child status has changed (POSIX). */
|
||||
#define SIGCONT 18 /* Continue (POSIX). */
|
||||
#define SIGSTOP 19 /* Stop, unblockable (POSIX). */
|
||||
#define SIGTSTP 20 /* Keyboard stop (POSIX). */
|
||||
#define SIGTTIN 21 /* Background read from tty (POSIX). */
|
||||
#define SIGTTOU 22 /* Background write to tty (POSIX). */
|
||||
#define SIGURG 23 /* Urgent condition on socket (4.2 BSD). */
|
||||
#define SIGXCPU 24 /* CPU limit exceeded (4.2 BSD). */
|
||||
#define SIGXFSZ 25 /* File size limit exceeded (4.2 BSD). */
|
||||
#define SIGVTALRM 26 /* Virtual alarm clock (4.2 BSD). */
|
||||
#define SIGPROF 27 /* Profiling alarm clock (4.2 BSD). */
|
||||
#define SIGWINCH 28 /* Window size change (4.3 BSD, Sun). */
|
||||
#define SIGPOLL SIGIO /* Pollable event occurred (System V). */
|
||||
#define SIGIO 29 /* I/O now possible (4.2 BSD). */
|
||||
#define SIGPWR 30 /* Power failure restart (System V). */
|
||||
#define SIGSYS 31 /* Bad system call. */
|
||||
#define SIGUNUSED 31
|
||||
|
||||
int raise(int sig);
|
||||
int
|
||||
raise(int sig);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* end of _SGX_SIGNAL_H */
|
||||
|
||||
|
||||
@ -9,18 +9,23 @@
|
||||
|
||||
#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,
|
||||
void *val_buf, unsigned int val_buf_size,
|
||||
void *len_buf);
|
||||
int
|
||||
ocall_socket(int *p_ret, int domain, int type, int protocol);
|
||||
int
|
||||
ocall_getsockopt(int *p_ret, int sockfd, int level, int optname, void *val_buf,
|
||||
unsigned int val_buf_size, void *len_buf);
|
||||
|
||||
int ocall_sendmsg(ssize_t *p_ret, int sockfd, void *msg_buf,
|
||||
unsigned int msg_buf_size, int flags);
|
||||
int ocall_recvmsg(ssize_t *p_ret, int sockfd, void *msg_buf,
|
||||
unsigned int msg_buf_size, int flags);
|
||||
int ocall_shutdown(int *p_ret, int sockfd, int how);
|
||||
int
|
||||
ocall_sendmsg(ssize_t *p_ret, int sockfd, void *msg_buf,
|
||||
unsigned int msg_buf_size, int flags);
|
||||
int
|
||||
ocall_recvmsg(ssize_t *p_ret, int sockfd, void *msg_buf,
|
||||
unsigned int msg_buf_size, int flags);
|
||||
int
|
||||
ocall_shutdown(int *p_ret, int sockfd, int how);
|
||||
|
||||
int socket(int domain, int type, int protocol)
|
||||
int
|
||||
socket(int domain, int type, int protocol)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -35,14 +40,15 @@ int socket(int domain, int type, int protocol)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int getsockopt(int sockfd, int level, int optname,
|
||||
void *optval, socklen_t *optlen)
|
||||
int
|
||||
getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen)
|
||||
{
|
||||
int ret;
|
||||
unsigned int val_buf_size = *optlen;
|
||||
|
||||
if (ocall_getsockopt(&ret, sockfd, level, optname, optval,
|
||||
val_buf_size, (void *)optlen) != SGX_SUCCESS) {
|
||||
if (ocall_getsockopt(&ret, sockfd, level, optname, optval, val_buf_size,
|
||||
(void *)optlen)
|
||||
!= SGX_SUCCESS) {
|
||||
TRACE_OCALL_FAIL();
|
||||
return -1;
|
||||
}
|
||||
@ -53,7 +59,8 @@ int getsockopt(int sockfd, int level, int optname,
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags)
|
||||
ssize_t
|
||||
sendmsg(int sockfd, const struct msghdr *msg, int flags)
|
||||
{
|
||||
ssize_t ret;
|
||||
int i;
|
||||
@ -77,7 +84,7 @@ ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags)
|
||||
if (msg1 == NULL)
|
||||
return -1;
|
||||
|
||||
p = (char*)(uintptr_t)sizeof(struct msghdr);
|
||||
p = (char *)(uintptr_t)sizeof(struct msghdr);
|
||||
|
||||
if (msg->msg_name != NULL) {
|
||||
msg1->msg_name = p;
|
||||
@ -106,8 +113,8 @@ ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags)
|
||||
}
|
||||
}
|
||||
|
||||
if (ocall_sendmsg(&ret, sockfd, (void *)msg1, (uint32)total_size,
|
||||
flags) != SGX_SUCCESS) {
|
||||
if (ocall_sendmsg(&ret, sockfd, (void *)msg1, (uint32)total_size, flags)
|
||||
!= SGX_SUCCESS) {
|
||||
TRACE_OCALL_FAIL();
|
||||
return -1;
|
||||
}
|
||||
@ -118,7 +125,8 @@ ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags)
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags)
|
||||
ssize_t
|
||||
recvmsg(int sockfd, struct msghdr *msg, int flags)
|
||||
{
|
||||
ssize_t ret;
|
||||
int i;
|
||||
@ -144,7 +152,7 @@ ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags)
|
||||
|
||||
memset(msg1, 0, total_size);
|
||||
|
||||
p = (char*)(uintptr_t)sizeof(struct msghdr);
|
||||
p = (char *)(uintptr_t)sizeof(struct msghdr);
|
||||
|
||||
if (msg->msg_name != NULL) {
|
||||
msg1->msg_name = p;
|
||||
@ -167,8 +175,8 @@ ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags)
|
||||
}
|
||||
}
|
||||
|
||||
if (ocall_recvmsg(&ret, sockfd, (void *)msg1, (uint32)total_size,
|
||||
flags) != SGX_SUCCESS) {
|
||||
if (ocall_recvmsg(&ret, sockfd, (void *)msg1, (uint32)total_size, flags)
|
||||
!= SGX_SUCCESS) {
|
||||
TRACE_OCALL_FAIL();
|
||||
return -1;
|
||||
}
|
||||
@ -203,7 +211,8 @@ ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int shutdown(int sockfd, int how)
|
||||
int
|
||||
shutdown(int sockfd, int how)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -219,4 +228,3 @@ int shutdown(int sockfd, int how)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -12,32 +12,32 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SOL_SOCKET 1
|
||||
#define SOL_SOCKET 1
|
||||
|
||||
#define SOCK_STREAM 1
|
||||
#define SOCK_DGRAM 2
|
||||
#define SOCK_STREAM 1
|
||||
#define SOCK_DGRAM 2
|
||||
|
||||
#define SO_TYPE 3
|
||||
#define SO_TYPE 3
|
||||
|
||||
#define MSG_OOB 0x0001
|
||||
#define MSG_PEEK 0x0002
|
||||
#define MSG_OOB 0x0001
|
||||
#define MSG_PEEK 0x0002
|
||||
#define MSG_DONTROUTE 0x0004
|
||||
#define MSG_CTRUNC 0x0008
|
||||
#define MSG_PROXY 0x0010
|
||||
#define MSG_TRUNC 0x0020
|
||||
#define MSG_DONTWAIT 0x0040
|
||||
#define MSG_EOR 0x0080
|
||||
#define MSG_WAITALL 0x0100
|
||||
#define MSG_FIN 0x0200
|
||||
#define MSG_SYN 0x0400
|
||||
#define MSG_CONFIRM 0x0800
|
||||
#define MSG_RST 0x1000
|
||||
#define MSG_ERRQUEUE 0x2000
|
||||
#define MSG_NOSIGNAL 0x4000
|
||||
#define MSG_MORE 0x8000
|
||||
#define MSG_CTRUNC 0x0008
|
||||
#define MSG_PROXY 0x0010
|
||||
#define MSG_TRUNC 0x0020
|
||||
#define MSG_DONTWAIT 0x0040
|
||||
#define MSG_EOR 0x0080
|
||||
#define MSG_WAITALL 0x0100
|
||||
#define MSG_FIN 0x0200
|
||||
#define MSG_SYN 0x0400
|
||||
#define MSG_CONFIRM 0x0800
|
||||
#define MSG_RST 0x1000
|
||||
#define MSG_ERRQUEUE 0x2000
|
||||
#define MSG_NOSIGNAL 0x4000
|
||||
#define MSG_MORE 0x8000
|
||||
#define MSG_WAITFORONE 0x10000
|
||||
#define MSG_BATCH 0x40000
|
||||
#define MSG_FASTOPEN 0x20000000
|
||||
#define MSG_BATCH 0x40000
|
||||
#define MSG_FASTOPEN 0x20000000
|
||||
#define MSG_CMSG_CLOEXEC 0x40000000
|
||||
|
||||
#define SHUT_RD 0
|
||||
@ -54,21 +54,23 @@ struct msghdr {
|
||||
int msg_flags;
|
||||
};
|
||||
|
||||
int
|
||||
socket(int domain, int type, int protocol);
|
||||
|
||||
int socket(int domain, int type, int protocol);
|
||||
int
|
||||
getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen);
|
||||
|
||||
int getsockopt(int sockfd, int level, int optname,
|
||||
void *optval, socklen_t *optlen);
|
||||
ssize_t
|
||||
sendmsg(int sockfd, const struct msghdr *msg, int flags);
|
||||
|
||||
ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags);
|
||||
ssize_t
|
||||
recvmsg(int sockfd, struct msghdr *msg, int flags);
|
||||
|
||||
ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags);
|
||||
|
||||
int shutdown(int sockfd, int how);
|
||||
int
|
||||
shutdown(int sockfd, int how);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* end of _SGX_SOCKET_H */
|
||||
|
||||
|
||||
@ -12,9 +12,10 @@ typedef struct {
|
||||
void *arg;
|
||||
} thread_wrapper_arg;
|
||||
|
||||
static void *os_thread_wrapper(void *arg)
|
||||
static void *
|
||||
os_thread_wrapper(void *arg)
|
||||
{
|
||||
thread_wrapper_arg * targ = arg;
|
||||
thread_wrapper_arg *targ = arg;
|
||||
thread_start_routine_t start_func = targ->start;
|
||||
void *thread_arg = targ->arg;
|
||||
os_printf("THREAD CREATED %p\n", &targ);
|
||||
@ -23,15 +24,16 @@ static void *os_thread_wrapper(void *arg)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int os_thread_create_with_prio(korp_tid *tid, thread_start_routine_t start,
|
||||
void *arg, unsigned int stack_size, int prio)
|
||||
int
|
||||
os_thread_create_with_prio(korp_tid *tid, thread_start_routine_t start,
|
||||
void *arg, unsigned int stack_size, int prio)
|
||||
{
|
||||
thread_wrapper_arg *targ;
|
||||
|
||||
assert(tid);
|
||||
assert(start);
|
||||
|
||||
targ = (thread_wrapper_arg *) BH_MALLOC(sizeof(*targ));
|
||||
targ = (thread_wrapper_arg *)BH_MALLOC(sizeof(*targ));
|
||||
if (!targ) {
|
||||
return BHT_ERROR;
|
||||
}
|
||||
@ -47,15 +49,17 @@ int os_thread_create_with_prio(korp_tid *tid, thread_start_routine_t start,
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int os_thread_create(korp_tid *tid, thread_start_routine_t start, void *arg,
|
||||
unsigned int stack_size)
|
||||
int
|
||||
os_thread_create(korp_tid *tid, thread_start_routine_t start, void *arg,
|
||||
unsigned int stack_size)
|
||||
{
|
||||
return os_thread_create_with_prio(tid, start, arg, stack_size,
|
||||
BH_THREAD_DEFAULT_PRIORITY);
|
||||
}
|
||||
#endif
|
||||
|
||||
korp_tid os_self_thread()
|
||||
korp_tid
|
||||
os_self_thread()
|
||||
{
|
||||
#ifndef SGX_DISABLE_PTHREAD
|
||||
return pthread_self();
|
||||
@ -64,7 +68,8 @@ korp_tid os_self_thread()
|
||||
#endif
|
||||
}
|
||||
|
||||
int os_mutex_init(korp_mutex *mutex)
|
||||
int
|
||||
os_mutex_init(korp_mutex *mutex)
|
||||
{
|
||||
#ifndef SGX_DISABLE_PTHREAD
|
||||
pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
|
||||
@ -73,7 +78,8 @@ int os_mutex_init(korp_mutex *mutex)
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int os_mutex_destroy(korp_mutex *mutex)
|
||||
int
|
||||
os_mutex_destroy(korp_mutex *mutex)
|
||||
{
|
||||
#ifndef SGX_DISABLE_PTHREAD
|
||||
pthread_mutex_destroy(mutex);
|
||||
@ -81,7 +87,8 @@ int os_mutex_destroy(korp_mutex *mutex)
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int os_mutex_lock(korp_mutex *mutex)
|
||||
int
|
||||
os_mutex_lock(korp_mutex *mutex)
|
||||
{
|
||||
#ifndef SGX_DISABLE_PTHREAD
|
||||
return pthread_mutex_lock(mutex);
|
||||
@ -90,7 +97,8 @@ int os_mutex_lock(korp_mutex *mutex)
|
||||
#endif
|
||||
}
|
||||
|
||||
int os_mutex_unlock(korp_mutex *mutex)
|
||||
int
|
||||
os_mutex_unlock(korp_mutex *mutex)
|
||||
{
|
||||
#ifndef SGX_DISABLE_PTHREAD
|
||||
return pthread_mutex_unlock(mutex);
|
||||
@ -99,7 +107,8 @@ int os_mutex_unlock(korp_mutex *mutex)
|
||||
#endif
|
||||
}
|
||||
|
||||
int os_cond_init(korp_cond *cond)
|
||||
int
|
||||
os_cond_init(korp_cond *cond)
|
||||
{
|
||||
#ifndef SGX_DISABLE_PTHREAD
|
||||
pthread_cond_t c = PTHREAD_COND_INITIALIZER;
|
||||
@ -108,7 +117,8 @@ int os_cond_init(korp_cond *cond)
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int os_cond_destroy(korp_cond *cond)
|
||||
int
|
||||
os_cond_destroy(korp_cond *cond)
|
||||
{
|
||||
#ifndef SGX_DISABLE_PTHREAD
|
||||
pthread_cond_destroy(cond);
|
||||
@ -116,7 +126,8 @@ int os_cond_destroy(korp_cond *cond)
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int os_cond_wait(korp_cond *cond, korp_mutex *mutex)
|
||||
int
|
||||
os_cond_wait(korp_cond *cond, korp_mutex *mutex)
|
||||
{
|
||||
#ifndef SGX_DISABLE_PTHREAD
|
||||
assert(cond);
|
||||
@ -129,14 +140,16 @@ int os_cond_wait(korp_cond *cond, korp_mutex *mutex)
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int os_cond_reltimedwait(korp_cond *cond, korp_mutex *mutex, uint64 useconds)
|
||||
int
|
||||
os_cond_reltimedwait(korp_cond *cond, korp_mutex *mutex, uint64 useconds)
|
||||
{
|
||||
os_printf("warning: SGX pthread_cond_timedwait isn't supported, "
|
||||
"calling pthread_cond_wait instead!\n");
|
||||
return BHT_ERROR;
|
||||
}
|
||||
|
||||
int os_cond_signal(korp_cond *cond)
|
||||
int
|
||||
os_cond_signal(korp_cond *cond)
|
||||
{
|
||||
#ifndef SGX_DISABLE_PTHREAD
|
||||
assert(cond);
|
||||
@ -148,7 +161,8 @@ int os_cond_signal(korp_cond *cond)
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int os_thread_join(korp_tid thread, void **value_ptr)
|
||||
int
|
||||
os_thread_join(korp_tid thread, void **value_ptr)
|
||||
{
|
||||
#ifndef SGX_DISABLE_PTHREAD
|
||||
return pthread_join(thread, value_ptr);
|
||||
@ -157,13 +171,15 @@ int os_thread_join(korp_tid thread, void **value_ptr)
|
||||
#endif
|
||||
}
|
||||
|
||||
int os_thread_detach(korp_tid thread)
|
||||
int
|
||||
os_thread_detach(korp_tid thread)
|
||||
{
|
||||
/* SGX pthread_detach isn't provided, return directly. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
void os_thread_exit(void *retval)
|
||||
void
|
||||
os_thread_exit(void *retval)
|
||||
{
|
||||
#ifndef SGX_DISABLE_PTHREAD
|
||||
pthread_exit(retval);
|
||||
@ -172,9 +188,9 @@ void os_thread_exit(void *retval)
|
||||
#endif
|
||||
}
|
||||
|
||||
uint8 *os_thread_get_stack_boundary()
|
||||
uint8 *
|
||||
os_thread_get_stack_boundary()
|
||||
{
|
||||
/* TODO: get sgx stack boundary */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@ -8,18 +8,22 @@
|
||||
#define TRACE_FUNC() os_printf("undefined %s\n", __FUNCTION__)
|
||||
#define TRACE_OCALL_FAIL() os_printf("ocall %s failed!\n", __FUNCTION__)
|
||||
|
||||
int ocall_clock_gettime(int *p_ret, unsigned clock_id,
|
||||
void *tp_buf, unsigned int tp_buf_size);
|
||||
int ocall_clock_getres(int *p_ret, int clock_id,
|
||||
void *res_buf, unsigned int res_buf_size);
|
||||
int ocall_utimensat(int *p_ret, int dirfd, const char *pathname,
|
||||
const void *times_buf, unsigned int times_buf_size,
|
||||
int flags);
|
||||
int ocall_futimens(int *p_ret, int fd,
|
||||
const void *times_buf, unsigned int times_buf_size);
|
||||
int ocall_clock_nanosleep(int *p_ret, unsigned clock_id, int flags,
|
||||
const void *req_buf, unsigned int req_buf_size,
|
||||
const void *rem_buf, unsigned int rem_buf_size);
|
||||
int
|
||||
ocall_clock_gettime(int *p_ret, unsigned clock_id, void *tp_buf,
|
||||
unsigned int tp_buf_size);
|
||||
int
|
||||
ocall_clock_getres(int *p_ret, int clock_id, void *res_buf,
|
||||
unsigned int res_buf_size);
|
||||
int
|
||||
ocall_utimensat(int *p_ret, int dirfd, const char *pathname,
|
||||
const void *times_buf, unsigned int times_buf_size, int flags);
|
||||
int
|
||||
ocall_futimens(int *p_ret, int fd, const void *times_buf,
|
||||
unsigned int times_buf_size);
|
||||
int
|
||||
ocall_clock_nanosleep(int *p_ret, unsigned clock_id, int flags,
|
||||
const void *req_buf, unsigned int req_buf_size,
|
||||
const void *rem_buf, unsigned int rem_buf_size);
|
||||
|
||||
uint64
|
||||
os_time_get_boot_microsecond()
|
||||
@ -30,12 +34,13 @@ os_time_get_boot_microsecond()
|
||||
|
||||
#ifndef SGX_DISABLE_WASI
|
||||
|
||||
int clock_getres(int clock_id, struct timespec *res)
|
||||
int
|
||||
clock_getres(int clock_id, struct timespec *res)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (ocall_clock_getres(&ret, clock_id, (void *)res,
|
||||
sizeof(struct timespec)) != SGX_SUCCESS) {
|
||||
if (ocall_clock_getres(&ret, clock_id, (void *)res, sizeof(struct timespec))
|
||||
!= SGX_SUCCESS) {
|
||||
TRACE_OCALL_FAIL();
|
||||
return -1;
|
||||
}
|
||||
@ -46,12 +51,13 @@ int clock_getres(int clock_id, struct timespec *res)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int clock_gettime(clockid_t clock_id, struct timespec *tp)
|
||||
int
|
||||
clock_gettime(clockid_t clock_id, struct timespec *tp)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if(ocall_clock_gettime(&ret, clock_id, (void *)tp,
|
||||
sizeof(struct timespec)) != SGX_SUCCESS) {
|
||||
if (ocall_clock_gettime(&ret, clock_id, (void *)tp, sizeof(struct timespec))
|
||||
!= SGX_SUCCESS) {
|
||||
TRACE_OCALL_FAIL();
|
||||
return -1;
|
||||
}
|
||||
@ -62,14 +68,15 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int utimensat(int dirfd, const char *pathname,
|
||||
const struct timespec times[2], int flags)
|
||||
int
|
||||
utimensat(int dirfd, const char *pathname, const struct timespec times[2],
|
||||
int flags)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (ocall_utimensat(&ret, dirfd, pathname, (void *)times,
|
||||
sizeof(struct timespec) * 2,
|
||||
flags) != SGX_SUCCESS) {
|
||||
sizeof(struct timespec) * 2, flags)
|
||||
!= SGX_SUCCESS) {
|
||||
TRACE_OCALL_FAIL();
|
||||
return -1;
|
||||
}
|
||||
@ -80,12 +87,13 @@ int utimensat(int dirfd, const char *pathname,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int futimens(int fd, const struct timespec times[2])
|
||||
int
|
||||
futimens(int fd, const struct timespec times[2])
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (ocall_futimens(&ret, fd, (void *)times,
|
||||
sizeof(struct timespec) * 2) != SGX_SUCCESS) {
|
||||
if (ocall_futimens(&ret, fd, (void *)times, sizeof(struct timespec) * 2)
|
||||
!= SGX_SUCCESS) {
|
||||
TRACE_OCALL_FAIL();
|
||||
return -1;
|
||||
}
|
||||
@ -96,16 +104,16 @@ int futimens(int fd, const struct timespec times[2])
|
||||
return ret;
|
||||
}
|
||||
|
||||
int clock_nanosleep(clockid_t clock_id, int flags,
|
||||
const struct timespec *request,
|
||||
struct timespec *remain)
|
||||
int
|
||||
clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *request,
|
||||
struct timespec *remain)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (ocall_clock_nanosleep(&ret, clock_id, flags, (void *)request,
|
||||
sizeof(struct timespec),
|
||||
(void *)remain,
|
||||
sizeof(struct timespec)) != SGX_SUCCESS) {
|
||||
sizeof(struct timespec), (void *)remain,
|
||||
sizeof(struct timespec))
|
||||
!= SGX_SUCCESS) {
|
||||
TRACE_OCALL_FAIL();
|
||||
return -1;
|
||||
}
|
||||
@ -117,4 +125,3 @@ int clock_nanosleep(clockid_t clock_id, int flags,
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -10,12 +10,12 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define CLOCK_REALTIME 0
|
||||
#define CLOCK_MONOTONIC 1
|
||||
#define CLOCK_REALTIME 0
|
||||
#define CLOCK_MONOTONIC 1
|
||||
#define CLOCK_PROCESS_CPUTIME_ID 2
|
||||
#define CLOCK_THREAD_CPUTIME_ID 3
|
||||
#define CLOCK_THREAD_CPUTIME_ID 3
|
||||
|
||||
#define UTIME_NOW 0x3fffffff
|
||||
#define UTIME_NOW 0x3fffffff
|
||||
#define UTIME_OMIT 0x3ffffffe
|
||||
#define TIMER_ABSTIME 1
|
||||
|
||||
@ -28,20 +28,23 @@ struct timespec {
|
||||
long tv_nsec;
|
||||
};
|
||||
|
||||
int clock_getres(int clock_id, struct timespec *res);
|
||||
int
|
||||
clock_getres(int clock_id, struct timespec *res);
|
||||
|
||||
int clock_gettime(clockid_t clock_id, struct timespec *tp);
|
||||
int
|
||||
clock_gettime(clockid_t clock_id, struct timespec *tp);
|
||||
|
||||
int utimensat(int dirfd, const char *pathname,
|
||||
const struct timespec times[2], int flags);
|
||||
int futimens(int fd, const struct timespec times[2]);
|
||||
int clock_nanosleep(clockid_t clock_id, int flags,
|
||||
const struct timespec *request,
|
||||
struct timespec *remain);
|
||||
int
|
||||
utimensat(int dirfd, const char *pathname, const struct timespec times[2],
|
||||
int flags);
|
||||
int
|
||||
futimens(int fd, const struct timespec times[2]);
|
||||
int
|
||||
clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *request,
|
||||
struct timespec *remain);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* end of _SGX_TIME_H */
|
||||
|
||||
|
||||
@ -19,8 +19,8 @@
|
||||
#include <poll.h>
|
||||
#include <errno.h>
|
||||
|
||||
int ocall_open(const char *pathname, int flags,
|
||||
bool has_mode, unsigned mode)
|
||||
int
|
||||
ocall_open(const char *pathname, int flags, bool has_mode, unsigned mode)
|
||||
{
|
||||
if (has_mode) {
|
||||
return open(pathname, flags, (mode_t)mode);
|
||||
@ -30,9 +30,9 @@ int ocall_open(const char *pathname, int flags,
|
||||
}
|
||||
}
|
||||
|
||||
int ocall_openat(int dirfd,
|
||||
const char *pathname, int flags,
|
||||
bool has_mode, unsigned mode)
|
||||
int
|
||||
ocall_openat(int dirfd, const char *pathname, int flags, bool has_mode,
|
||||
unsigned mode)
|
||||
{
|
||||
if (has_mode) {
|
||||
return openat(dirfd, pathname, flags, (mode_t)mode);
|
||||
@ -42,12 +42,14 @@ int ocall_openat(int dirfd,
|
||||
}
|
||||
}
|
||||
|
||||
int ocall_close(int fd)
|
||||
int
|
||||
ocall_close(int fd)
|
||||
{
|
||||
return close(fd);
|
||||
}
|
||||
|
||||
ssize_t ocall_read(int fd, void *buf, size_t read_size)
|
||||
ssize_t
|
||||
ocall_read(int fd, void *buf, size_t read_size)
|
||||
{
|
||||
if (buf != NULL) {
|
||||
return read(fd, buf, read_size);
|
||||
@ -57,45 +59,53 @@ ssize_t ocall_read(int fd, void *buf, size_t read_size)
|
||||
}
|
||||
}
|
||||
|
||||
off_t ocall_lseek(int fd, off_t offset, int whence)
|
||||
off_t
|
||||
ocall_lseek(int fd, off_t offset, int whence)
|
||||
{
|
||||
return lseek(fd, offset, whence);
|
||||
}
|
||||
|
||||
int ocall_ftruncate(int fd, off_t length)
|
||||
int
|
||||
ocall_ftruncate(int fd, off_t length)
|
||||
{
|
||||
return ftruncate(fd, length);
|
||||
}
|
||||
|
||||
int ocall_fsync(int fd)
|
||||
int
|
||||
ocall_fsync(int fd)
|
||||
{
|
||||
return fsync(fd);
|
||||
}
|
||||
|
||||
int ocall_fdatasync(int fd)
|
||||
int
|
||||
ocall_fdatasync(int fd)
|
||||
{
|
||||
return fdatasync(fd);
|
||||
}
|
||||
|
||||
int ocall_isatty(int fd)
|
||||
int
|
||||
ocall_isatty(int fd)
|
||||
{
|
||||
return isatty(fd);
|
||||
}
|
||||
|
||||
void ocall_fdopendir(int fd, void **dirp)
|
||||
void
|
||||
ocall_fdopendir(int fd, void **dirp)
|
||||
{
|
||||
if (dirp) {
|
||||
*(DIR **)dirp = fdopendir(fd);
|
||||
}
|
||||
}
|
||||
|
||||
void *ocall_readdir(void *dirp)
|
||||
void *
|
||||
ocall_readdir(void *dirp)
|
||||
{
|
||||
DIR *p_dirp = (DIR *)dirp;
|
||||
return readdir(p_dirp);
|
||||
}
|
||||
|
||||
void ocall_rewinddir(void *dirp)
|
||||
void
|
||||
ocall_rewinddir(void *dirp)
|
||||
{
|
||||
DIR *p_dirp = (DIR *)dirp;
|
||||
if (p_dirp) {
|
||||
@ -103,7 +113,8 @@ void ocall_rewinddir(void *dirp)
|
||||
}
|
||||
}
|
||||
|
||||
void ocall_seekdir(void *dirp, long loc)
|
||||
void
|
||||
ocall_seekdir(void *dirp, long loc)
|
||||
{
|
||||
DIR *p_dirp = (DIR *)dirp;
|
||||
|
||||
@ -112,7 +123,8 @@ void ocall_seekdir(void *dirp, long loc)
|
||||
}
|
||||
}
|
||||
|
||||
long ocall_telldir(void *dirp)
|
||||
long
|
||||
ocall_telldir(void *dirp)
|
||||
{
|
||||
DIR *p_dirp = (DIR *)dirp;
|
||||
if (p_dirp) {
|
||||
@ -121,7 +133,8 @@ long ocall_telldir(void *dirp)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ocall_closedir(void* dirp)
|
||||
int
|
||||
ocall_closedir(void *dirp)
|
||||
{
|
||||
DIR *p_dirp = (DIR *)dirp;
|
||||
if (p_dirp) {
|
||||
@ -130,82 +143,91 @@ int ocall_closedir(void* dirp)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ocall_stat(const char *pathname,
|
||||
void *buf, unsigned int buf_len)
|
||||
int
|
||||
ocall_stat(const char *pathname, void *buf, unsigned int buf_len)
|
||||
{
|
||||
return stat(pathname, (struct stat *)buf);
|
||||
}
|
||||
|
||||
int ocall_fstat(int fd, void *buf, unsigned int buf_len)
|
||||
int
|
||||
ocall_fstat(int fd, void *buf, unsigned int buf_len)
|
||||
{
|
||||
return fstat(fd, (struct stat *)buf);
|
||||
}
|
||||
|
||||
int ocall_fstatat(int dirfd, const char *pathname, void *buf,
|
||||
unsigned int buf_len, int flags)
|
||||
int
|
||||
ocall_fstatat(int dirfd, const char *pathname, void *buf, unsigned int buf_len,
|
||||
int flags)
|
||||
{
|
||||
return fstatat(dirfd, pathname, (struct stat *)buf, flags);
|
||||
}
|
||||
|
||||
int ocall_mkdirat(int dirfd, const char *pathname, unsigned mode)
|
||||
int
|
||||
ocall_mkdirat(int dirfd, const char *pathname, unsigned mode)
|
||||
{
|
||||
return mkdirat(dirfd, pathname, (mode_t)mode);
|
||||
}
|
||||
|
||||
int ocall_link(const char *oldpath, const char *newpath)
|
||||
int
|
||||
ocall_link(const char *oldpath, const char *newpath)
|
||||
{
|
||||
return link(oldpath, newpath);
|
||||
}
|
||||
|
||||
int ocall_linkat(int olddirfd, const char *oldpath,
|
||||
int newdirfd, const char *newpath, int flags)
|
||||
int
|
||||
ocall_linkat(int olddirfd, const char *oldpath, int newdirfd,
|
||||
const char *newpath, int flags)
|
||||
{
|
||||
return linkat(olddirfd, oldpath, newdirfd, newpath, flags);
|
||||
}
|
||||
|
||||
int ocall_unlinkat(int dirfd, const char *pathname, int flags)
|
||||
int
|
||||
ocall_unlinkat(int dirfd, const char *pathname, int flags)
|
||||
{
|
||||
return unlinkat(dirfd, pathname, flags);
|
||||
}
|
||||
|
||||
ssize_t ocall_readlinkat(int dirfd, const char *pathname,
|
||||
char *buf, size_t bufsiz)
|
||||
ssize_t
|
||||
ocall_readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz)
|
||||
{
|
||||
return readlinkat(dirfd, pathname, buf, bufsiz);
|
||||
}
|
||||
|
||||
int ocall_renameat(int olddirfd, const char *oldpath,
|
||||
int newdirfd, const char *newpath)
|
||||
int
|
||||
ocall_renameat(int olddirfd, const char *oldpath, int newdirfd,
|
||||
const char *newpath)
|
||||
{
|
||||
return renameat(olddirfd, oldpath, newdirfd, newpath);
|
||||
}
|
||||
|
||||
int ocall_symlinkat(const char *target, int newdirfd,
|
||||
const char *linkpath)
|
||||
int
|
||||
ocall_symlinkat(const char *target, int newdirfd, const char *linkpath)
|
||||
{
|
||||
return symlinkat(target, newdirfd, linkpath);
|
||||
}
|
||||
|
||||
int ocall_ioctl(int fd, unsigned long request,
|
||||
void *arg, unsigned int arg_len)
|
||||
int
|
||||
ocall_ioctl(int fd, unsigned long request, void *arg, unsigned int arg_len)
|
||||
{
|
||||
/* support just int *arg temporally */
|
||||
return ioctl(fd, request, (int *)arg);
|
||||
}
|
||||
|
||||
int ocall_fcntl(int fd, int cmd)
|
||||
int
|
||||
ocall_fcntl(int fd, int cmd)
|
||||
{
|
||||
return fcntl(fd, cmd);
|
||||
return fcntl(fd, cmd);
|
||||
}
|
||||
|
||||
int ocall_fcntl_long(int fd, int cmd, long arg)
|
||||
int
|
||||
ocall_fcntl_long(int fd, int cmd, long arg)
|
||||
{
|
||||
return fcntl(fd, cmd, arg);
|
||||
return fcntl(fd, cmd, arg);
|
||||
}
|
||||
|
||||
ssize_t ocall_readv(int fd, char *iov_buf,
|
||||
unsigned int buf_size, int iovcnt,
|
||||
bool has_offset, off_t offset)
|
||||
ssize_t
|
||||
ocall_readv(int fd, char *iov_buf, unsigned int buf_size, int iovcnt,
|
||||
bool has_offset, off_t offset)
|
||||
{
|
||||
struct iovec *iov = (struct iovec *)iov_buf;
|
||||
ssize_t ret;
|
||||
@ -223,9 +245,9 @@ ssize_t ocall_readv(int fd, char *iov_buf,
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t ocall_writev(int fd, char *iov_buf,
|
||||
unsigned int buf_size, int iovcnt,
|
||||
bool has_offset, off_t offset)
|
||||
ssize_t
|
||||
ocall_writev(int fd, char *iov_buf, unsigned int buf_size, int iovcnt,
|
||||
bool has_offset, off_t offset)
|
||||
{
|
||||
struct iovec *iov = (struct iovec *)iov_buf;
|
||||
int i;
|
||||
@ -243,9 +265,10 @@ ssize_t ocall_writev(int fd, char *iov_buf,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ocall_realpath(const char *path, char *buf, unsigned int buf_len)
|
||||
int
|
||||
ocall_realpath(const char *path, char *buf, unsigned int buf_len)
|
||||
{
|
||||
char* val = NULL;
|
||||
char *val = NULL;
|
||||
val = realpath(path, buf);
|
||||
if (val != NULL) {
|
||||
return 0;
|
||||
@ -253,47 +276,53 @@ int ocall_realpath(const char *path, char *buf, unsigned int buf_len)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ocall_posix_fallocate(int fd, off_t offset, off_t len)
|
||||
int
|
||||
ocall_posix_fallocate(int fd, off_t offset, off_t len)
|
||||
{
|
||||
return posix_fallocate(fd, offset, len);
|
||||
}
|
||||
|
||||
int ocall_poll(void *fds, unsigned nfds, int timeout,
|
||||
unsigned int fds_len)
|
||||
int
|
||||
ocall_poll(void *fds, unsigned nfds, int timeout, unsigned int fds_len)
|
||||
{
|
||||
return poll((struct pollfd *)fds, (nfds_t)nfds, timeout);
|
||||
}
|
||||
|
||||
int ocall_getopt(int argc, char *argv_buf, unsigned int argv_buf_len,
|
||||
const char *optstring)
|
||||
int
|
||||
ocall_getopt(int argc, char *argv_buf, unsigned int argv_buf_len,
|
||||
const char *optstring)
|
||||
{
|
||||
int ret;
|
||||
int i;
|
||||
char **argv = (char **)argv_buf;
|
||||
|
||||
for (i=0; i < argc; i++) {
|
||||
for (i = 0; i < argc; i++) {
|
||||
argv[i] = argv_buf + (uintptr_t)argv[i];
|
||||
}
|
||||
|
||||
return getopt(argc, argv, optstring);
|
||||
}
|
||||
|
||||
ssize_t ocall_getrandom(void *buf, size_t buflen, unsigned int flags)
|
||||
ssize_t
|
||||
ocall_getrandom(void *buf, size_t buflen, unsigned int flags)
|
||||
{
|
||||
return getrandom(buf, buflen, flags);
|
||||
}
|
||||
|
||||
int ocall_getentropy(void *buffer, size_t length)
|
||||
int
|
||||
ocall_getentropy(void *buffer, size_t length)
|
||||
{
|
||||
return getentropy(buffer, length);
|
||||
}
|
||||
|
||||
int ocall_sched_yield()
|
||||
int
|
||||
ocall_sched_yield()
|
||||
{
|
||||
return sched_yield();
|
||||
}
|
||||
|
||||
int ocall_get_errno()
|
||||
int
|
||||
ocall_get_errno()
|
||||
{
|
||||
return errno;
|
||||
}
|
||||
|
||||
@ -6,7 +6,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
|
||||
int ocall_pthread_rwlock_init(void **rwlock, void *attr)
|
||||
int
|
||||
ocall_pthread_rwlock_init(void **rwlock, void *attr)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@ -15,7 +16,7 @@ int ocall_pthread_rwlock_init(void **rwlock, void *attr)
|
||||
return -1;
|
||||
|
||||
ret = pthread_rwlock_init((pthread_rwlock_t *)*rwlock, NULL);
|
||||
if (ret != 0) {
|
||||
if (ret != 0) {
|
||||
free(*rwlock);
|
||||
*rwlock = NULL;
|
||||
}
|
||||
@ -23,7 +24,8 @@ int ocall_pthread_rwlock_init(void **rwlock, void *attr)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ocall_pthread_rwlock_destroy(void *rwlock)
|
||||
int
|
||||
ocall_pthread_rwlock_destroy(void *rwlock)
|
||||
{
|
||||
pthread_rwlock_t *lock = (pthread_rwlock_t *)rwlock;
|
||||
int ret;
|
||||
@ -33,18 +35,20 @@ int ocall_pthread_rwlock_destroy(void *rwlock)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ocall_pthread_rwlock_rdlock(void *rwlock)
|
||||
int
|
||||
ocall_pthread_rwlock_rdlock(void *rwlock)
|
||||
{
|
||||
return pthread_rwlock_rdlock((pthread_rwlock_t *)rwlock);
|
||||
}
|
||||
|
||||
int ocall_pthread_rwlock_wrlock(void *rwlock)
|
||||
int
|
||||
ocall_pthread_rwlock_wrlock(void *rwlock)
|
||||
{
|
||||
return pthread_rwlock_wrlock((pthread_rwlock_t *)rwlock);
|
||||
}
|
||||
|
||||
int ocall_pthread_rwlock_unlock(void *rwlock)
|
||||
int
|
||||
ocall_pthread_rwlock_unlock(void *rwlock)
|
||||
{
|
||||
return pthread_rwlock_unlock((pthread_rwlock_t *)rwlock);
|
||||
}
|
||||
|
||||
|
||||
@ -4,7 +4,8 @@
|
||||
*/
|
||||
#include <signal.h>
|
||||
|
||||
int ocall_raise(int sig)
|
||||
int
|
||||
ocall_raise(int sig)
|
||||
{
|
||||
return raise(sig);
|
||||
}
|
||||
@ -7,20 +7,21 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
int ocall_socket(int domain, int type, int protocol)
|
||||
int
|
||||
ocall_socket(int domain, int type, int protocol)
|
||||
{
|
||||
return socket(domain, type, protocol);
|
||||
}
|
||||
|
||||
int ocall_getsockopt(int sockfd, int level, int optname, void *val_buf,
|
||||
unsigned int val_buf_size, void *len_buf)
|
||||
int
|
||||
ocall_getsockopt(int sockfd, int level, int optname, void *val_buf,
|
||||
unsigned int val_buf_size, void *len_buf)
|
||||
{
|
||||
return getsockopt(sockfd, level, optname, val_buf,
|
||||
(socklen_t *)len_buf);
|
||||
return getsockopt(sockfd, level, optname, val_buf, (socklen_t *)len_buf);
|
||||
}
|
||||
|
||||
ssize_t ocall_sendmsg(int sockfd, void *msg_buf,
|
||||
unsigned int msg_buf_size, int flags)
|
||||
ssize_t
|
||||
ocall_sendmsg(int sockfd, void *msg_buf, unsigned int msg_buf_size, int flags)
|
||||
{
|
||||
struct msghdr *msg = (struct msghdr *)msg_buf;
|
||||
int i;
|
||||
@ -35,16 +36,16 @@ ssize_t ocall_sendmsg(int sockfd, void *msg_buf,
|
||||
if (msg->msg_iov != NULL) {
|
||||
msg->msg_iov = msg_buf + (unsigned)(uintptr_t)msg->msg_iov;
|
||||
for (i = 0; i < msg->msg_iovlen; i++) {
|
||||
msg->msg_iov[i].iov_base = msg_buf + (unsigned)(uintptr_t)
|
||||
msg->msg_iov[i].iov_base;
|
||||
msg->msg_iov[i].iov_base =
|
||||
msg_buf + (unsigned)(uintptr_t)msg->msg_iov[i].iov_base;
|
||||
}
|
||||
}
|
||||
|
||||
return sendmsg(sockfd, msg, flags);
|
||||
}
|
||||
|
||||
ssize_t ocall_recvmsg(int sockfd, void *msg_buf, unsigned int msg_buf_size,
|
||||
int flags)
|
||||
ssize_t
|
||||
ocall_recvmsg(int sockfd, void *msg_buf, unsigned int msg_buf_size, int flags)
|
||||
{
|
||||
struct msghdr *msg = (struct msghdr *)msg_buf;
|
||||
int i;
|
||||
@ -58,16 +59,17 @@ ssize_t ocall_recvmsg(int sockfd, void *msg_buf, unsigned int msg_buf_size,
|
||||
|
||||
if (msg->msg_iov != NULL) {
|
||||
msg->msg_iov = msg_buf + (unsigned)(uintptr_t)msg->msg_iov;
|
||||
for (i = 0; i <msg->msg_iovlen; i++) {
|
||||
msg->msg_iov[i].iov_base = msg_buf + (unsigned)(uintptr_t)
|
||||
msg->msg_iov[i].iov_base;
|
||||
for (i = 0; i < msg->msg_iovlen; i++) {
|
||||
msg->msg_iov[i].iov_base =
|
||||
msg_buf + (unsigned)(uintptr_t)msg->msg_iov[i].iov_base;
|
||||
}
|
||||
}
|
||||
|
||||
return recvmsg(sockfd, msg, flags);
|
||||
}
|
||||
|
||||
int ocall_shutdown(int sockfd, int how)
|
||||
int
|
||||
ocall_shutdown(int sockfd, int how)
|
||||
{
|
||||
return shutdown(sockfd, how);
|
||||
}
|
||||
@ -7,41 +7,38 @@
|
||||
#include <time.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
|
||||
/** time clock **/
|
||||
int ocall_clock_gettime(unsigned clock_id, void *tp_buf,
|
||||
unsigned int tp_buf_size)
|
||||
int
|
||||
ocall_clock_gettime(unsigned clock_id, void *tp_buf, unsigned int tp_buf_size)
|
||||
{
|
||||
return clock_gettime((clockid_t)clock_id,
|
||||
(struct timespec *)tp_buf);
|
||||
return clock_gettime((clockid_t)clock_id, (struct timespec *)tp_buf);
|
||||
}
|
||||
|
||||
int ocall_clock_getres(int clock_id, void *res_buf,
|
||||
unsigned int res_buf_size)
|
||||
int
|
||||
ocall_clock_getres(int clock_id, void *res_buf, unsigned int res_buf_size)
|
||||
{
|
||||
return clock_getres(clock_id, (struct timespec *)res_buf);
|
||||
}
|
||||
|
||||
int ocall_utimensat(int dirfd, const char *pathname,
|
||||
const void *times_buf,
|
||||
unsigned int times_buf_size, int flags)
|
||||
int
|
||||
ocall_utimensat(int dirfd, const char *pathname, const void *times_buf,
|
||||
unsigned int times_buf_size, int flags)
|
||||
{
|
||||
return utimensat(dirfd, pathname, (struct timespec *)times_buf, flags);
|
||||
|
||||
}
|
||||
|
||||
int ocall_futimens(int fd, const void *times_buf,
|
||||
unsigned int times_buf_size)
|
||||
int
|
||||
ocall_futimens(int fd, const void *times_buf, unsigned int times_buf_size)
|
||||
{
|
||||
return futimens(fd, (struct timespec *)times_buf);
|
||||
}
|
||||
|
||||
int ocall_clock_nanosleep(unsigned clock_id, int flags,
|
||||
const void *req_buf, unsigned int req_buf_size,
|
||||
const void *rem_buf, unsigned int rem_buf_size)
|
||||
int
|
||||
ocall_clock_nanosleep(unsigned clock_id, int flags, const void *req_buf,
|
||||
unsigned int req_buf_size, const void *rem_buf,
|
||||
unsigned int rem_buf_size)
|
||||
{
|
||||
return clock_nanosleep((clockid_t)clock_id, flags,
|
||||
(struct timespec *)req_buf,
|
||||
(struct timespec *)rem_buf);
|
||||
|
||||
}
|
||||
|
||||
@ -13,8 +13,7 @@ bh_platform_init()
|
||||
|
||||
void
|
||||
bh_platform_destroy()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
int
|
||||
os_printf(const char *format, ...)
|
||||
@ -42,4 +41,3 @@ os_vprintf(const char *format, va_list ap)
|
||||
return BH_VPRINTF(format, ap);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -59,10 +59,8 @@ typedef pthread_t korp_thread;
|
||||
#define os_thread_local_attribute __thread
|
||||
|
||||
#if WASM_DISABLE_HW_BOUND_CHECK == 0
|
||||
#if defined(BUILD_TARGET_X86_64) \
|
||||
|| defined(BUILD_TARGET_AMD_64) \
|
||||
|| defined(BUILD_TARGET_AARCH64) \
|
||||
|| defined(BUILD_TARGET_RISCV64_LP64D) \
|
||||
#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64) \
|
||||
|| defined(BUILD_TARGET_AARCH64) || defined(BUILD_TARGET_RISCV64_LP64D) \
|
||||
|| defined(BUILD_TARGET_RISCV64_LP64)
|
||||
|
||||
#include <setjmp.h>
|
||||
@ -79,15 +77,20 @@ typedef jmp_buf korp_jmpbuf;
|
||||
|
||||
typedef void (*os_signal_handler)(void *sig_addr);
|
||||
|
||||
int os_thread_signal_init(os_signal_handler handler);
|
||||
int
|
||||
os_thread_signal_init(os_signal_handler handler);
|
||||
|
||||
void os_thread_signal_destroy();
|
||||
void
|
||||
os_thread_signal_destroy();
|
||||
|
||||
bool os_thread_signal_inited();
|
||||
bool
|
||||
os_thread_signal_inited();
|
||||
|
||||
void os_signal_unmask();
|
||||
void
|
||||
os_signal_unmask();
|
||||
|
||||
void os_sigreturn();
|
||||
void
|
||||
os_sigreturn();
|
||||
#endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64/RISCV64 */
|
||||
#endif /* end of WASM_DISABLE_HW_BOUND_CHECK */
|
||||
|
||||
@ -96,4 +99,3 @@ void os_sigreturn();
|
||||
#endif
|
||||
|
||||
#endif /* end of _PLATFORM_INTERNAL_H */
|
||||
|
||||
|
||||
@ -38,7 +38,7 @@ typedef pthread_t korp_thread;
|
||||
/* Default thread priority */
|
||||
#define BH_THREAD_DEFAULT_PRIORITY 100
|
||||
|
||||
#define os_printf printf
|
||||
#define os_printf printf
|
||||
#define os_vprintf vprintf
|
||||
|
||||
/* On NuttX, time_t is uint32_t */
|
||||
|
||||
@ -7,12 +7,12 @@
|
||||
#ifndef _PLATFORM_INTERNAL_H
|
||||
#define _PLATFORM_INTERNAL_H
|
||||
|
||||
//Riot includes core
|
||||
/* Riot includes core */
|
||||
#include <sched.h>
|
||||
#include <thread.h>
|
||||
#include <mutex.h>
|
||||
|
||||
//Riot includes sys
|
||||
/* Riot includes sys */
|
||||
#include <sema.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
@ -39,19 +39,20 @@ typedef thread_t korp_thread;
|
||||
typedef kernel_pid_t korp_tid;
|
||||
typedef mutex_t korp_mutex;
|
||||
|
||||
// typedef sema_t korp_sem;
|
||||
/* typedef sema_t korp_sem; */
|
||||
|
||||
struct os_thread_wait_node;
|
||||
typedef struct os_thread_wait_node *os_thread_wait_list;
|
||||
typedef struct korp_cond {
|
||||
mutex_t wait_list_lock;
|
||||
os_thread_wait_list thread_wait_list;
|
||||
mutex_t wait_list_lock;
|
||||
os_thread_wait_list thread_wait_list;
|
||||
} korp_cond;
|
||||
|
||||
#define os_printf printf
|
||||
#define os_printf printf
|
||||
#define os_vprintf vprintf
|
||||
|
||||
#if WA_MATH
|
||||
/* clang-format off */
|
||||
/* math functions which are not provided by os*/
|
||||
double sqrt(double x);
|
||||
double floor(double x);
|
||||
@ -69,7 +70,7 @@ float rintf(float x);
|
||||
float truncf(float x);
|
||||
int signbit(double x);
|
||||
int isnan(double x);
|
||||
/* clang-format on */
|
||||
#endif
|
||||
|
||||
#endif /* end of _BH_PLATFORM_H */
|
||||
|
||||
|
||||
@ -9,19 +9,21 @@
|
||||
|
||||
#include <panic.h>
|
||||
|
||||
/* clang-format off */
|
||||
#define bh_assert(v) do { \
|
||||
if (!(v)) { \
|
||||
printf("\nASSERTION FAILED: %s, at %s, line %d\n", \
|
||||
#v, __FILE__, __LINE__); \
|
||||
core_panic(0,0/*expr_string*/); \
|
||||
core_panic(0, 0/*expr_string*/); \
|
||||
while (1); \
|
||||
} \
|
||||
} while (0)
|
||||
} while (0)
|
||||
/* clang-format on */
|
||||
|
||||
struct os_thread_data;
|
||||
typedef struct os_thread_wait_node {
|
||||
sema_t sem;
|
||||
void * ret;
|
||||
void *ret;
|
||||
os_thread_wait_list next;
|
||||
} os_thread_wait_node;
|
||||
|
||||
@ -63,7 +65,8 @@ static mutex_t thread_data_lock;
|
||||
/* Thread data list */
|
||||
static os_thread_data *thread_data_list = NULL;
|
||||
|
||||
static void thread_data_list_add(os_thread_data *thread_data)
|
||||
static void
|
||||
thread_data_list_add(os_thread_data *thread_data)
|
||||
{
|
||||
mutex_lock(&thread_data_lock);
|
||||
if (!thread_data_list)
|
||||
@ -86,7 +89,8 @@ static void thread_data_list_add(os_thread_data *thread_data)
|
||||
mutex_unlock(&thread_data_lock);
|
||||
}
|
||||
|
||||
static void thread_data_list_remove(os_thread_data *thread_data)
|
||||
static void
|
||||
thread_data_list_remove(os_thread_data *thread_data)
|
||||
{
|
||||
mutex_lock(&thread_data_lock);
|
||||
if (thread_data_list) {
|
||||
@ -153,7 +157,7 @@ thread_data_current()
|
||||
static void
|
||||
os_thread_cleanup(void)
|
||||
{
|
||||
//TODO Check this (Join sema trigger, cleanup of thread_data)
|
||||
// TODO Check this (Join sema trigger, cleanup of thread_data)
|
||||
os_thread_data *thread_data = thread_data_current();
|
||||
bh_assert(thread_data != NULL);
|
||||
mutex_lock(&thread_data->wait_list_lock);
|
||||
@ -177,7 +181,7 @@ static void *
|
||||
os_thread_wrapper(void *thread_data)
|
||||
{
|
||||
/* Set thread custom data */
|
||||
os_thread_data * t = (os_thread_data*) thread_data;
|
||||
os_thread_data *t = (os_thread_data *)thread_data;
|
||||
t->tid = thread_getpid();
|
||||
thread_data_list_add(t);
|
||||
|
||||
@ -187,13 +191,13 @@ os_thread_wrapper(void *thread_data)
|
||||
os_thread_cleanup(); // internal structures and joiners
|
||||
|
||||
BH_FREE(thread_data);
|
||||
sched_task_exit();// stop thread //clean
|
||||
return NULL; //never reached
|
||||
sched_task_exit(); // stop thread //clean
|
||||
return NULL; // never reached
|
||||
}
|
||||
|
||||
int
|
||||
os_thread_create(korp_tid *p_tid, thread_start_routine_t start,
|
||||
void *arg, unsigned int stack_size)
|
||||
os_thread_create(korp_tid *p_tid, thread_start_routine_t start, void *arg,
|
||||
unsigned int stack_size)
|
||||
{
|
||||
return os_thread_create_with_prio(p_tid, start, arg, stack_size,
|
||||
BH_THREAD_DEFAULT_PRIORITY);
|
||||
@ -223,8 +227,8 @@ os_thread_create_with_prio(korp_tid *p_tid, thread_start_routine_t start,
|
||||
thread_data->arg = arg;
|
||||
|
||||
/* Create the thread &*/
|
||||
if (!((tid = thread_create( thread_data->stack,
|
||||
stack_size,prio,0, os_thread_wrapper, thread_data,"WASM")))) {
|
||||
if (!((tid = thread_create(thread_data->stack, stack_size, prio, 0,
|
||||
os_thread_wrapper, thread_data, "WASM")))) {
|
||||
BH_FREE(thread_data);
|
||||
return BHT_ERROR;
|
||||
}
|
||||
@ -240,15 +244,14 @@ os_thread_create_with_prio(korp_tid *p_tid, thread_start_routine_t start,
|
||||
korp_tid
|
||||
os_self_thread()
|
||||
{
|
||||
return (korp_tid) thread_getpid();
|
||||
return (korp_tid)thread_getpid();
|
||||
}
|
||||
|
||||
int
|
||||
os_thread_join (korp_tid thread, void **value_ptr)
|
||||
os_thread_join(korp_tid thread, void **value_ptr)
|
||||
{
|
||||
// will test if thread is still working,
|
||||
// wait if it is
|
||||
// (void) value_ptr;
|
||||
os_thread_data *thread_data;
|
||||
os_thread_wait_node node;
|
||||
|
||||
@ -257,8 +260,8 @@ os_thread_join (korp_tid thread, void **value_ptr)
|
||||
|
||||
/* Get thread data */
|
||||
thread_data = thread_data_list_lookup(thread);
|
||||
if(thread_data == NULL){
|
||||
//thread not found
|
||||
if (thread_data == NULL) {
|
||||
// thread not found
|
||||
sema_destroy(&node.sem);
|
||||
return BHT_ERROR;
|
||||
}
|
||||
@ -277,22 +280,21 @@ os_thread_join (korp_tid thread, void **value_ptr)
|
||||
mutex_unlock(&thread_data->wait_list_lock);
|
||||
|
||||
sema_wait(&node.sem);
|
||||
//get the return value pointer conted may not be availible after return
|
||||
if(value_ptr) (* value_ptr) = node.ret;
|
||||
// get the return value pointer conted may not be availible after return
|
||||
if (value_ptr)
|
||||
(*value_ptr) = node.ret;
|
||||
/* Wait some time for the thread to be actually terminated */
|
||||
// TODO: k_sleep(100);
|
||||
// TODO: k_sleep(100);
|
||||
|
||||
//TODO: bump target prio to make it finish and free its resources
|
||||
// TODO: bump target prio to make it finish and free its resources
|
||||
thread_yield();
|
||||
|
||||
//node has done its job
|
||||
// node has done its job
|
||||
sema_destroy(&node.sem);
|
||||
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// int vm_mutex_trylock(korp_mutex *mutex)
|
||||
// {
|
||||
// return mutex_trylock(mutex);
|
||||
@ -308,7 +310,7 @@ os_mutex_init(korp_mutex *mutex)
|
||||
int
|
||||
os_mutex_destroy(korp_mutex *mutex)
|
||||
{
|
||||
(void) mutex;
|
||||
(void)mutex;
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
@ -316,15 +318,14 @@ int
|
||||
os_mutex_lock(korp_mutex *mutex)
|
||||
{
|
||||
mutex_lock(mutex);
|
||||
return 0; //Riot mutexes do not return until success
|
||||
return 0; // Riot mutexes do not return until success
|
||||
}
|
||||
|
||||
int
|
||||
os_mutex_unlock(korp_mutex *mutex)
|
||||
{
|
||||
mutex_unlock(mutex);
|
||||
return 0; //Riot mutexes do not return until success
|
||||
|
||||
return 0; // Riot mutexes do not return until success
|
||||
}
|
||||
|
||||
int
|
||||
@ -338,13 +339,13 @@ os_cond_init(korp_cond *cond)
|
||||
int
|
||||
os_cond_destroy(korp_cond *cond)
|
||||
{
|
||||
(void) cond;
|
||||
(void)cond;
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
os_cond_wait_internal(korp_cond *cond, korp_mutex *mutex,
|
||||
bool timed, uint64 useconds)
|
||||
os_cond_wait_internal(korp_cond *cond, korp_mutex *mutex, bool timed,
|
||||
uint64 useconds)
|
||||
{
|
||||
os_thread_wait_node *node;
|
||||
|
||||
@ -369,10 +370,10 @@ os_cond_wait_internal(korp_cond *cond, korp_mutex *mutex,
|
||||
|
||||
/* Unlock mutex, wait sem and lock mutex again */
|
||||
mutex_unlock(mutex);
|
||||
if(timed)
|
||||
if (timed)
|
||||
sema_wait(&node->sem);
|
||||
else
|
||||
sema_wait_timed(&node->sem,useconds);
|
||||
sema_wait_timed(&node->sem, useconds);
|
||||
mutex_lock(mutex);
|
||||
|
||||
/* Remove wait node from wait list */
|
||||
@ -401,8 +402,8 @@ os_cond_wait(korp_cond *cond, korp_mutex *mutex)
|
||||
int
|
||||
os_cond_reltimedwait(korp_cond *cond, korp_mutex *mutex, uint64 useconds)
|
||||
{
|
||||
return os_cond_wait_internal(cond, mutex,
|
||||
(useconds != BHT_WAIT_FOREVER), useconds);
|
||||
return os_cond_wait_internal(cond, mutex, (useconds != BHT_WAIT_FOREVER),
|
||||
useconds);
|
||||
}
|
||||
|
||||
int
|
||||
@ -417,11 +418,12 @@ os_cond_signal(korp_cond *cond)
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
uint8 *os_thread_get_stack_boundary()
|
||||
uint8 *
|
||||
os_thread_get_stack_boundary()
|
||||
{
|
||||
#if defined(DEVELHELP) || defined(SCHED_TEST_STACK) \
|
||||
|| defined(MODULE_MPU_STACK_GUARD)
|
||||
return (uint8*)thread_get_active()->stack_start;
|
||||
return (uint8 *)thread_get_active()->stack_start;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
|
||||
@ -12,4 +12,3 @@ os_time_get_boot_microsecond()
|
||||
{
|
||||
return xtimer_now_usec64();
|
||||
}
|
||||
|
||||
|
||||
@ -44,5 +44,4 @@ typedef rt_int16_t int16_t;
|
||||
typedef rt_uint64_t uint64_t;
|
||||
typedef rt_int64_t int64_t;
|
||||
|
||||
|
||||
#endif //RTTHREAD_PLATFORM_INTERNAL_H
|
||||
#endif /* RTTHREAD_PLATFORM_INTERNAL_H */
|
||||
|
||||
@ -8,67 +8,65 @@
|
||||
#include <platform_api_extension.h>
|
||||
|
||||
typedef struct os_malloc_list {
|
||||
void* real;
|
||||
void* used;
|
||||
void *real;
|
||||
void *used;
|
||||
rt_list_t node;
|
||||
}os_malloc_list_t;
|
||||
} os_malloc_list_t;
|
||||
|
||||
int bh_platform_init(void)
|
||||
int
|
||||
bh_platform_init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void bh_platform_destroy(void)
|
||||
{
|
||||
}
|
||||
void
|
||||
bh_platform_destroy(void)
|
||||
{}
|
||||
|
||||
void *os_malloc(unsigned size)
|
||||
void *
|
||||
os_malloc(unsigned size)
|
||||
{
|
||||
void *buf_origin;
|
||||
void *buf_fixed;
|
||||
rt_ubase_t *addr_field;
|
||||
|
||||
buf_origin = rt_malloc(size + 8 + sizeof(rt_ubase_t));
|
||||
buf_fixed = buf_origin + sizeof(void*);
|
||||
if ((rt_ubase_t)buf_fixed & 0x7)
|
||||
{
|
||||
buf_fixed = (void*)((rt_ubase_t)(buf_fixed+8)&(~7));
|
||||
buf_fixed = buf_origin + sizeof(void *);
|
||||
if ((rt_ubase_t)buf_fixed & 0x7) {
|
||||
buf_fixed = (void *)((rt_ubase_t)(buf_fixed + 8) & (~7));
|
||||
}
|
||||
|
||||
addr_field = buf_fixed - sizeof(rt_ubase_t);
|
||||
*addr_field = (rt_ubase_t )buf_origin;
|
||||
*addr_field = (rt_ubase_t)buf_origin;
|
||||
|
||||
return buf_fixed;
|
||||
|
||||
}
|
||||
|
||||
void *os_realloc(void *ptr, unsigned size)
|
||||
void *
|
||||
os_realloc(void *ptr, unsigned size)
|
||||
{
|
||||
|
||||
void* mem_origin;
|
||||
void* mem_new;
|
||||
void *mem_origin;
|
||||
void *mem_new;
|
||||
void *mem_new_fixed;
|
||||
rt_ubase_t *addr_field;
|
||||
|
||||
if (!ptr)
|
||||
{
|
||||
if (!ptr) {
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
addr_field = ptr - sizeof(rt_ubase_t);
|
||||
mem_origin = (void*)(*addr_field);
|
||||
mem_origin = (void *)(*addr_field);
|
||||
mem_new = rt_realloc(mem_origin, size + 8 + sizeof(rt_ubase_t));
|
||||
|
||||
if (mem_origin != mem_new)
|
||||
{
|
||||
if (mem_origin != mem_new) {
|
||||
mem_new_fixed = mem_new + sizeof(rt_ubase_t);
|
||||
if ((rt_ubase_t)mem_new_fixed & 0x7)
|
||||
{
|
||||
mem_new_fixed = (void*)((rt_ubase_t)(mem_new_fixed+8)&(~7));
|
||||
if ((rt_ubase_t)mem_new_fixed & 0x7) {
|
||||
mem_new_fixed = (void *)((rt_ubase_t)(mem_new_fixed + 8) & (~7));
|
||||
}
|
||||
|
||||
addr_field = mem_new_fixed - sizeof(rt_ubase_t);
|
||||
*addr_field = (rt_ubase_t )mem_new;
|
||||
*addr_field = (rt_ubase_t)mem_new;
|
||||
|
||||
return mem_new_fixed;
|
||||
}
|
||||
@ -76,115 +74,130 @@ void *os_realloc(void *ptr, unsigned size)
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void os_free(void *ptr)
|
||||
void
|
||||
os_free(void *ptr)
|
||||
{
|
||||
void* mem_origin;
|
||||
void *mem_origin;
|
||||
rt_ubase_t *addr_field;
|
||||
|
||||
if (ptr)
|
||||
{
|
||||
if (ptr) {
|
||||
addr_field = ptr - sizeof(rt_ubase_t);
|
||||
mem_origin = (void*)(*addr_field);
|
||||
mem_origin = (void *)(*addr_field);
|
||||
|
||||
rt_free(mem_origin);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
static char wamr_vprint_buf[RT_CONSOLEBUF_SIZE * 2];
|
||||
int os_printf(const char *format, ...)
|
||||
|
||||
int
|
||||
os_printf(const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
rt_size_t len = vsnprintf(wamr_vprint_buf, sizeof(wamr_vprint_buf)-1, format, ap);
|
||||
rt_size_t len =
|
||||
vsnprintf(wamr_vprint_buf, sizeof(wamr_vprint_buf) - 1, format, ap);
|
||||
wamr_vprint_buf[len] = 0x00;
|
||||
rt_kputs(wamr_vprint_buf);
|
||||
va_end(ap);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int os_vprintf(const char *format, va_list ap)
|
||||
int
|
||||
os_vprintf(const char *format, va_list ap)
|
||||
{
|
||||
rt_size_t len = vsnprintf(wamr_vprint_buf, sizeof(wamr_vprint_buf)-1, format, ap);
|
||||
rt_size_t len =
|
||||
vsnprintf(wamr_vprint_buf, sizeof(wamr_vprint_buf) - 1, format, ap);
|
||||
wamr_vprint_buf[len] = 0;
|
||||
rt_kputs(wamr_vprint_buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64 os_time_get_boot_microsecond(void)
|
||||
uint64
|
||||
os_time_get_boot_microsecond(void)
|
||||
{
|
||||
uint64 ret = rt_tick_get()*1000;
|
||||
uint64 ret = rt_tick_get() * 1000;
|
||||
ret /= RT_TICK_PER_SECOND;
|
||||
return ret;
|
||||
}
|
||||
|
||||
korp_tid os_self_thread(void)
|
||||
korp_tid
|
||||
os_self_thread(void)
|
||||
{
|
||||
return rt_thread_self();
|
||||
}
|
||||
|
||||
uint8 *os_thread_get_stack_boundary(void)
|
||||
uint8 *
|
||||
os_thread_get_stack_boundary(void)
|
||||
{
|
||||
rt_thread_t tid = rt_thread_self();
|
||||
return tid->stack_addr;
|
||||
}
|
||||
|
||||
int os_mutex_init(korp_mutex *mutex)
|
||||
int
|
||||
os_mutex_init(korp_mutex *mutex)
|
||||
{
|
||||
return rt_mutex_init(mutex, "wamr0", RT_IPC_FLAG_FIFO);
|
||||
}
|
||||
|
||||
int os_mutex_destroy(korp_mutex *mutex)
|
||||
int
|
||||
os_mutex_destroy(korp_mutex *mutex)
|
||||
{
|
||||
return rt_mutex_detach(mutex);
|
||||
}
|
||||
|
||||
int os_mutex_lock(korp_mutex *mutex)
|
||||
int
|
||||
os_mutex_lock(korp_mutex *mutex)
|
||||
{
|
||||
return rt_mutex_take(mutex, RT_WAITING_FOREVER);
|
||||
}
|
||||
|
||||
int os_mutex_unlock(korp_mutex *mutex)
|
||||
int
|
||||
os_mutex_unlock(korp_mutex *mutex)
|
||||
{
|
||||
return rt_mutex_release(mutex);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* functions below was not implement
|
||||
*/
|
||||
|
||||
int os_cond_init(korp_cond *cond)
|
||||
int
|
||||
os_cond_init(korp_cond *cond)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int os_cond_destroy(korp_cond *cond)
|
||||
int
|
||||
os_cond_destroy(korp_cond *cond)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int os_cond_wait(korp_cond *cond, korp_mutex *mutex)
|
||||
int
|
||||
os_cond_wait(korp_cond *cond, korp_mutex *mutex)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *os_mmap(void *hint, size_t size, int prot, int flags)
|
||||
void *
|
||||
os_mmap(void *hint, size_t size, int prot, int flags)
|
||||
{
|
||||
return rt_malloc(size);
|
||||
}
|
||||
|
||||
void os_munmap(void *addr, size_t size)
|
||||
void
|
||||
os_munmap(void *addr, size_t size)
|
||||
{
|
||||
rt_free(addr);
|
||||
}
|
||||
|
||||
int os_mprotect(void *addr, size_t size, int prot)
|
||||
int
|
||||
os_mprotect(void *addr, size_t size, int prot)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void os_dcache_flush(void)
|
||||
{
|
||||
}
|
||||
void
|
||||
os_dcache_flush(void)
|
||||
{}
|
||||
|
||||
@ -13,8 +13,7 @@ bh_platform_init()
|
||||
|
||||
void
|
||||
bh_platform_destroy()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
int
|
||||
os_printf(const char *format, ...)
|
||||
@ -42,4 +41,3 @@ os_vprintf(const char *format, va_list ap)
|
||||
return BH_VPRINTF(format, ap);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -58,8 +58,7 @@ typedef pthread_t korp_thread;
|
||||
#define os_thread_local_attribute __thread
|
||||
|
||||
#if WASM_DISABLE_HW_BOUND_CHECK == 0
|
||||
#if defined(BUILD_TARGET_X86_64) \
|
||||
|| defined(BUILD_TARGET_AMD_64) \
|
||||
#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64) \
|
||||
|| defined(BUILD_TARGET_AARCH64)
|
||||
|
||||
#include <setjmp.h>
|
||||
@ -76,15 +75,20 @@ typedef jmp_buf korp_jmpbuf;
|
||||
|
||||
typedef void (*os_signal_handler)(void *sig_addr);
|
||||
|
||||
int os_thread_signal_init(os_signal_handler handler);
|
||||
int
|
||||
os_thread_signal_init(os_signal_handler handler);
|
||||
|
||||
void os_thread_signal_destroy();
|
||||
void
|
||||
os_thread_signal_destroy();
|
||||
|
||||
bool os_thread_signal_inited();
|
||||
bool
|
||||
os_thread_signal_inited();
|
||||
|
||||
void os_signal_unmask();
|
||||
void
|
||||
os_signal_unmask();
|
||||
|
||||
void os_sigreturn();
|
||||
void
|
||||
os_sigreturn();
|
||||
#endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64 */
|
||||
#endif /* end of WASM_DISABLE_HW_BOUND_CHECK */
|
||||
|
||||
@ -93,4 +97,3 @@ void os_sigreturn();
|
||||
#endif
|
||||
|
||||
#endif /* end of _PLATFORM_INTERNAL_H */
|
||||
|
||||
|
||||
@ -60,6 +60,4 @@ os_getpagesize()
|
||||
|
||||
void
|
||||
os_dcache_flush(void)
|
||||
{
|
||||
}
|
||||
|
||||
{}
|
||||
|
||||
@ -53,15 +53,17 @@ typedef struct korp_cond {
|
||||
os_thread_wait_list thread_wait_list;
|
||||
} korp_cond;
|
||||
|
||||
unsigned os_getpagesize();
|
||||
void *os_mem_commit(void *ptr, size_t size, int flags);
|
||||
void os_mem_decommit(void *ptr, size_t size);
|
||||
unsigned
|
||||
os_getpagesize();
|
||||
void *
|
||||
os_mem_commit(void *ptr, size_t size, int flags);
|
||||
void
|
||||
os_mem_decommit(void *ptr, size_t size);
|
||||
|
||||
#define os_thread_local_attribute __declspec(thread)
|
||||
|
||||
#if WASM_DISABLE_HW_BOUND_CHECK == 0
|
||||
#if defined(BUILD_TARGET_X86_64) \
|
||||
|| defined(BUILD_TARGET_AMD_64)
|
||||
#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)
|
||||
|
||||
#include <setjmp.h>
|
||||
|
||||
@ -72,11 +74,14 @@ typedef jmp_buf korp_jmpbuf;
|
||||
#define os_setjmp setjmp
|
||||
#define os_longjmp longjmp
|
||||
|
||||
int os_thread_signal_init();
|
||||
int
|
||||
os_thread_signal_init();
|
||||
|
||||
void os_thread_signal_destroy();
|
||||
void
|
||||
os_thread_signal_destroy();
|
||||
|
||||
bool os_thread_signal_inited();
|
||||
bool
|
||||
os_thread_signal_inited();
|
||||
|
||||
#define os_signal_unmask() (void)0
|
||||
#define os_sigreturn() (void)0
|
||||
@ -89,4 +94,3 @@ bool os_thread_signal_inited();
|
||||
#endif
|
||||
|
||||
#endif /* end of _PLATFORM_INTERNAL_H */
|
||||
|
||||
|
||||
@ -22,6 +22,3 @@ os_free(void *ptr)
|
||||
{
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -79,8 +79,7 @@ os_munmap(void *addr, size_t size)
|
||||
}
|
||||
}
|
||||
#if TRACE_MEMMAP != 0
|
||||
printf("Unmap memory, addr: %p, request_size: %zu\n",
|
||||
addr, request_size);
|
||||
printf("Unmap memory, addr: %p, request_size: %zu\n", addr, request_size);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -95,8 +94,8 @@ os_mem_commit(void *addr, size_t size, int flags)
|
||||
return NULL;
|
||||
|
||||
#if TRACE_MEMMAP != 0
|
||||
printf("Commit memory, addr: %p, request_size: %zu, protect: 0x%x\n",
|
||||
addr, request_size, protect);
|
||||
printf("Commit memory, addr: %p, request_size: %zu, protect: 0x%x\n", addr,
|
||||
request_size, protect);
|
||||
#endif
|
||||
return VirtualAlloc((LPVOID)addr, request_size, MEM_COMMIT, protect);
|
||||
}
|
||||
@ -111,8 +110,8 @@ os_mem_decommit(void *addr, size_t size)
|
||||
return;
|
||||
|
||||
#if TRACE_MEMMAP != 0
|
||||
printf("Decommit memory, addr: %p, request_size: %zu\n",
|
||||
addr, request_size);
|
||||
printf("Decommit memory, addr: %p, request_size: %zu\n", addr,
|
||||
request_size);
|
||||
#endif
|
||||
VirtualFree((LPVOID)addr, request_size, MEM_DECOMMIT);
|
||||
}
|
||||
@ -134,4 +133,3 @@ os_mprotect(void *addr, size_t size, int prot)
|
||||
#endif
|
||||
return VirtualProtect((LPVOID)addr, request_size, protect, NULL);
|
||||
}
|
||||
|
||||
|
||||
@ -47,11 +47,16 @@ static os_thread_data supervisor_thread_data;
|
||||
/* Thread data key */
|
||||
static DWORD thread_data_key;
|
||||
|
||||
int os_sem_init(korp_sem* sem);
|
||||
int os_sem_destroy(korp_sem* sem);
|
||||
int os_sem_wait(korp_sem* sem);
|
||||
int os_sem_reltimed_wait(korp_sem* sem, uint64 useconds);
|
||||
int os_sem_signal(korp_sem* sem);
|
||||
int
|
||||
os_sem_init(korp_sem *sem);
|
||||
int
|
||||
os_sem_destroy(korp_sem *sem);
|
||||
int
|
||||
os_sem_wait(korp_sem *sem);
|
||||
int
|
||||
os_sem_reltimed_wait(korp_sem *sem, uint64 useconds);
|
||||
int
|
||||
os_sem_signal(korp_sem *sem);
|
||||
|
||||
int
|
||||
os_thread_sys_init()
|
||||
@ -141,8 +146,7 @@ os_thread_cleanup(void *retval)
|
||||
BH_FREE(thread_data);
|
||||
}
|
||||
|
||||
static unsigned __stdcall
|
||||
os_thread_wrapper(void *arg)
|
||||
static unsigned __stdcall os_thread_wrapper(void *arg)
|
||||
{
|
||||
os_thread_data *thread_data = arg;
|
||||
os_thread_data *parent = thread_data->parent;
|
||||
@ -202,9 +206,8 @@ os_thread_create_with_prio(korp_tid *p_tid, thread_start_routine_t start,
|
||||
goto fail3;
|
||||
|
||||
os_mutex_lock(&parent->wait_lock);
|
||||
if (!_beginthreadex(NULL, stack_size,
|
||||
os_thread_wrapper, thread_data,
|
||||
0, NULL)) {
|
||||
if (!_beginthreadex(NULL, stack_size, os_thread_wrapper, thread_data, 0,
|
||||
NULL)) {
|
||||
os_mutex_unlock(&parent->wait_lock);
|
||||
goto fail4;
|
||||
}
|
||||
@ -371,7 +374,7 @@ os_sem_wait(korp_sem *sem)
|
||||
|
||||
if (ret == WAIT_OBJECT_0)
|
||||
return BHT_OK;
|
||||
else if(ret == WAIT_TIMEOUT)
|
||||
else if (ret == WAIT_TIMEOUT)
|
||||
return (int)WAIT_TIMEOUT;
|
||||
else /* WAIT_FAILED or others */
|
||||
return BHT_ERROR;
|
||||
@ -404,7 +407,7 @@ os_sem_reltimed_wait(korp_sem *sem, uint64 useconds)
|
||||
|
||||
if (ret == WAIT_OBJECT_0)
|
||||
return BHT_OK;
|
||||
else if(ret == WAIT_TIMEOUT)
|
||||
else if (ret == WAIT_TIMEOUT)
|
||||
return (int)WAIT_TIMEOUT;
|
||||
else /* WAIT_FAILED or others */
|
||||
return BHT_ERROR;
|
||||
@ -414,8 +417,7 @@ int
|
||||
os_sem_signal(korp_sem *sem)
|
||||
{
|
||||
bh_assert(sem);
|
||||
return ReleaseSemaphore(*sem, 1, NULL) != FALSE
|
||||
? BHT_OK: BHT_ERROR;
|
||||
return ReleaseSemaphore(*sem, 1, NULL) != FALSE ? BHT_OK : BHT_ERROR;
|
||||
}
|
||||
|
||||
int
|
||||
@ -478,8 +480,8 @@ os_cond_destroy(korp_cond *cond)
|
||||
}
|
||||
|
||||
static int
|
||||
os_cond_wait_internal(korp_cond *cond, korp_mutex *mutex,
|
||||
bool timed, uint64 useconds)
|
||||
os_cond_wait_internal(korp_cond *cond, korp_mutex *mutex, bool timed,
|
||||
uint64 useconds)
|
||||
{
|
||||
os_thread_wait_node *node = &thread_data_current()->wait_node;
|
||||
|
||||
@ -567,7 +569,7 @@ os_thread_get_stack_boundary()
|
||||
GetCurrentThreadStackLimits(&low_limit, &high_limit);
|
||||
/* 4 pages are set unaccessible by system, we reserved
|
||||
one more page at least for safety */
|
||||
thread_stack_boundary = (uint8*)(uintptr_t)low_limit + page_size * 5;
|
||||
thread_stack_boundary = (uint8 *)(uintptr_t)low_limit + page_size * 5;
|
||||
return thread_stack_boundary;
|
||||
}
|
||||
|
||||
@ -601,4 +603,3 @@ os_thread_signal_inited()
|
||||
return thread_signal_inited;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@ -13,4 +13,3 @@ os_time_get_boot_microsecond()
|
||||
|
||||
return ((uint64)ts.tv_sec) * 1000 * 1000 + ((uint64)ts.tv_nsec) / 1000;
|
||||
}
|
||||
|
||||
|
||||
@ -37,7 +37,6 @@
|
||||
#include <arch/arm/aarch32/cortex_m/cmsis.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef BH_PLATFORM_ZEPHYR
|
||||
#define BH_PLATFORM_ZEPHYR
|
||||
#endif
|
||||
@ -62,6 +61,7 @@ typedef struct korp_cond {
|
||||
#define Z_TIMEOUT_MS(ms) ms
|
||||
#endif
|
||||
|
||||
/* clang-format off */
|
||||
void abort(void);
|
||||
size_t strspn(const char *s, const char *accept);
|
||||
size_t strcspn(const char *s, const char *reject);
|
||||
@ -91,6 +91,7 @@ double scalbn(double x, int n);
|
||||
unsigned long long int strtoull(const char *nptr, char **endptr, int base);
|
||||
double strtod(const char *nptr, char **endptr);
|
||||
float strtof(const char *nptr, char **endptr);
|
||||
/* clang-format on */
|
||||
|
||||
/**
|
||||
* @brief Allocate executable memroy
|
||||
@ -99,7 +100,7 @@ float strtof(const char *nptr, char **endptr);
|
||||
*
|
||||
* @return the address of the allocated memory if not NULL
|
||||
*/
|
||||
typedef void* (*exec_mem_alloc_func_t)(unsigned int size);
|
||||
typedef void *(*exec_mem_alloc_func_t)(unsigned int size);
|
||||
|
||||
/**
|
||||
* @brief Release executable memroy
|
||||
@ -108,8 +109,12 @@ typedef void* (*exec_mem_alloc_func_t)(unsigned int size);
|
||||
*/
|
||||
typedef void (*exec_mem_free_func_t)(void *addr);
|
||||
|
||||
/* Below function are called by external project to set related function pointers that
|
||||
* will be used to malloc/free executable memory. Otherwise default mechanise will be used. */
|
||||
void set_exec_mem_alloc_func(exec_mem_alloc_func_t alloc_func, exec_mem_free_func_t free_func);
|
||||
/* Below function are called by external project to set related function
|
||||
* pointers that will be used to malloc/free executable memory. Otherwise
|
||||
* default mechanise will be used.
|
||||
*/
|
||||
void
|
||||
set_exec_mem_alloc_func(exec_mem_alloc_func_t alloc_func,
|
||||
exec_mem_free_func_t free_func);
|
||||
|
||||
#endif
|
||||
|
||||
@ -29,9 +29,8 @@ disable_mpu_rasr_xn(void)
|
||||
MPU->RASR |= ~MPU_RASR_XN_Msk;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#endif /* end of CONFIG_ARM_MPU */
|
||||
#endif /* end of CONFIG_ARM_MPU */
|
||||
#endif
|
||||
|
||||
static int
|
||||
@ -84,8 +83,7 @@ os_realloc(void *ptr, unsigned size)
|
||||
|
||||
void
|
||||
os_free(void *ptr)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
#if 0
|
||||
struct out_context {
|
||||
@ -203,17 +201,17 @@ os_dcache_flush()
|
||||
SCB_CleanDCache();
|
||||
irq_unlock(key);
|
||||
#elif defined(CONFIG_SOC_CVF_EM7D) && defined(CONFIG_ARC_MPU) \
|
||||
&& defined (CONFIG_CACHE_FLUSHING)
|
||||
&& defined(CONFIG_CACHE_FLUSHING)
|
||||
__asm__ __volatile__("sync");
|
||||
z_arc_v2_aux_reg_write(_ARC_V2_DC_FLSH, BIT(0));
|
||||
__asm__ __volatile__("sync");
|
||||
#endif
|
||||
}
|
||||
|
||||
void set_exec_mem_alloc_func(exec_mem_alloc_func_t alloc_func,
|
||||
exec_mem_free_func_t free_func)
|
||||
void
|
||||
set_exec_mem_alloc_func(exec_mem_alloc_func_t alloc_func,
|
||||
exec_mem_free_func_t free_func)
|
||||
{
|
||||
exec_mem_alloc_func = alloc_func;
|
||||
exec_mem_free_func = free_func;
|
||||
}
|
||||
|
||||
|
||||
@ -6,13 +6,15 @@
|
||||
#include "platform_api_vmcore.h"
|
||||
#include "platform_api_extension.h"
|
||||
|
||||
/* clang-format off */
|
||||
#define bh_assert(v) do { \
|
||||
if (!(v)) { \
|
||||
printf("\nASSERTION FAILED: %s, at %s, line %d\n", \
|
||||
#v, __FILE__, __LINE__); \
|
||||
abort(); \
|
||||
} \
|
||||
} while (0)
|
||||
} while (0)
|
||||
/* clang-format on */
|
||||
|
||||
#if defined(CONFIG_ARM_MPU) || defined(CONFIG_ARC_MPU) \
|
||||
|| KERNEL_VERSION_NUMBER > 0x020300 /* version 2.3.0 */
|
||||
@ -28,13 +30,13 @@
|
||||
#endif
|
||||
|
||||
#if BH_ENABLE_ZEPHYR_MPU_STACK != 0
|
||||
static K_THREAD_STACK_ARRAY_DEFINE(mpu_stacks,
|
||||
BH_ZEPHYR_MPU_STACK_COUNT,
|
||||
static K_THREAD_STACK_ARRAY_DEFINE(mpu_stacks, BH_ZEPHYR_MPU_STACK_COUNT,
|
||||
BH_ZEPHYR_MPU_STACK_SIZE);
|
||||
static bool mpu_stack_allocated[BH_ZEPHYR_MPU_STACK_COUNT];
|
||||
static struct k_mutex mpu_stack_lock;
|
||||
|
||||
static char *mpu_stack_alloc()
|
||||
static char *
|
||||
mpu_stack_alloc()
|
||||
{
|
||||
int i;
|
||||
|
||||
@ -43,14 +45,15 @@ static char *mpu_stack_alloc()
|
||||
if (!mpu_stack_allocated[i]) {
|
||||
mpu_stack_allocated[i] = true;
|
||||
k_mutex_unlock(&mpu_stack_lock);
|
||||
return (char*)mpu_stacks[i];
|
||||
return (char *)mpu_stacks[i];
|
||||
}
|
||||
}
|
||||
k_mutex_unlock(&mpu_stack_lock);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void mpu_stack_free(char *stack)
|
||||
static void
|
||||
mpu_stack_free(char *stack)
|
||||
{
|
||||
int i;
|
||||
|
||||
@ -114,7 +117,8 @@ static struct k_mutex thread_obj_lock;
|
||||
/* Thread object list */
|
||||
static os_thread_obj *thread_obj_list = NULL;
|
||||
|
||||
static void thread_data_list_add(os_thread_data *thread_data)
|
||||
static void
|
||||
thread_data_list_add(os_thread_data *thread_data)
|
||||
{
|
||||
k_mutex_lock(&thread_data_lock, K_FOREVER);
|
||||
if (!thread_data_list)
|
||||
@ -137,7 +141,8 @@ static void thread_data_list_add(os_thread_data *thread_data)
|
||||
k_mutex_unlock(&thread_data_lock);
|
||||
}
|
||||
|
||||
static void thread_data_list_remove(os_thread_data *thread_data)
|
||||
static void
|
||||
thread_data_list_remove(os_thread_data *thread_data)
|
||||
{
|
||||
k_mutex_lock(&thread_data_lock, K_FOREVER);
|
||||
if (thread_data_list) {
|
||||
@ -174,7 +179,8 @@ thread_data_list_lookup(k_tid_t tid)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void thread_obj_list_add(os_thread_obj *thread_obj)
|
||||
static void
|
||||
thread_obj_list_add(os_thread_obj *thread_obj)
|
||||
{
|
||||
k_mutex_lock(&thread_obj_lock, K_FOREVER);
|
||||
if (!thread_obj_list)
|
||||
@ -187,7 +193,8 @@ static void thread_obj_list_add(os_thread_obj *thread_obj)
|
||||
k_mutex_unlock(&thread_obj_lock);
|
||||
}
|
||||
|
||||
static void thread_obj_list_reclaim()
|
||||
static void
|
||||
thread_obj_list_reclaim()
|
||||
{
|
||||
os_thread_obj *p, *p_prev;
|
||||
k_mutex_lock(&thread_obj_lock, K_FOREVER);
|
||||
@ -199,12 +206,14 @@ static void thread_obj_list_reclaim()
|
||||
thread_obj_list = p->next;
|
||||
BH_FREE(p);
|
||||
p = thread_obj_list;
|
||||
} else { /* p is not the head of list */
|
||||
}
|
||||
else { /* p is not the head of list */
|
||||
p_prev->next = p->next;
|
||||
BH_FREE(p);
|
||||
p = p_prev->next;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
p_prev = p;
|
||||
p = p->next;
|
||||
}
|
||||
@ -212,7 +221,8 @@ static void thread_obj_list_reclaim()
|
||||
k_mutex_unlock(&thread_obj_lock);
|
||||
}
|
||||
|
||||
int os_thread_sys_init()
|
||||
int
|
||||
os_thread_sys_init()
|
||||
{
|
||||
if (is_thread_sys_inited)
|
||||
return BHT_OK;
|
||||
@ -233,7 +243,8 @@ int os_thread_sys_init()
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
void os_thread_sys_destroy(void)
|
||||
void
|
||||
os_thread_sys_destroy(void)
|
||||
{
|
||||
if (is_thread_sys_inited) {
|
||||
is_thread_sys_inited = false;
|
||||
@ -247,7 +258,8 @@ thread_data_current()
|
||||
return thread_data_list_lookup(tid);
|
||||
}
|
||||
|
||||
static void os_thread_cleanup(void)
|
||||
static void
|
||||
os_thread_cleanup(void)
|
||||
{
|
||||
os_thread_data *thread_data = thread_data_current();
|
||||
|
||||
@ -269,32 +281,35 @@ static void os_thread_cleanup(void)
|
||||
thread_data_list_remove(thread_data);
|
||||
/* Set flag to true for the next thread creating to
|
||||
free the thread object */
|
||||
((os_thread_obj*) thread_data->tid)->to_be_freed = true;
|
||||
((os_thread_obj *)thread_data->tid)->to_be_freed = true;
|
||||
#if BH_ENABLE_ZEPHYR_MPU_STACK != 0
|
||||
mpu_stack_free(thread_data->stack);
|
||||
#endif
|
||||
BH_FREE(thread_data);
|
||||
}
|
||||
|
||||
static void os_thread_wrapper(void *start, void *arg, void *thread_data)
|
||||
static void
|
||||
os_thread_wrapper(void *start, void *arg, void *thread_data)
|
||||
{
|
||||
/* Set thread custom data */
|
||||
((os_thread_data*) thread_data)->tid = k_current_get();
|
||||
((os_thread_data *)thread_data)->tid = k_current_get();
|
||||
thread_data_list_add(thread_data);
|
||||
|
||||
((thread_start_routine_t) start)(arg);
|
||||
((thread_start_routine_t)start)(arg);
|
||||
os_thread_cleanup();
|
||||
}
|
||||
|
||||
int os_thread_create(korp_tid *p_tid, thread_start_routine_t start, void *arg,
|
||||
unsigned int stack_size)
|
||||
int
|
||||
os_thread_create(korp_tid *p_tid, thread_start_routine_t start, void *arg,
|
||||
unsigned int stack_size)
|
||||
{
|
||||
return os_thread_create_with_prio(p_tid, start, arg, stack_size,
|
||||
BH_THREAD_DEFAULT_PRIORITY);
|
||||
}
|
||||
|
||||
int os_thread_create_with_prio(korp_tid *p_tid, thread_start_routine_t start,
|
||||
void *arg, unsigned int stack_size, int prio)
|
||||
int
|
||||
os_thread_create_with_prio(korp_tid *p_tid, thread_start_routine_t start,
|
||||
void *arg, unsigned int stack_size, int prio)
|
||||
{
|
||||
korp_tid tid;
|
||||
os_thread_data *thread_data;
|
||||
@ -347,7 +362,7 @@ int os_thread_create_with_prio(korp_tid *p_tid, thread_start_routine_t start,
|
||||
|
||||
/* Set thread custom data */
|
||||
thread_data_list_add(thread_data);
|
||||
thread_obj_list_add((os_thread_obj*)tid);
|
||||
thread_obj_list_add((os_thread_obj *)tid);
|
||||
*p_tid = tid;
|
||||
return BHT_OK;
|
||||
|
||||
@ -362,14 +377,16 @@ fail1:
|
||||
return BHT_ERROR;
|
||||
}
|
||||
|
||||
korp_tid os_self_thread()
|
||||
korp_tid
|
||||
os_self_thread()
|
||||
{
|
||||
return (korp_tid)k_current_get();
|
||||
}
|
||||
|
||||
int os_thread_join(korp_tid thread, void **value_ptr)
|
||||
int
|
||||
os_thread_join(korp_tid thread, void **value_ptr)
|
||||
{
|
||||
(void) value_ptr;
|
||||
(void)value_ptr;
|
||||
os_thread_data *thread_data;
|
||||
os_thread_wait_node *node;
|
||||
|
||||
@ -407,30 +424,35 @@ int os_thread_join(korp_tid thread, void **value_ptr)
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int os_mutex_init(korp_mutex *mutex)
|
||||
int
|
||||
os_mutex_init(korp_mutex *mutex)
|
||||
{
|
||||
k_mutex_init(mutex);
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int os_recursive_mutex_init(korp_mutex *mutex)
|
||||
int
|
||||
os_recursive_mutex_init(korp_mutex *mutex)
|
||||
{
|
||||
k_mutex_init(mutex);
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int os_mutex_destroy(korp_mutex *mutex)
|
||||
int
|
||||
os_mutex_destroy(korp_mutex *mutex)
|
||||
{
|
||||
(void) mutex;
|
||||
(void)mutex;
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int os_mutex_lock(korp_mutex *mutex)
|
||||
int
|
||||
os_mutex_lock(korp_mutex *mutex)
|
||||
{
|
||||
return k_mutex_lock(mutex, K_FOREVER);
|
||||
}
|
||||
|
||||
int os_mutex_unlock(korp_mutex *mutex)
|
||||
int
|
||||
os_mutex_unlock(korp_mutex *mutex)
|
||||
{
|
||||
#if KERNEL_VERSION_NUMBER >= 0x020200 /* version 2.2.0 */
|
||||
return k_mutex_unlock(mutex);
|
||||
@ -440,21 +462,23 @@ int os_mutex_unlock(korp_mutex *mutex)
|
||||
#endif
|
||||
}
|
||||
|
||||
int os_cond_init(korp_cond *cond)
|
||||
int
|
||||
os_cond_init(korp_cond *cond)
|
||||
{
|
||||
k_mutex_init(&cond->wait_list_lock);
|
||||
cond->thread_wait_list = NULL;
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int os_cond_destroy(korp_cond *cond)
|
||||
int
|
||||
os_cond_destroy(korp_cond *cond)
|
||||
{
|
||||
(void) cond;
|
||||
(void)cond;
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
static int os_cond_wait_internal(korp_cond *cond, korp_mutex *mutex,
|
||||
bool timed, int mills)
|
||||
static int
|
||||
os_cond_wait_internal(korp_cond *cond, korp_mutex *mutex, bool timed, int mills)
|
||||
{
|
||||
os_thread_wait_node *node;
|
||||
|
||||
@ -499,12 +523,14 @@ static int os_cond_wait_internal(korp_cond *cond, korp_mutex *mutex,
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int os_cond_wait(korp_cond *cond, korp_mutex *mutex)
|
||||
int
|
||||
os_cond_wait(korp_cond *cond, korp_mutex *mutex)
|
||||
{
|
||||
return os_cond_wait_internal(cond, mutex, false, 0);
|
||||
}
|
||||
|
||||
int os_cond_reltimedwait(korp_cond *cond, korp_mutex *mutex, uint64 useconds)
|
||||
int
|
||||
os_cond_reltimedwait(korp_cond *cond, korp_mutex *mutex, uint64 useconds)
|
||||
{
|
||||
|
||||
if (useconds == BHT_WAIT_FOREVER) {
|
||||
@ -526,7 +552,8 @@ int os_cond_reltimedwait(korp_cond *cond, korp_mutex *mutex, uint64 useconds)
|
||||
}
|
||||
}
|
||||
|
||||
int os_cond_signal(korp_cond *cond)
|
||||
int
|
||||
os_cond_signal(korp_cond *cond)
|
||||
{
|
||||
/* Signal the head wait node of wait list */
|
||||
k_mutex_lock(&cond->wait_list_lock, K_FOREVER);
|
||||
@ -537,13 +564,13 @@ int os_cond_signal(korp_cond *cond)
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
uint8 *os_thread_get_stack_boundary()
|
||||
uint8 *
|
||||
os_thread_get_stack_boundary()
|
||||
{
|
||||
#if defined(CONFIG_THREAD_STACK_INFO)
|
||||
korp_tid thread = k_current_get();
|
||||
return (uint8*)thread->stack_info.start;
|
||||
return (uint8 *)thread->stack_info.start;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -10,4 +10,3 @@ os_time_get_boot_microsecond()
|
||||
{
|
||||
return k_uptime_get() * 1000;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user