#define MORECORE to orca_mem_grow. Removed builtin memory routine that don't seem to be supported by wasm3 (TODO: investigate that later)

This commit is contained in:
Martin Fouilleul 2023-06-25 15:34:03 +02:00
parent bcf84e0b80
commit 98a67cef72
3 changed files with 335 additions and 305 deletions

View File

@ -9,12 +9,12 @@ DEBUG_FLAGS="-g -DDEBUG -DLOG_COMPILE_DEBUG"
# set target # set target
#-------------------------------------------------------------- #--------------------------------------------------------------
target="$1" target="${1:-}"
if [ -z $target ] ; then if [ -z $target ] ; then
target='lib' target='lib'
fi fi
shaderFlagParam="$2" shaderFlagParam="${2:-}"
#-------------------------------------------------------------- #--------------------------------------------------------------
# Detect OS and set environment variables accordingly # Detect OS and set environment variables accordingly
#-------------------------------------------------------------- #--------------------------------------------------------------

View File

@ -6,11 +6,8 @@
#define LACKS_UNISTD_H #define LACKS_UNISTD_H
#define LACKS_SYS_PARAM_H #define LACKS_SYS_PARAM_H
void* nomorecore(size_t size) { extern void* orca_mem_grow(u64 size);
abort(); #define MORECORE orca_mem_grow
}
#define MORECORE nomorecore
/* /*
This is a version (aka dlmalloc) of malloc/free/realloc written by This is a version (aka dlmalloc) of malloc/free/realloc written by

View File

@ -7,7 +7,6 @@
*****************************************************************/ *****************************************************************/
#include"platform_memory.h" #include"platform_memory.h"
#include <stdlib.h>
void* ORCA_IMPORT(orca_mem_grow)(u64 size); void* ORCA_IMPORT(orca_mem_grow)(u64 size);
@ -31,24 +30,58 @@ mem_base_allocator* mem_base_allocator_default()
return(&base); return(&base);
} }
// malloc, free, realloc, etc. are defined in orca_malloc.c
//TODO: implement malloc/realloc/free/memset/etc here...
void* memset(void* b, int c, size_t n) void* memset(void* b, int c, size_t n)
{ {
return __builtin_memset(b, c, n); for(size_t i = 0; i<n; i++)
{
((char*)b)[i] = (u8)c;
}
return(b);
} }
void* memcpy(void *restrict dst, const void *restrict src, size_t n) void* memcpy(void *restrict dst, const void *restrict src, size_t n)
{ {
return __builtin_memcpy(dst, src, n); for(size_t i = 0; i<n; i++)
{
((char*)dst)[i] = ((char*)src)[i];
}
return(dst);
} }
void* memmove(void *dst, const void *src, size_t n) void* memmove(void *dst, const void *src, size_t n)
{ {
return __builtin_memmove(dst, src, n); if(src < dst)
{
for(size_t i = n-1; i>=0; i--)
{
((char*)dst)[i] = ((char*)src)[i];
}
}
else if(src > dst)
{
for(size_t i = 0; i<n; i++)
{
((char*)dst)[i] = ((char*)src)[i];
}
}
return(dst);
} }
int memcmp(const void *s1, const void *s2, size_t n) int memcmp(const void *s1, const void *s2, size_t n)
{ {
return __builtin_memcmp(s1, s2, n); const unsigned char* c1 = (const unsigned char*)s1;
const unsigned char* c2 = (const unsigned char*)s2;
for(size_t i = 0; i<n; i++)
{
if(c1[i] != c2[i])
{
return(c1 - c2);
}
}
return(0);
} }