0

Let me verify if the following code does everything before calling a malloc() of stdlib (optlib).

————-
#include <stdlib.h>

/* initialization, allocation of heap memory in .bss */
#define HEAP_SIZE 2000
static char heap_storage[HEAP_SIZE];

extern char *_heap_of_memory;
extern char *_last_heap_object;
extern char *_top_of_heap;

void init_heap( void ){
_heap_of_memory = heap_storage;
_last_heap_object = heap_storage;
_top_of_heap = heap_storage + sizeof(heap_storage) – 1;
}
—————

Open Source Tools Support 質問が編集されました
質問 は閉じられました。新しい回答は受け付けておりません。
    • Hello,

      Thank you for reaching out to us!

      At this time, we are still looking into the issue you have raised and we do not have a definitive answer available at the moment.

      However, we are doing our best to provide you with accurate feedback as soon as possible.

      Thank you again for your patience and we will be reaching out to you soon!


      Thank you,
      Darius
      The GNU Tools Team

    • Hello,

      Thank you for your patience.

      By default, malloc() will work without any prior setup and thus the heap memory will be allocated after the end of .bss section.

      For example: if the end of .bss is 0x20060a28, calling malloc() will return a pointer to 0x20060a30.

      If you like to overwrite this and take control of where to place the heap, you should instead overwrite the _sbrk()/_sbrk_r() function.

      Also, we have noticed that you have posted another question with the same issue on the forum. If you opened that issue by mistake, would you like us to close it and continue answering in here?

      Thank you again for your patience and please, let us know if we can be of further assistance.

      Best regards,
      Darius
      The GNU Tools Team

    • I may have misunderstandings about malloc behavior.

      So, only need to do is not to place anything between .bss and .stack?

      Is there any documentations or design guides about implementing _sbrk()/_sbrk_r() functions for this library?

    • Hello,

      Yes, there is no need to place anything between .bss and .stack.

      Unfortunately, we do not have any tutorials/documentation for implementing _sbrk()/_sbrk_r() functions.

      However, we can suggest you to take a look at the sbrk man page description (find it here: https://linux.die.net/man/2/sbrk) and the following link: http://stackoverflow.com/questions/22317477/setting-up-heap-in-memory-for-arm-embedded-system.

      Should you have any more questions, please let us know and we will be happy to assist further.

      Best regards,
      Darius
      The GNU Tools Team

    • Thank you for the responses.
      Let me confirm a little more.

      Basically, _sbrk() and _sbrk_r() found in Newlib source code located below do the same thing as optlib, right?
      \arm-none-eabi\arm-none-eabi\bin\newlib\libc\sys\arm\syscalls.c
      \arm-none-eabi\arm-none-eabi\bin\newlib\libc\common\sbrkr.c

    • Hello,

      Thank you for your reply.

      The implementation for the _sbrk() and _sbrk_r() is indeed in these folders.

      Unfortunately, there is currently no implementation in optlib for the _sbrk() or _sbrk_r() functions. To be able to use them, please continue linking the newlib library.

      Should you have any more questions, please let us know and we will be happy to assist further.

      Best regards,
      Darius
      The GNU Tools Team

    • OK, understood.
      Thank you for your support.
      It’s fine to close this quiery.