[lkml]   [2022]   [Mar]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [RFC PATCH v1 5/6] tools/nolibc/stdlib: Implement `malloc()`, `calloc()`, `realloc()` and `free()`

a few points below:

On Sun, Mar 20, 2022 at 04:37:49PM +0700, Ammar Faizi wrote:
> +struct nolibc_heap {
> + size_t len;
> + char user_p[] __attribute__((__aligned__));
> +};

Note that many programs assume that malloc() returns a field aligned
to 2*sizeof(pointer) and unless I'm mistaken, above the user pointer
will only be aligned by one pointer. This may have an impact when the
compiler decides to use SIMD instructions.

> +#ifndef offsetof
> +#define offsetof(TYPE, FIELD) ((size_t) &((TYPE *)0)->FIELD)
> +#endif
> +
> +#ifndef container_of
> +#define container_of(PTR, TYPE, FIELD) ({ \
> + __typeof__(((TYPE *)0)->FIELD) *__FIELD_PTR = (PTR); \
> + (TYPE *)((char *) __FIELD_PTR - offsetof(TYPE, FIELD)); \
> +})
> +#endif

These ones are independent on the malloc code and should move to a
different patch and likely to a different file. I'm seeing we already
have a few macros in types.h and since it's shared by almost everything
it might be more suitable there.


 \ /
  Last update: 2022-03-20 17:17    [W:0.224 / U:0.744 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site