Re-org memory allocation interfaces, add --stack-size and --heap-size option (#193)
This commit is contained in:
@ -4,7 +4,6 @@
|
||||
*/
|
||||
|
||||
#include "bh_platform.h"
|
||||
#include "bh_memory.h"
|
||||
#include "bh_common.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -15,16 +14,33 @@ bh_platform_init()
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *
|
||||
os_malloc(unsigned size)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *
|
||||
os_realloc(void *ptr, unsigned size)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
os_free(void *ptr)
|
||||
{
|
||||
}
|
||||
|
||||
void *
|
||||
bh_mmap(void *hint, unsigned int size, int prot, int flags)
|
||||
{
|
||||
return bh_malloc(size);
|
||||
return BH_MALLOC(size);
|
||||
}
|
||||
|
||||
void
|
||||
bh_munmap(void *addr, uint32 size)
|
||||
{
|
||||
return bh_free(addr);
|
||||
return BH_FREE(addr);
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
@ -8,7 +8,6 @@
|
||||
|
||||
#include "bh_config.h"
|
||||
#include "bh_types.h"
|
||||
#include "bh_memory.h"
|
||||
#include <aos/kernel.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
@ -39,10 +38,6 @@
|
||||
typedef uint64_t uint64;
|
||||
typedef int64_t int64;
|
||||
|
||||
#define wa_malloc bh_malloc
|
||||
#define wa_free bh_free
|
||||
#define wa_strdup bh_strdup
|
||||
|
||||
typedef aos_task_t korp_thread;
|
||||
typedef korp_thread *korp_tid;
|
||||
typedef aos_task_t *aos_tid_t;
|
||||
@ -58,6 +53,10 @@ typedef struct korp_cond {
|
||||
|
||||
typedef void* (*thread_start_routine_t)(void*);
|
||||
|
||||
void *os_malloc(unsigned size);
|
||||
void *os_realloc(void *ptr, unsigned size);
|
||||
void os_free(void *ptr);
|
||||
|
||||
/* Unit test framework is based on C++, where the declaration of
|
||||
snprintf is different. */
|
||||
#ifndef __cplusplus
|
||||
@ -85,10 +84,6 @@ int snprintf(char *buffer, size_t count, const char *format, ...);
|
||||
extern 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)
|
||||
|
||||
extern int b_memcpy_s(void * s1, unsigned int s1max, const void * s2, unsigned int n);
|
||||
extern int b_strcat_s(char * s1, size_t s1max, const char * s2);
|
||||
extern int b_strcpy_s(char * s1, size_t s1max, const char * s2);
|
||||
|
||||
/* math functions */
|
||||
double sqrt(double x);
|
||||
double floor(double x);
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -102,7 +101,7 @@ vm_thread_cleanup(void)
|
||||
wait_node_sem = &thread_data->wait_node.sem;
|
||||
|
||||
/* Free thread data firstly */
|
||||
bh_free(thread_data);
|
||||
BH_FREE(thread_data);
|
||||
|
||||
aos_mutex_lock(wait_list_lock, AOS_WAIT_FOREVER);
|
||||
if (thread_wait_list) {
|
||||
@ -152,7 +151,7 @@ _vm_thread_create_with_prio(korp_tid *p_tid, thread_start_routine_t start,
|
||||
return BHT_ERROR;
|
||||
|
||||
/* Create and initialize thread data */
|
||||
if (!(thread_data = bh_malloc(sizeof(bh_thread_data))))
|
||||
if (!(thread_data = BH_MALLOC(sizeof(bh_thread_data))))
|
||||
return BHT_ERROR;
|
||||
|
||||
memset(thread_data, 0, sizeof(bh_thread_data));
|
||||
@ -184,7 +183,7 @@ fail3:
|
||||
fail2:
|
||||
aos_sem_free(&thread_data->wait_node.sem);
|
||||
fail1:
|
||||
bh_free(thread_data);
|
||||
BH_FREE(thread_data);
|
||||
return BHT_ERROR;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user