[riot-commits] [RIOT-OS/RIOT] ad4d88: pkg/tlsf: fix double pointer.

benpicco noreply at github.com
Tue Sep 17 23:12:38 CEST 2019


  Branch: refs/heads/master
  Home:   https://github.com/RIOT-OS/RIOT
  Commit: ad4d883c4fceb29281c5e8bdf25fe3679449f0f2
      https://github.com/RIOT-OS/RIOT/commit/ad4d883c4fceb29281c5e8bdf25fe3679449f0f2
  Author: Juan Carrano <j.carrano at fu-berlin.de>
  Date:   2019-08-16 (Fri, 16 Aug 2019)

  Changed paths:
    M pkg/tlsf/contrib/include/tlsf-malloc.h
    M pkg/tlsf/contrib/tlsf-malloc.c

  Log Message:
  -----------
  pkg/tlsf: fix double pointer.

A (void*) function was declared as (void**) because one of the void pointers
was hidden behind a typedef. Because of the way a void* works, this has no
consequences, but it is confusing.


  Commit: cc907fa54eb62dbfce7f0a1c0a43cbd3cbb83dbd
      https://github.com/RIOT-OS/RIOT/commit/cc907fa54eb62dbfce7f0a1c0a43cbd3cbb83dbd
  Author: Juan Carrano <j.carrano at fu-berlin.de>
  Date:   2019-09-17 (Tue, 17 Sep 2019)

  Changed paths:
    A pkg/tlsf/Makefile.dep
    M pkg/tlsf/Makefile.include
    M pkg/tlsf/contrib/Makefile
    M pkg/tlsf/contrib/include/tlsf-malloc.h
    A pkg/tlsf/contrib/native.c
    A pkg/tlsf/contrib/newlib.c
    A pkg/tlsf/contrib/tlsf-malloc-internal.h
    M pkg/tlsf/contrib/tlsf-malloc.c

  Log Message:
  -----------
  pkg/tlsf: Fix the way system functions are overriden.

The correct way to overrride the malloc family of functions in newlib-nano is
to provide the *_r (reentrant) variants. Newlib implements the "normal"
functions on top of these (see the newlib source code). Also, internally it calls
the *_r functions when allocating buffers.

If only the "normal" non-reentrant functions are provided this will mean that
some of the code will still use the vanilla newlib allocator. Furthermore, if
one uses the whole heap as a pool for TLSF then the system may in the best case
crash as there is no enough memory for its internall allocations or in the worst
case function eratically (this depends on how the heap reserved, there is an
upcomming series of commits in that direction).

This commit splits the handling between newlib and native. It also prepares the
ground for future work on the pool initialization.

Right now I could only test this in ARM and native and I cannot ensure it will
work on other platforms. Replacing the system's memory allocator is not something
that can be taken lightly and will inevitably require diving into the depths of
the libc. Therefore I would say that using TLSF as a system wide allocator is ATM
supported officially only on those plaftorms.

Testing:

Aside from reading the newlib sources, you can see the issue in a live system
using the debugger.

Compile any example (with or without tlsf-malloc), grab a debugger and place
a breakpoint in sbrk and _sbrk_r. Doing a backtrace will reveal it gets called
by _malloc_r.


  Commit: f02095102fbb8bcc647a7d1e033184284594abdc
      https://github.com/RIOT-OS/RIOT/commit/f02095102fbb8bcc647a7d1e033184284594abdc
  Author: benpicco <benpicco at googlemail.com>
  Date:   2019-09-17 (Tue, 17 Sep 2019)

  Changed paths:
    A pkg/tlsf/Makefile.dep
    M pkg/tlsf/Makefile.include
    M pkg/tlsf/contrib/Makefile
    M pkg/tlsf/contrib/include/tlsf-malloc.h
    A pkg/tlsf/contrib/native.c
    A pkg/tlsf/contrib/newlib.c
    A pkg/tlsf/contrib/tlsf-malloc-internal.h
    M pkg/tlsf/contrib/tlsf-malloc.c

  Log Message:
  -----------
  Merge pull request #12031 from jcarrano/tlsf-malloc-fix-override

 pkg/tlsf: Fix the way system functions are overriden.


Compare: https://github.com/RIOT-OS/RIOT/compare/d5c272ed869c...f02095102fbb


More information about the commits mailing list