Re-org memory allocation interfaces, add --stack-size and --heap-size option (#193)

This commit is contained in:
wenyongh
2020-03-10 19:54:44 +08:00
committed by GitHub
parent 381859d530
commit 0fdd49ea31
110 changed files with 1264 additions and 2125 deletions

View File

@ -18,6 +18,24 @@ bh_platform_init()
return 0;
}
void *
os_malloc(unsigned size)
{
return malloc(size);
}
void *
os_realloc(void *ptr, unsigned size)
{
return realloc(ptr, size);
}
void
os_free(void *ptr)
{
free(ptr);
}
char*
bh_read_file_to_buffer(const char *filename, uint32 *ret_size)
{
@ -46,7 +64,7 @@ bh_read_file_to_buffer(const char *filename, uint32 *ret_size)
file_size = (uint32)stat_buf.st_size;
if (!(buffer = bh_malloc(file_size))) {
if (!(buffer = BH_MALLOC(file_size))) {
printf("Read file to buffer failed: alloc memory failed.\n");
close(file);
return NULL;
@ -57,7 +75,7 @@ bh_read_file_to_buffer(const char *filename, uint32 *ret_size)
if (read_size < file_size) {
printf("Read file to buffer failed: read file content failed.\n");
bh_free(buffer);
BH_FREE(buffer);
return NULL;
}

View File

@ -8,7 +8,6 @@
#include "bh_config.h"
#include "bh_types.h"
#include "bh_memory.h"
#include <inttypes.h>
#include <stdbool.h>
#include <assert.h>
@ -36,16 +35,10 @@ extern "C" {
typedef uint64_t uint64;
typedef int64_t int64;
extern void DEBUGME(void);
#define DIE do{bh_debug("Die here\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); DEBUGME(void); while(1);}while(0)
#ifndef BH_PLATFORM_ANDROID
#define BH_PLATFORM_ANDROID
#endif
/* NEED qsort */
#define _STACK_SIZE_ADJUSTMENT (32 * 1024)
/* Stack size of applet threads's native part. */
@ -67,13 +60,12 @@ typedef pthread_cond_t korp_cond;
typedef pthread_t korp_thread;
typedef void* (*thread_start_routine_t)(void*);
#define wa_malloc bh_malloc
#define wa_free bh_free
#define wa_strdup bh_strdup
void *os_malloc(unsigned size);
void *os_realloc(void *ptr, unsigned size);
void os_free(void *ptr);
#define bh_printf(...) (__android_log_print(ANDROID_LOG_INFO, "wasm_runtime::", __VA_ARGS__))
int snprintf(char *buffer, size_t count, const char *format, ...);
double fmod(double x, double y);
float fmodf(float x, float y);
@ -99,15 +91,8 @@ double sqrt(double x);
#define bh_assert assert
int b_memcpy_s(void * s1, unsigned int s1max, const void * s2,
unsigned int n);
int b_strcat_s(char * s1, size_t s1max, const char * s2);
int b_strcpy_s(char * s1, size_t s1max, const char * s2);
char *bh_read_file_to_buffer(const char *filename, uint32 *ret_size);
char *bh_strdup(const char *s);
int bh_platform_init();
/* MMAP mode */

View File

@ -6,7 +6,6 @@
#include "bh_thread.h"
#include "bh_assert.h"
#include "bh_log.h"
#include "bh_memory.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
@ -67,7 +66,7 @@ static void *vm_thread_wrapper(void *arg)
targ->stack = (void *)((uintptr_t)(&arg) & (uintptr_t)~0xfff);
_vm_tls_put(1, targ);
targ->start(targ->arg);
bh_free(targ);
BH_FREE(targ);
_vm_tls_put(1, NULL);
return NULL;
}
@ -94,7 +93,7 @@ int _vm_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;
@ -106,7 +105,7 @@ int _vm_thread_create_with_prio(korp_tid *tid, thread_start_routine_t start,
if (pthread_create(tid, &tattr, vm_thread_wrapper, targ) != 0) {
pthread_attr_destroy(&tattr);
bh_free(targ);
BH_FREE(targ);
return BHT_ERROR;
}
@ -128,7 +127,7 @@ korp_tid _vm_self_thread()
void vm_thread_exit(void * code)
{
bh_free(_vm_tls_get(1));
BH_FREE(_vm_tls_get(1));
_vm_tls_put(1, NULL);
pthread_exit(code);
}