re-org platform APIs, simplify porting process (#201)
Co-authored-by: Xu Jun <jun1.xu@intel.com>
This commit is contained in:
@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef _BH_ASSERT_H
|
||||
#define _BH_ASSERT_H
|
||||
|
||||
#include "bh_config.h"
|
||||
#include "bh_platform.h"
|
||||
|
||||
#ifdef BH_TEST
|
||||
# ifndef BH_DEBUG
|
||||
# error "BH_TEST should be defined under BH_DEBUG"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef BH_TEST
|
||||
# if defined(WIN32) || defined(__linux__)
|
||||
# else
|
||||
# error "Test case can not run on the current platform"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef BH_DEBUG
|
||||
|
||||
void bh_assert_internal(int v, const char *file_name, int line_number,
|
||||
const char *expr_string);
|
||||
#define bh_assert(expr) bh_assert_internal((int)(expr), __FILE__, __LINE__, #expr)
|
||||
|
||||
void bh_debug_internal(const char *file_name, int line_number,
|
||||
const char *fmt, ...);
|
||||
#if defined(WIN32)
|
||||
#define bh_debug(fmt, ...) bh_debug_internal(__FILE__, __LINE__, fmt, __VA_ARGS__)
|
||||
#elif defined(__linux__)
|
||||
#define bh_debug bh_debug_internal(__FILE__, __LINE__, "");printf
|
||||
#else
|
||||
#error "Unsupported platform"
|
||||
#endif
|
||||
|
||||
#else /* else of BH_DEBUG */
|
||||
|
||||
#define bh_debug if(0)printf
|
||||
|
||||
#endif /* end of BH_DEBUG */
|
||||
|
||||
#ifdef BH_TEST
|
||||
#define BH_STATIC
|
||||
#else
|
||||
#define BH_STATIC static
|
||||
#endif /* end of BH_TEST */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file bh_config.h
|
||||
* @date Tue Sep 13 14:53:17 2011
|
||||
*
|
||||
* @brief Configurations for different platforms and targets. Make
|
||||
* sure all source files in Beihai project include this header file
|
||||
* directly or indirectly.
|
||||
*/
|
||||
|
||||
#ifndef BH_CONFIG
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#define BH_KB (1024)
|
||||
#define BH_MB ((BH_KB)*1024)
|
||||
#define BH_GB ((BH_MB)*1024)
|
||||
|
||||
#ifndef BH_MALLOC
|
||||
#define BH_MALLOC os_malloc
|
||||
#endif
|
||||
|
||||
#ifndef BH_FREE
|
||||
#define BH_FREE os_free
|
||||
#endif
|
||||
|
||||
#ifndef WA_MALLOC
|
||||
#include <stdlib.h>
|
||||
#define WA_MALLOC malloc
|
||||
#endif
|
||||
|
||||
#ifndef WA_FREE
|
||||
#include <stdlib.h>
|
||||
#define WA_FREE free
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void *wasm_runtime_malloc(unsigned int size);
|
||||
void wasm_runtime_free(void *ptr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* end of BH_CONFIG */
|
||||
|
||||
@ -1,25 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef BH_PLATFORM_LOG
|
||||
#define BH_PLATFORM_LOG
|
||||
|
||||
#include "bh_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void bh_log_emit(const char *fmt, va_list ap);
|
||||
|
||||
int bh_fprintf(void *stream, const char *fmt, ...);
|
||||
|
||||
int bh_fflush(void *stream);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,398 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef _BH_THREAD_H
|
||||
#define _BH_THREAD_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "bh_config.h"
|
||||
#include "bh_platform.h"
|
||||
|
||||
#define BH_MAX_THREAD 32
|
||||
#define BH_MAX_TLS_NUM 2
|
||||
|
||||
#define BHT_ERROR (-1)
|
||||
#define BHT_TIMED_OUT (1)
|
||||
#define BHT_OK (0)
|
||||
|
||||
#define BHT_NO_WAIT 0x00000000
|
||||
#define BHT_WAIT_FOREVER 0xFFFFFFFF
|
||||
|
||||
/**
|
||||
* vm_thread_sys_init
|
||||
* initiation function for beihai thread system. Invoked at the beginning of beihai intiation.
|
||||
*
|
||||
* @return 0 if succuess.
|
||||
*/
|
||||
int _vm_thread_sys_init(void);
|
||||
#ifdef _INSTRUMENT_TEST_ENABLED
|
||||
int vm_thread_sys_init_instr(const char*func_name);
|
||||
#define vm_thread_sys_init(void) vm_thread_sys_init_instr(__FUNCTION__)
|
||||
#else
|
||||
#define vm_thread_sys_init _vm_thread_sys_init
|
||||
#endif
|
||||
|
||||
void vm_thread_sys_destroy(void);
|
||||
|
||||
/**
|
||||
* This function creates a thread
|
||||
*
|
||||
* @param p_tid [OUTPUT] the pointer of tid
|
||||
* @param start main routine of the thread
|
||||
* @param arg argument passed to main routine
|
||||
* @param stack_size bytes of stack size
|
||||
*
|
||||
* @return 0 if success.
|
||||
*/
|
||||
int _vm_thread_create(korp_tid *p_tid, thread_start_routine_t start, void *arg,
|
||||
unsigned int stack_size);
|
||||
#ifdef _INSTRUMENT_TEST_ENABLED
|
||||
int vm_thread_create_instr(korp_tid *p_tid, thread_start_routine_t start, void *arg, unsigned int stack_size, const char*func_name);
|
||||
#define vm_thread_create(p_tid, start, arg, stack_size) vm_thread_create_instr(p_tid, start, arg, stack_size, __FUNCTION__)
|
||||
#else
|
||||
#define vm_thread_create _vm_thread_create
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function creates a thread
|
||||
*
|
||||
* @param p_tid [OUTPUT] the pointer of tid
|
||||
* @param start main routine of the thread
|
||||
* @param arg argument passed to main routine
|
||||
* @param stack_size bytes of stack size
|
||||
* @param prio the priority
|
||||
*
|
||||
* @return 0 if success.
|
||||
*/
|
||||
int _vm_thread_create_with_prio(korp_tid *p_tid, thread_start_routine_t start,
|
||||
void *arg, unsigned int stack_size, int prio);
|
||||
#ifdef _INSTRUMENT_TEST_ENABLED
|
||||
int vm_thread_create_with_prio_instr(korp_tid *p_tid, thread_start_routine_t start, void *arg, unsigned int stack_size, int prio, const char*func_name);
|
||||
#define vm_thread_create_with_prio(p_tid, start, arg, stack_size) vm_thread_create_instr(p_tid, start, arg, stack_size, prio, __FUNCTION__)
|
||||
#else
|
||||
#define vm_thread_create_with_prio _vm_thread_create_with_prio
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function never returns.
|
||||
*
|
||||
* @param code not used
|
||||
*/
|
||||
void vm_thread_exit(void *code);
|
||||
|
||||
/**
|
||||
* This function gets current thread id
|
||||
*
|
||||
* @return current thread id
|
||||
*/
|
||||
korp_tid _vm_self_thread(void);
|
||||
#ifdef _INSTRUMENT_TEST_ENABLED
|
||||
korp_tid vm_self_thread_instr(const char*func_name);
|
||||
#define vm_self_thread(void) vm_self_thread_instr(__FUNCTION__)
|
||||
#else
|
||||
#define vm_self_thread _vm_self_thread
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function saves a pointer in thread local storage. One thread can only save one pointer.
|
||||
*
|
||||
* @param idx tls array index
|
||||
* @param ptr pointer need save as TLS
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int _vm_tls_put(unsigned idx, void *ptr);
|
||||
#ifdef _INSTRUMENT_TEST_ENABLED
|
||||
int vm_tls_put_instr(unsigned idx, void *ptr, const char*func_name);
|
||||
#define vm_tls_put(idx, ptr) vm_tls_put_instr(idx, ptr, __FUNCTION__)
|
||||
#else
|
||||
#define vm_tls_put _vm_tls_put
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function gets a pointer saved in TLS.
|
||||
*
|
||||
* @param idx tls array index
|
||||
*
|
||||
* @return the pointer saved in TLS.
|
||||
*/
|
||||
void *_vm_tls_get(unsigned idx);
|
||||
#ifdef _INSTRUMENT_TEST_ENABLED
|
||||
void *vm_tls_get_instr(unsigned idx, const char*func_name);
|
||||
#define vm_tls_get(idx) vm_tls_get_instr(idx, __FUNCTION__)
|
||||
#else
|
||||
#define vm_tls_get _vm_tls_get
|
||||
#endif
|
||||
|
||||
#define vm_thread_testcancel(void)
|
||||
|
||||
/**
|
||||
* This function creates a non-recursive mutex
|
||||
*
|
||||
* @param mutex [OUTPUT] pointer to mutex initialized.
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int _vm_mutex_init(korp_mutex *mutex);
|
||||
#ifdef INSTRUMENT_TEST_ENABLED
|
||||
int vm_mutex_init_instr(korp_mutex *mutex, const char*func_name);
|
||||
#define vm_mutex_init(mutex) vm_mutex_init_instr(mutex, __FUNCTION__)
|
||||
#else
|
||||
#define vm_mutex_init _vm_mutex_init
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function creates a recursive mutex
|
||||
*
|
||||
* @param mutex [OUTPUT] pointer to mutex initialized.
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int _vm_recursive_mutex_init(korp_mutex *mutex);
|
||||
#ifdef INSTRUMENT_TEST_ENABLED
|
||||
int vm_recursive_mutex_init_instr(korp_mutex *mutex, const char*func_name);
|
||||
#define vm_recursive_mutex_init(mutex) vm_recursive_mutex_init_instr(mutex, __FUNCTION__)
|
||||
#else
|
||||
#define vm_recursive_mutex_init _vm_recursive_mutex_init
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function destroys a mutex
|
||||
*
|
||||
* @param mutex pointer to mutex need destroy
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int _vm_mutex_destroy(korp_mutex *mutex);
|
||||
#ifdef _INSTRUMENT_TEST_ENABLED
|
||||
int vm_mutex_destroy_instr(korp_mutex *mutex, const char*func_name);
|
||||
#define vm_mutex_destroy(mutex) vm_mutex_destroy_instr(mutex, __FUNCTION__)
|
||||
#else
|
||||
#define vm_mutex_destroy _vm_mutex_destroy
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function locks the mutex
|
||||
*
|
||||
* @param mutex pointer to mutex need lock
|
||||
*
|
||||
* @return Void
|
||||
*/
|
||||
void vm_mutex_lock(korp_mutex *mutex);
|
||||
|
||||
/**
|
||||
* This function locks the mutex without waiting
|
||||
*
|
||||
* @param mutex pointer to mutex need lock
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int vm_mutex_trylock(korp_mutex *mutex);
|
||||
|
||||
/**
|
||||
* This function unlocks the mutex
|
||||
*
|
||||
* @param mutex pointer to mutex need unlock
|
||||
*
|
||||
* @return Void
|
||||
*/
|
||||
void vm_mutex_unlock(korp_mutex *mutex);
|
||||
|
||||
/**
|
||||
* This function creates a semaphone
|
||||
*
|
||||
* @param sem [OUTPUT] pointer to semaphone
|
||||
* @param c counter of semaphone
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int _vm_sem_init(korp_sem *sem, unsigned int c);
|
||||
#ifdef _INSTRUMENT_TEST_ENABLED
|
||||
int vm_sem_init_instr(korp_sem *sem, unsigned int c, const char*func_name);
|
||||
#define vm_sem_init(sem, c) vm_sem_init_instr(sem, c, __FUNCTION__)
|
||||
#else
|
||||
#define vm_sem_init _vm_sem_init
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function destroys a semaphone
|
||||
*
|
||||
* @param sem pointer to semaphone need destroy
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int _vm_sem_destroy(korp_sem *sem);
|
||||
#ifdef _INSTRUMENT_TEST_ENABLED
|
||||
int vm_sem_destroy_instr(korp_sem *sem, const char*func_name);
|
||||
#define vm_sem_destroy(sem) vm_sem_destroy_instr(sem, __FUNCTION__)
|
||||
#else
|
||||
#define vm_sem_destroy _vm_sem_destroy
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function performs wait operation on semaphone
|
||||
*
|
||||
* @param sem pointer to semaphone need perform wait operation
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int _vm_sem_wait(korp_sem *sem);
|
||||
#ifdef _INSTRUMENT_TEST_ENABLED
|
||||
int vm_sem_wait_instr(korp_sem *sem, const char*func_name);
|
||||
#define vm_sem_wait(sem) vm_sem_wait_instr(sem, __FUNCTION__)
|
||||
#else
|
||||
#define vm_sem_wait _vm_sem_wait
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function performs wait operation on semaphone with a timeout
|
||||
*
|
||||
* @param sem pointer to semaphone need perform wait operation
|
||||
* @param mills wait milliseconds to return
|
||||
*
|
||||
* @return 0 if success
|
||||
* @return BH_TIMEOUT if time out
|
||||
*/
|
||||
int _vm_sem_reltimedwait(korp_sem *sem, int mills);
|
||||
#ifdef _INSTRUMENT_TEST_ENABLED
|
||||
int vm_sem_reltimedwait_instr(korp_sem *sem, int mills, const char*func_name);
|
||||
#define vm_sem_reltimedwait(sem, mills) vm_sem_reltimedwait_instr(sem, mills, __FUNCTION__)
|
||||
#else
|
||||
#define vm_sem_reltimedwait _vm_sem_reltimedwait
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function performs post operation on semaphone
|
||||
*
|
||||
* @param sem pointer to semaphone need perform post operation
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int _vm_sem_post(korp_sem *sem);
|
||||
#ifdef _INSTRUMENT_TEST_ENABLED
|
||||
int vm_sem_post_instr(korp_sem *sem, const char*func_name);
|
||||
#define vm_sem_post(sem) vm_sem_post_instr(sem, __FUNCTION__)
|
||||
#else
|
||||
#define vm_sem_post _vm_sem_post
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function creates a condition variable
|
||||
*
|
||||
* @param cond [OUTPUT] pointer to condition variable
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int _vm_cond_init(korp_cond *cond);
|
||||
#ifdef INSTRUMENT_TEST_ENABLED
|
||||
int vm_cond_init_instr(korp_cond *cond, const char*func_name);
|
||||
#define vm_cond_init(cond) vm_cond_init_instr(cond, __FUNCTION__)
|
||||
#else
|
||||
#define vm_cond_init _vm_cond_init
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function destroys condition variable
|
||||
*
|
||||
* @param cond pointer to condition variable
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int _vm_cond_destroy(korp_cond *cond);
|
||||
#ifdef _INSTRUMENT_TEST_ENABLED
|
||||
int vm_cond_destroy_instr(korp_cond *cond, const char*func_name);
|
||||
#define vm_cond_destroy(cond) vm_cond_destroy_instr(cond, __FUNCTION__)
|
||||
#else
|
||||
#define vm_cond_destroy _vm_cond_destroy
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function will block on a condition varible.
|
||||
*
|
||||
* @param cond pointer to condition variable
|
||||
* @param mutex pointer to mutex to protect the condition variable
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int _vm_cond_wait(korp_cond *cond, korp_mutex *mutex);
|
||||
#ifdef _INSTRUMENT_TEST_ENABLED
|
||||
int vm_cond_wait_instr(korp_cond *cond, korp_mutex *mutex, const char*func_name);
|
||||
#define vm_cond_wait(cond, mutex) vm_cond_wait_instr(cond, mutex, __FUNCTION__)
|
||||
#else
|
||||
#define vm_cond_wait _vm_cond_wait
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function will block on a condition varible or return if time specified passes.
|
||||
*
|
||||
* @param cond pointer to condition variable
|
||||
* @param mutex pointer to mutex to protect the condition variable
|
||||
* @param mills milliseconds to wait
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int _vm_cond_reltimedwait(korp_cond *cond, korp_mutex *mutex, int mills);
|
||||
#ifdef _INSTRUMENT_TEST_ENABLED
|
||||
int vm_cond_reltimedwait_instr(korp_cond *cond, korp_mutex *mutex, int mills, const char*func_name);
|
||||
#define vm_cond_reltimedwait(cond, mutex, mills) vm_cond_reltimedwait_instr(cond, mutex, mills, __FUNCTION__)
|
||||
#else
|
||||
#define vm_cond_reltimedwait _vm_cond_reltimedwait
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function signals the condition variable
|
||||
*
|
||||
* @param cond condition variable
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int _vm_cond_signal(korp_cond *cond);
|
||||
#ifdef _INSTRUMENT_TEST_ENABLED
|
||||
int vm_cond_signal_instr(korp_cond *cond, const char*func_name);
|
||||
#define vm_cond_signal(cond) vm_cond_signal_instr(cond, __FUNCTION__)
|
||||
#else
|
||||
#define vm_cond_signal _vm_cond_signal
|
||||
#endif
|
||||
|
||||
int _vm_cond_broadcast(korp_cond *cond);
|
||||
#ifdef _INSTRUMENT_TEST_ENABLED
|
||||
int vm_cond_broadcast_instr(korp_cond *cond, const char*func_name);
|
||||
#define vm_cond_broadcast(cond) vm_cond_broadcast_instr(cond, __FUNCTION__)
|
||||
#else
|
||||
#define vm_cond_broadcast _vm_cond_broadcast
|
||||
#endif
|
||||
|
||||
int _vm_thread_cancel(korp_tid thread);
|
||||
#ifdef _INSTRUMENT_TEST_ENABLED
|
||||
int vm_thread_cancel_instr(korp_tid thread, const char*func_name);
|
||||
#define vm_thread_cancel(thread) vm_thread_cancel_instr(thread, __FUNCTION__)
|
||||
#else
|
||||
#define vm_thread_cancel _vm_thread_cancel
|
||||
#endif
|
||||
|
||||
int _vm_thread_join(korp_tid thread, void **value_ptr, int mills);
|
||||
#ifdef _INSTRUMENT_TEST_ENABLED
|
||||
int vm_thread_join_instr(korp_tid thread, void **value_ptr, int mills, const char*func_name);
|
||||
#define vm_thread_join(thread, value_ptr, mills) vm_thread_join_instr(thread, value_ptr, mills, __FUNCTION__)
|
||||
#else
|
||||
#define vm_thread_join _vm_thread_join
|
||||
#endif
|
||||
|
||||
int _vm_thread_detach(korp_tid thread);
|
||||
#ifdef _INSTRUMENT_TEST_ENABLED
|
||||
int vm_thread_detach_instr(korp_tid thread, const char*func_name);
|
||||
#define vm_thread_detach(thread) vm_thread_detach_instr(thread, __FUNCTION__)
|
||||
#else
|
||||
#define vm_thread_detach _vm_thread_detach
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* #ifndef _BH_THREAD_H */
|
||||
@ -1,86 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef _BH_TIME_H
|
||||
#define _BH_TIME_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "bh_config.h"
|
||||
#include "bh_types.h"
|
||||
#include "bh_platform.h"
|
||||
|
||||
/*
|
||||
* This function returns milliseconds per tick.
|
||||
* @return milliseconds per tick.
|
||||
*/
|
||||
extern uint64 _bh_time_get_tick_millisecond(void);
|
||||
#ifdef _INSTRUMENT_TEST_ENABLED
|
||||
extern uint64 bh_time_get_tick_millisecond_instr(const char*func_name);
|
||||
#define bh_time_get_tick_millisecond() bh_time_get_tick_millisecond_instr(__FUNCTION__)
|
||||
#else
|
||||
#define bh_time_get_tick_millisecond _bh_time_get_tick_millisecond
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This function returns milliseconds after boot.
|
||||
* @return milliseconds after boot.
|
||||
*/
|
||||
extern uint64 _bh_time_get_boot_millisecond(void);
|
||||
#ifdef _INSTRUMENT_TEST_ENABLED
|
||||
extern uint64 bh_time_get_boot_millisecond_instr(const char*func_name);
|
||||
#define bh_time_get_boot_millisecond() bh_time_get_boot_millisecond_instr(__FUNCTION__)
|
||||
#else
|
||||
#define bh_time_get_boot_millisecond _bh_time_get_boot_millisecond
|
||||
#endif
|
||||
|
||||
extern uint32 bh_get_tick_sec();
|
||||
#define bh_get_tick_ms _bh_time_get_boot_millisecond
|
||||
|
||||
/*
|
||||
* This function returns GMT milliseconds since from 1970.1.1, AKA UNIX time.
|
||||
* @return milliseconds since from 1970.1.1.
|
||||
*/
|
||||
extern uint64 _bh_time_get_millisecond_from_1970(void);
|
||||
#ifdef _INSTRUMENT_TEST_ENABLED
|
||||
extern uint64 bh_time_get_millisecond_from_1970_instr(const char*func_name);
|
||||
#define bh_time_get_millisecond_from_1970() bh_time_get_millisecond_from_1970_instr(__FUNCTION__)
|
||||
#else
|
||||
#define bh_time_get_millisecond_from_1970 _bh_time_get_millisecond_from_1970
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function sets timezone with specific hours.
|
||||
*
|
||||
* @param hours represents the deviation (in hours) of the local time from GMT (can be a positive or a negative number)
|
||||
* @param half_hour if true, adds half an hour to the local time calculation. For example, if hours=(+5) then the time will be GMT +5:30; if hours=(-5) then the time will be GMT -4:30.
|
||||
* @param daylight_save if true, applies the daylight saving scheme when calculating the local time (adds one hour to the local time calculation)
|
||||
*/
|
||||
extern void bh_set_timezone(int hours, int half_hour, int daylight_save);
|
||||
|
||||
/**
|
||||
* This functions returns the offset in seconds which needs to be added GMT to get the local time.
|
||||
*
|
||||
*
|
||||
* @return offset in secords which needs to be added GMT to get the local time.
|
||||
*/
|
||||
extern int bh_get_timezone_offset(void);
|
||||
|
||||
size_t bh_time_strftime(char *s, size_t max, const char *format, int64 time);
|
||||
|
||||
#ifdef _INSTRUMENT_TEST_ENABLED
|
||||
size_t bh_time_strftime_instr(char *s, size_t max, const char *format, int64 time, const char*func_name);
|
||||
#define bh_time_strftime(s, max, format, time) bh_time_strftime_instr(s, max, format, time, __FUNCTION__)
|
||||
#else
|
||||
#define bh_time_strftime _bh_time_strftime
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef _BH_TYPES_H
|
||||
#define _BH_TYPES_H
|
||||
|
||||
#include "bh_config.h"
|
||||
|
||||
typedef unsigned char uint8;
|
||||
typedef char int8;
|
||||
typedef unsigned short uint16;
|
||||
typedef short int16;
|
||||
typedef unsigned int uint32;
|
||||
typedef int int32;
|
||||
typedef float float32;
|
||||
typedef double float64;
|
||||
|
||||
#include "bh_platform.h"
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL (void*)0
|
||||
#endif
|
||||
|
||||
#ifndef __cplusplus
|
||||
#define true 1
|
||||
#define false 0
|
||||
#define inline __inline
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
140
core/shared/platform/include/platform_api_extension.h
Normal file
140
core/shared/platform/include/platform_api_extension.h
Normal file
@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef PLATFORM_API_EXTENSION_H
|
||||
#define PLATFORM_API_EXTENSION_H
|
||||
|
||||
#include "platform_common.h"
|
||||
/**
|
||||
* The related data structures should be defined
|
||||
* in platform_internal.h
|
||||
**/
|
||||
#include "platform_internal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************
|
||||
* *
|
||||
* Extension interface *
|
||||
* *
|
||||
***************************************************/
|
||||
|
||||
/**
|
||||
* NOTES:
|
||||
* 1. If you are building VM core only, it must be implemented to
|
||||
* enable multi-thread support, otherwise no need to implement it
|
||||
* 2. To build the app-mgr and app-framework, you must implement it
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Ceates a thread
|
||||
*
|
||||
* @param p_tid [OUTPUT] the pointer of tid
|
||||
* @param start main routine of the thread
|
||||
* @param arg argument passed to main routine
|
||||
* @param stack_size bytes of stack size
|
||||
*
|
||||
* @return 0 if success.
|
||||
*/
|
||||
int os_thread_create(korp_tid *p_tid, thread_start_routine_t start, void *arg,
|
||||
unsigned int stack_size);
|
||||
|
||||
/**
|
||||
* Creates a thread with priority
|
||||
*
|
||||
* @param p_tid [OUTPUT] the pointer of tid
|
||||
* @param start main routine of the thread
|
||||
* @param arg argument passed to main routine
|
||||
* @param stack_size bytes of stack size
|
||||
* @param prio the priority
|
||||
*
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* Waits for the thread specified by thread to terminate
|
||||
*
|
||||
* @param thread the thread to wait
|
||||
* @param retval if not NULL, output the exit status of the terminated thread
|
||||
*
|
||||
* @return return 0 if success
|
||||
*/
|
||||
int os_thread_join(korp_tid thread, void **retval);
|
||||
|
||||
/**
|
||||
* Suspend execution of the calling thread for (at least)
|
||||
* usec microseconds
|
||||
*
|
||||
* @param return 0 if success, -1 otherwise
|
||||
*/
|
||||
int os_usleep(uint32 usec);
|
||||
|
||||
/**
|
||||
* Creates a recursive mutex
|
||||
*
|
||||
* @param mutex [OUTPUT] pointer to mutex initialized.
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int os_recursive_mutex_init(korp_mutex *mutex);
|
||||
|
||||
/**
|
||||
* This function creates a condition variable
|
||||
*
|
||||
* @param cond [OUTPUT] pointer to condition variable
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int os_cond_init(korp_cond *cond);
|
||||
|
||||
/**
|
||||
* This function destroys condition variable
|
||||
*
|
||||
* @param cond pointer to condition variable
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int os_cond_destroy(korp_cond *cond);
|
||||
|
||||
/**
|
||||
* Wait a condition variable.
|
||||
*
|
||||
* @param cond pointer to condition variable
|
||||
* @param mutex pointer to mutex to protect the condition variable
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int os_cond_wait(korp_cond *cond, korp_mutex *mutex);
|
||||
|
||||
/**
|
||||
* Wait a condition varible or return if time specified passes.
|
||||
*
|
||||
* @param cond pointer to condition variable
|
||||
* @param mutex pointer to mutex to protect the condition variable
|
||||
* @param useconds microseconds to wait
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int os_cond_reltimedwait(korp_cond *cond, korp_mutex *mutex, int useconds);
|
||||
|
||||
/**
|
||||
* Signals the condition variable
|
||||
*
|
||||
* @param cond condition variable
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int os_cond_signal(korp_cond *cond);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* #ifndef PLATFORM_API_EXTENSION_H */
|
||||
122
core/shared/platform/include/platform_api_vmcore.h
Normal file
122
core/shared/platform/include/platform_api_vmcore.h
Normal file
@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef _PLATFORM_API_VMCORE_H
|
||||
#define _PLATFORM_API_VMCORE_H
|
||||
|
||||
#include "platform_common.h"
|
||||
#include "platform_internal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/****************************************************
|
||||
* Section 1 *
|
||||
* Interfaces required by the runtime *
|
||||
****************************************************/
|
||||
|
||||
/**
|
||||
* Initialize the platform internal resources if needed,
|
||||
* this function is called by wasm_runtime_init() and
|
||||
* wasm_runtime_full_init()
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int bh_platform_init();
|
||||
|
||||
/**
|
||||
* Destroy the platform internal resources if needed,
|
||||
* this function is called by wasm_runtime_destroy()
|
||||
*/
|
||||
void bh_platform_destroy();
|
||||
|
||||
/**
|
||||
******** memory allocator APIs **********
|
||||
*/
|
||||
|
||||
void *os_malloc(unsigned size);
|
||||
|
||||
void *os_realloc(void *ptr, unsigned size);
|
||||
|
||||
void os_free(void *ptr);
|
||||
|
||||
/**
|
||||
* Note: the above APIs can simply return NULL if wasm runtime
|
||||
* isn't initialized with Alloc_With_System_Allocator.
|
||||
* Refer to wasm_runtime_full_init().
|
||||
*/
|
||||
|
||||
|
||||
int os_printf(const char *format, ...);
|
||||
|
||||
int os_vprintf(const char *format, va_list ap);
|
||||
|
||||
/**
|
||||
* Get microseconds after boot.
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
************** mutext APIs ***********
|
||||
* vmcore: Not required until pthread is supported by runtime
|
||||
* app-mgr: Must be implemented
|
||||
*/
|
||||
|
||||
int os_mutex_init(korp_mutex *mutex);
|
||||
|
||||
int os_mutex_destroy(korp_mutex *mutex);
|
||||
|
||||
void os_mutex_lock(korp_mutex *mutex);
|
||||
|
||||
void os_mutex_unlock(korp_mutex *mutex);
|
||||
|
||||
|
||||
/**************************************************
|
||||
* Section 2 *
|
||||
* APIs required by WAMR AOT *
|
||||
**************************************************/
|
||||
|
||||
/* Memory map modes */
|
||||
enum {
|
||||
MMAP_PROT_NONE = 0,
|
||||
MMAP_PROT_READ = 1,
|
||||
MMAP_PROT_WRITE = 2,
|
||||
MMAP_PROT_EXEC = 4
|
||||
};
|
||||
|
||||
/* Memory map flags */
|
||||
enum {
|
||||
MMAP_MAP_NONE = 0,
|
||||
/* Put the mapping into 0 to 2 G, supported only on x86_64 */
|
||||
MMAP_MAP_32BIT = 1,
|
||||
/* Don't interpret addr as a hint: place the mapping at exactly
|
||||
that address. */
|
||||
MMAP_MAP_FIXED = 2
|
||||
};
|
||||
|
||||
void *os_mmap(void *hint, unsigned int size, int prot, int flags);
|
||||
void os_munmap(void *addr, uint32 size);
|
||||
int os_mprotect(void *addr, uint32 size, int prot);
|
||||
|
||||
/**
|
||||
* Flush cpu data cache, in some CPUs, after applying relocation to the
|
||||
* AOT code, the code may haven't been written back to the cpu data cache,
|
||||
* 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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* #ifndef _PLATFORM_API_VMCORE_H */
|
||||
73
core/shared/platform/include/platform_common.h
Normal file
73
core/shared/platform/include/platform_common.h
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef _PLATFORM_COMMON_H
|
||||
#define _PLATFORM_COMMON_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../../../config.h"
|
||||
#include "platform_internal.h"
|
||||
|
||||
#define BH_MAX_THREAD 32
|
||||
|
||||
#define BHT_ERROR (-1)
|
||||
#define BHT_TIMED_OUT (1)
|
||||
#define BHT_OK (0)
|
||||
|
||||
#define BHT_NO_WAIT 0x00000000
|
||||
#define BHT_WAIT_FOREVER 0xFFFFFFFF
|
||||
|
||||
#define BH_KB (1024)
|
||||
#define BH_MB ((BH_KB)*1024)
|
||||
#define BH_GB ((BH_MB)*1024)
|
||||
|
||||
#ifndef BH_MALLOC
|
||||
#define BH_MALLOC os_malloc
|
||||
#endif
|
||||
|
||||
#ifndef BH_FREE
|
||||
#define BH_FREE os_free
|
||||
#endif
|
||||
|
||||
void *BH_MALLOC(unsigned int size);
|
||||
void BH_FREE(void *ptr);
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL (void*)0
|
||||
#endif
|
||||
|
||||
#ifndef __cplusplus
|
||||
#define true 1
|
||||
#define false 0
|
||||
#define inline __inline
|
||||
#endif
|
||||
|
||||
/* Return the offset of the given field in the given type */
|
||||
#ifndef offsetof
|
||||
#define offsetof(Type, field) ((size_t)(&((Type *)0)->field))
|
||||
#endif
|
||||
|
||||
typedef uint8_t uint8;
|
||||
typedef int8_t int8;
|
||||
typedef uint16_t uint16;
|
||||
typedef int16_t int16;
|
||||
typedef uint32_t uint32;
|
||||
typedef int32_t int32;
|
||||
typedef float float32;
|
||||
typedef double float64;
|
||||
typedef uint64_t uint64;
|
||||
typedef int64_t int64;
|
||||
|
||||
typedef void* (*thread_start_routine_t)(void*);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* #ifndef _PLATFORM_COMMON_H */
|
||||
Reference in New Issue
Block a user