Opened 3 years ago

Last modified 22 months ago

#23882 new enhancement

Investigate implementing a Rust allocator wrapping tor_malloc

Reported by: isis Owned by:
Priority: High Milestone: Tor: unspecified
Component: Core Tor/Tor Version: Tor:
Severity: Normal Keywords: rust, rust-pilot, 034-triage-20180328, 034-removed-20180328, 041-proposed
Cc: chelseakomlo Actual Points:
Parent ID: Points: 3
Reviewer: Sponsor:


We should look into implementing the Rust alloc::allocator::Alloc trait as a wrapper around tor_malloc as a way to have a cleaner allocator interface in Rust moving forward (which still works with our current legacy C code).

This is what the Rust code in Firefox has done, and the alloc crate is supposed to stabilised "soon" (as in, within the next six months) because FF is using it.

Child Tickets

#27208enhancementclosedadd API for allocating aligned memory

Change History (14)

comment:1 Changed 3 years ago by

The tracking issue for stabilization is at . FF isn't using it, but I would like it to.

I'll be trying to get stabilization to happen soon.

comment:2 Changed 3 years ago by chelseakomlo

Cc: chelseakomlo added

comment:3 Changed 3 years ago by nickm

Milestone: Tor: 0.3.3.x-finalTor: 0.3.4.x-final

comment:4 Changed 3 years ago by isis

The tracking issue for stabilisation of the std::heap::Alloc trait is here, which is probably also important since the global allocator feature that Manish linked to requires that we impl<'a> Alloc for &'a TorAlloc.

comment:5 Changed 3 years ago by nickm

Keywords: 034-triage-20180328 added

comment:6 Changed 3 years ago by nickm

Keywords: 034-removed-20180328 added

Per our triage process, these tickets are pending removal from 0.3.4.

comment:7 Changed 3 years ago by nickm

Milestone: Tor: 0.3.4.x-finalTor: unspecified

These tickets, tagged with 034-removed-*, are no longer in-scope for 0.3.4. We can reconsider any of them, if time permits.

comment:9 in reply to:  8 Changed 2 years ago by chelseakomlo

Replying to cypherpunks3:

GlobalAlloc is now stable.

Excellent, this is great news. Thanks for updating this ticket.

comment:10 Changed 2 years ago by nickm

Milestone: Tor: unspecifiedTor: 0.3.6.x-final

comment:11 Changed 2 years ago by cypherpunks3

Implementing GlobalAlloc::alloc requires respecting the alignment in the Layout that's passed to it, and right now there isn't an API for allocating aligned memory.

So first gotta add something like tor_aligned_alloc that uses aligned_alloc (C11), _aligned_malloc (Windows), or posix_memalign or memalign. And you'd have to make the original tor_malloc forward to the new function, too, it can't keep calling malloc.

At least it seemingly can't on Windows, because pointers returned by _aligned_malloc have to be freed with _aligned_free. The docs say Using free is illegal. And there'd be no way to distinguish which pointers were allocated by which.

comment:12 Changed 2 years ago by nickm

Milestone: Tor: 0.3.6.x-finalTor: 0.4.0.x-final

Tor 0.3.6.x has been renamed to 0.4.0.x.

comment:13 Changed 22 months ago by gaba

Sponsor: Sponsor8-can

comment:14 Changed 22 months ago by nickm

Keywords: 041-proposed added
Milestone: Tor: 0.4.0.x-finalTor: unspecified

Mark some 0.4.0.x tickets as proposed for 0.4.1.x

Note: See TracTickets for help on using tickets.