Implement post-MVP features and native stack overflow check (#243)

Implement native thread stack overflow check
Implement post-MVP: Non-trapping float-to-int conversions
Implement post-MVP: Sign-extension operators
Enhance WASM loader checks
This commit is contained in:
wenyongh
2020-04-30 17:52:11 +08:00
committed by GitHub
parent ab4f0c5419
commit d381b0fdec
36 changed files with 1246 additions and 232 deletions

View File

@ -339,3 +339,9 @@ os_cond_signal(korp_cond *cond)
return BHT_OK;
}
uint8 *os_thread_get_stack_boundary()
{
/* TODO: get alios stack boundary */
return NULL;
}

View File

@ -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 (32 * 1024 + _STACK_SIZE_ADJUSTMENT)
/* Default thread priority */
#define BH_THREAD_DEFAULT_PRIORITY 0

View File

@ -3,6 +3,9 @@
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include "platform_api_vmcore.h"
#include "platform_api_extension.h"
@ -218,3 +221,20 @@ int os_thread_join(korp_tid thread, void **value_ptr)
return pthread_join(thread, value_ptr);
}
uint8 *os_thread_get_stack_boundary()
{
pthread_attr_t attr;
void *addr = NULL;
size_t size;
if (pthread_getattr_np(pthread_self(), &attr) == 0) {
pthread_attr_getstack(&attr, &addr, &size);
pthread_attr_destroy (&attr);
}
if (addr)
return (uint8*)addr + _STACK_SIZE_ADJUSTMENT;
else
return NULL;
}

View File

@ -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 (32 * 1024 + _STACK_SIZE_ADJUSTMENT)
/* Default thread priority */
#define BH_THREAD_DEFAULT_PRIORITY 0

View File

@ -65,6 +65,13 @@ uint64 os_time_get_boot_microsecond(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);
/**
************** mutext APIs ***********
* vmcore: Not required until pthread is supported by runtime

View File

@ -47,3 +47,9 @@ int os_cond_destroy(korp_cond *cond)
return BHT_OK;
}
uint8 *os_thread_get_stack_boundary()
{
/* TODO: get sgx stack boundary */
return NULL;
}

View File

@ -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 (32 * 1024 + _STACK_SIZE_ADJUSTMENT)
/* Default thread priority */
#define BH_THREAD_DEFAULT_PRIORITY 0

View File

@ -39,7 +39,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 (32 * 1024 + _STACK_SIZE_ADJUSTMENT)
/* Default thread priority */
#define BH_THREAD_DEFAULT_PRIORITY 0

View File

@ -444,3 +444,13 @@ int os_cond_signal(korp_cond *cond)
return BHT_OK;
}
uint8 *os_thread_get_stack_boundary()
{
#if defined(CONFIG_THREAD_STACK_INFO)
korp_tid thread = k_current_get();
return (uint8*)thread->stack_info.start;
#else
return NULL;
#endif
}