Fix os_cond_timedwait and other issues for NuttX sim/macOS (#562)

This commit is contained in:
YAMAMOTO Takashi 2021-05-31 10:56:47 +09:00 committed by GitHub
parent 631838cfd9
commit 15dd651539
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 8 deletions

View File

@ -3618,7 +3618,7 @@ wasm_loader_find_block_addr(BlockAddr *block_addr_cache,
uint32 block_nested_depth = 1, count, i, j, t; uint32 block_nested_depth = 1, count, i, j, t;
uint32 error_buf_size = sizeof(error_buf); uint32 error_buf_size = sizeof(error_buf);
uint8 opcode, u8; uint8 opcode, u8;
BlockAddr block_stack[16] = { 0 }, *block; BlockAddr block_stack[16] = {{0}}, *block;
i = ((uintptr_t)start_addr) & (uintptr_t)(BLOCK_ADDR_CACHE_SIZE - 1); i = ((uintptr_t)start_addr) & (uintptr_t)(BLOCK_ADDR_CACHE_SIZE - 1);
block = block_addr_cache + BLOCK_ADDR_CONFLICT_SIZE * i; block = block_addr_cache + BLOCK_ADDR_CONFLICT_SIZE * i;

View File

@ -92,7 +92,7 @@ gc_init_with_struct_and_pool(char *struct_buf, gc_size_t struct_buf_size,
} }
if (struct_buf_size < sizeof(gc_handle_t)) { if (struct_buf_size < sizeof(gc_handle_t)) {
os_printf("[GC_ERROR]heap init struct buf size (%u) < %u\n", os_printf("[GC_ERROR]heap init struct buf size (%u) < %zu\n",
struct_buf_size, sizeof(gc_handle_t)); struct_buf_size, sizeof(gc_handle_t));
return NULL; return NULL;
} }

View File

@ -31,7 +31,7 @@ static void *os_thread_wrapper(void *arg)
os_signal_handler handler = targ->signal_handler; os_signal_handler handler = targ->signal_handler;
#endif #endif
os_printf("THREAD CREATED %p\n", pthread_self()); os_printf("THREAD CREATED %jx\n", (uintmax_t)(uintptr_t)pthread_self());
BH_FREE(targ); BH_FREE(targ);
#ifdef OS_ENABLE_HW_BOUND_CHECK #ifdef OS_ENABLE_HW_BOUND_CHECK
if (os_thread_signal_init(handler) != 0) if (os_thread_signal_init(handler) != 0)
@ -184,17 +184,18 @@ int os_cond_wait(korp_cond *cond, korp_mutex *mutex)
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; struct timeval tv;
long int tv_sec_new, tv_nsec_new; time_t tv_sec_new;
long int tv_nsec_new;
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
tv_sec_new = (long int)(tv.tv_sec + usec / 1000000); tv_sec_new = (time_t)(tv.tv_sec + usec / 1000000);
if (tv_sec_new >= tv.tv_sec) { if (tv_sec_new >= tv.tv_sec) {
ts->tv_sec = tv_sec_new; ts->tv_sec = tv_sec_new;
} }
else { else {
/* integer overflow */ /* integer overflow */
ts->tv_sec = LONG_MAX; ts->tv_sec = BH_TIME_T_MAX;
os_printf("Warning: os_cond_reltimedwait exceeds limit, " os_printf("Warning: os_cond_reltimedwait exceeds limit, "
"set to max timeout instead\n"); "set to max timeout instead\n");
} }
@ -211,7 +212,7 @@ static void msec_nsec_to_abstime(struct timespec *ts, uint64 usec)
"set to max timeout instead\n"); "set to max timeout instead\n");
} }
if (ts->tv_nsec >= 1000000000L && ts->tv_sec < LONG_MAX) { if (ts->tv_nsec >= 1000000000L && ts->tv_sec < BH_TIME_T_MAX) {
ts->tv_sec++; ts->tv_sec++;
ts->tv_nsec -= 1000000000L; ts->tv_nsec -= 1000000000L;
} }
@ -263,7 +264,9 @@ void os_thread_exit(void *retval)
return pthread_exit(retval); return pthread_exit(retval);
} }
#if defined(os_thread_local_attribute)
static os_thread_local_attribute uint8 *thread_stack_boundary = NULL; static os_thread_local_attribute uint8 *thread_stack_boundary = NULL;
#endif
uint8 *os_thread_get_stack_boundary() uint8 *os_thread_get_stack_boundary()
{ {
@ -276,8 +279,10 @@ uint8 *os_thread_get_stack_boundary()
size_t stack_size, max_stack_size; size_t stack_size, max_stack_size;
int page_size; int page_size;
#if defined(os_thread_local_attribute)
if (thread_stack_boundary) if (thread_stack_boundary)
return thread_stack_boundary; return thread_stack_boundary;
#endif
page_size = getpagesize(); page_size = getpagesize();
self = pthread_self(); self = pthread_self();
@ -312,7 +317,9 @@ uint8 *os_thread_get_stack_boundary()
} }
#endif #endif
#if defined(os_thread_local_attribute)
thread_stack_boundary = addr; thread_stack_boundary = addr;
#endif
return addr; return addr;
} }

View File

@ -33,6 +33,10 @@ extern "C" {
#define BH_FREE os_free #define BH_FREE os_free
#endif #endif
#ifndef BH_TIME_T_MAX
#define BH_TIME_T_MAX LONG_MAX
#endif
#if defined(_MSC_BUILD) #if defined(_MSC_BUILD)
#if defined(COMPILING_WASM_RUNTIME_API) #if defined(COMPILING_WASM_RUNTIME_API)
__declspec(dllexport) void *BH_MALLOC(unsigned int size); __declspec(dllexport) void *BH_MALLOC(unsigned int size);

View File

@ -40,6 +40,9 @@ typedef pthread_t korp_thread;
#define os_printf printf #define os_printf printf
#define os_vprintf vprintf #define os_vprintf vprintf
/* On NuttX, time_t is uint32_t */
#define BH_TIME_T_MAX 0xffffffff
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -23,7 +23,7 @@ WAMR_BUILD_TARGET := X86_64
endif endif
ifeq ($(CONFIG_HOST_MACOS),y) ifeq ($(CONFIG_HOST_MACOS),y)
# Note: invokeNative_em64.s needs BH_PLATFORM_DARWIN # Note: invokeNative_em64.s needs BH_PLATFORM_DARWIN
CFLAGS += -DBH_PLATFORM_DARWIN AFLAGS += -DBH_PLATFORM_DARWIN
endif endif
endif endif