From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by gnuweeb.org (Postfix) with ESMTP id 855187E2DA for ; Sun, 20 Mar 2022 16:16:53 +0000 (UTC) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 22KGGiDY026852; Sun, 20 Mar 2022 17:16:44 +0100 Date: Sun, 20 Mar 2022 17:16:44 +0100 From: Willy Tarreau To: Ammar Faizi Cc: "Paul E. McKenney" , Alviro Iskandar Setiawan , Nugraha , Linux Kernel Mailing List , GNU/Weeb Mailing List Subject: Re: [RFC PATCH v1 5/6] tools/nolibc/stdlib: Implement `malloc()`, `calloc()`, `realloc()` and `free()` Message-ID: <20220320161644.GF8067@1wt.eu> References: <20220320093750.159991-1-ammarfaizi2@gnuweeb.org> <20220320093750.159991-6-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220320093750.159991-6-ammarfaizi2@gnuweeb.org> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: Ammar, 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. Thanks! Willy