Skip to content

LocalIo is unsafe and should not be. #11053

Closed
@alexcrichton

Description

@alexcrichton

The current implementation of LocalIo involves unsafe borrowing which doesn't transfer ownership of the IoFactory. This unsafe code allows for mutably aliasing the IoFactory multiple times on the stack (leading to memory unsafety).

Fixing this would involve dancing around transferring ownership of the IoFactory between the calls that it makes. My initial idea was for LocalIo to take ownership and give out &mut loans to it, but this is insufficient because when a green task context switches the scheduler must again have ownership of the IoFactory.

My best idea for doing this right now is to change all methods on IoFactory to take ~self and then right before the M:N methods block they would transfer ownership back to the scheduler. All the 1:1 methods would basically immediately return ownership of the factory back to the local Task.

Metadata

Metadata

Assignees

Labels

A-runtimeArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions