On Sun, Sep 15, 2024 at 08:22:42PM +0100, Gary Guo wrote: > On Sun, 15 Sep 2024 19:02:40 +0200 > Danilo Krummrich <dakr@xxxxxxxxxx> wrote: > > There is also 4. > > > > Let `alloc` and `realloc` return a properly aligned dangling pointer for > > `size == 0` and don't accept dangling pointers in `realloc` and `free`. > > I'll consider the API design to be bad if I can't pass allocated pointer to > free. If caller needs to handle ZST specially then we might as well > just ban it completely. Fine for me -- I don't see a need to support ZSTs with `Allocator`. I think its main purpose is to give us an interface to actually allocate memory. We probably don't need it to be a "dangling pointer generator". > > > And 5. > > > > Reject the combination of `None` and `size == 0` entirely, as earlier proposed > > by Benno. > > > > I'm fine with both, 4. and 5. with a slight preference for 4. > > > > I'd also go along with 1., as a mix of 4. and 5. > > > > I really don't like making `alloc` unsafe, and I really don't want to have > > `old_layout` in `free`. Please let's not discuss this again. :-) > > I don't buy it. > > Your argument for having `old_layout` is so that the caller doesn't > need to care about the size. But as demonstrated the caller *does* need > to care about whether the size is zero. > > Our previous discussion doesn't cover the particular case of ZST and > you said that it reason arise that we need this extra parameter, then > it could be added. It feels to me that sane behaviour when it comes > to ZST allocation is a very good reason. I don't see why we should "optimize" the API for creating dangling pointers and be able to pass them to `free` (which does not serve any practical purpose). I don't want to add arguments that are meaningless for the actual backing allocators (such as Kmalloc, Vmalloc, etc.), only to be able to generate and "free" pointers for ZSTs with arbitrary alignment. Do we even have use cases for ZSTs with other alignments? > > > > > > > > > Best, > > > Gary > > > > > > > > > > > Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx> > > > > Signed-off-by: Danilo Krummrich <dakr@xxxxxxxxxx> > > > > --- > > > > rust/kernel/alloc.rs | 112 +++++++++++++++++++++++++++++++++++++++++++ > > > > 1 file changed, 112 insertions(+) >