-
Notifications
You must be signed in to change notification settings - Fork 647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add porting codes of rt-thread. #494
Conversation
…t-thread, document was modified passingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for submitting the patch!
@@ -0,0 +1,27 @@ | |||
# for module compiling |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should add license header for all files, for the new file, you might claim the copyright to yourself and set license to "Apache-2.0 WITH LLVM-exception", please ref to other file submitted by community developer, e.g. nuttx_platform.c.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have add license header to files I added, please check it.
#include <stdint.h> | ||
#include <ctype.h> | ||
|
||
#ifndef BUILD_TARGET |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure whether we should define BUILD_TARGET here, normally we define BUILD_TARGET_XXX in build-scripts/config_common.cmake by parsing the WAMR_BUILD_TARGET=XXX passed by cmake variable (cmake -DWAMR_BUILD_TARGET=XXX).
And had better define the BH_PLATFORM_XXX macro in this file, so other files can use the macro, e.g. wasm_native.c:
#ifndef BUILD_PLATFORM_RT_THREAD
#define BUILD_PLATFORM_RT_THREAD
#endif
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, this definiation was used in the past version and I forgot to delete it, I just remove it from rt-thread/platform_internal.h
.
void *os_malloc(unsigned size) | ||
{ | ||
void* buf = rt_malloc(size + 8); | ||
if (((rt_ubase_t)buf)&7) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why here it doesn't check buf != NULL, but check (buf & 7), could buf's lowest 3 bits be zero, and higher bits be not zero? e.g. 0x11110, or 0x11118.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wamr need heap init struct be aligned to 8-bytes, otherwise iwasm will print error information: [GC_ERROR]heap init struct buf not 8-byte aligned
. these codes are used to make sure the memories allocated are all align to 8-byte.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, thanks a lot! And should we also check the input pointer ptr like os_free in os_realloc? The ptr might be not the original buffer returned by rt_malloc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is a list to save the map from fixed-address to origin-address named mem_list
. if the address of memory allocated is not align to 8-byte, this address and fixed-address will be save into this list. while os_free
be called, will also check this list to find the original address of the pointer pass in.
as for os_realloc
, I have not done anything yet, I will resolve it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, it seems that the performance might be not so good if saving the map to mem_list, e.g. in os_free, we need to traverse the list. And also for multi-thread, normally we should to add lock for the list. How about allocating memory with extra 16 bytes, saving the original address to the next 8-byte aligned address, and return the next next 8-byte aligned address? e.g.:
void *os_malloc(unsigned size)
{
uint8 *buf = rt_malloc(size + 16);
uint8 *buf_aligned;
if (buf) {
buf_aligned = (uint8 *)(((uintptr_t)buf + 7) & ~(uintptr_t)7);
*(uint8 **)buf_aligned = buf;
buf = buf_aligned + 8;
}
return buf;
}
void os_free(void *ptr)
{
uint8 *buf_aligned;
if (ptr) {
buf_aligned = (uint8 *)ptr - 8;
buf = *(uint8 **)buf_aligned;
rt_free(buf);
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thinks for your reply and advice, It seems be a good idea, I will try this today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have rewrite these three method, please check.
…o 8-byte, remove the map list of memories address.
…al.h of rt-thread.
add porting codes and scons building scripts that are used by rt-thread, document was modified passingly.