lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <eaad9eb3-dca9-4943-a58e-06824e8811c2@proton.me>
Date: Mon, 23 Sep 2024 15:20:43 +0000
From: Benno Lossin <benno.lossin@...ton.me>
To: Alice Ryhl <aliceryhl@...gle.com>, Danilo Krummrich <dakr@...nel.org>
Cc: ojeda@...nel.org, alex.gaynor@...il.com, wedsonaf@...il.com, boqun.feng@...il.com, gary@...yguo.net, bjorn3_gh@...tonmail.com, a.hindborg@...sung.com, akpm@...ux-foundation.org, daniel.almeida@...labora.com, faith.ekstrand@...labora.com, boris.brezillon@...labora.com, lina@...hilina.net, mcanal@...lia.com, zhiw@...dia.com, cjia@...dia.com, jhubbard@...dia.com, airlied@...hat.com, ajanulgu@...hat.com, lyude@...hat.com, linux-kernel@...r.kernel.org, rust-for-linux@...r.kernel.org, linux-mm@...ck.org
Subject: Re: [RFC PATCH] rust: alloc: pass `old_layout` to `Allocator`

On 23.09.24 15:56, Alice Ryhl wrote:
> On Sat, Sep 21, 2024 at 5:33 PM Danilo Krummrich <dakr@...nel.org> wrote:
>> @@ -84,11 +92,18 @@ unsafe fn call(
>>          &self,
>>          ptr: Option<NonNull<u8>>,
>>          layout: Layout,
>> +        old_layout: Layout,
>>          flags: Flags,
>>      ) -> Result<NonNull<[u8]>, AllocError> {
>>          let size = aligned_size(layout);
>>          let ptr = match ptr {
>> -            Some(ptr) => ptr.as_ptr(),
>> +            Some(ptr) => {
>> +                if old_layout.size() == 0 {
>> +                    ptr::null()
>> +                } else {
>> +                    ptr.as_ptr()
>> +                }
>> +            }
> 
> This is making Allocator work with zero-sized types, which deviates
> from std. We should not do that without a reason. What is the reason?

The global allocator doesn't support it, but the `Allocator` trait from
std handles zero-sized allocations. For example, this code runs as
expected:

    #![feature(allocator_api)]
    
    use std::alloc::{self, Allocator, Layout};
    
    fn main() {
        let alloc: &dyn Allocator = &alloc::Global;
        let ptr = alloc.allocate(Layout::new::<()>()).unwrap().cast::<u8>();
        unsafe { alloc.deallocate(ptr, Layout::new::<()>()) };
    }

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=0a2d12ee6dabf16f2ebd67cc6faa864e

---
Cheers,
Benno


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ