Skip to content

Safety, races, and interrupts #26

Closed
@jmaargh

Description

@jmaargh

This is related to #15

As I see it, there are two problems with the common idea of using a static mut _: Cell for MMIO. As well documented here one of these is ensuring that access is properly volatile and non-dereferencable. As far as I can see, this crate solves that.

However, there are other problems with static mut _: Cell, even if you're not using it for volatile access (including MMIO). The documentation currently says

Volatile access has no automatic synchronization of its own, and so if your target requires some sort of synchronization for volatile accesses of the address in question you must provide the appropriate synchronization in some way external to this type.

which suggests to me that there are cases where using VolAddress through a global const is sound. But I don't think that's the case. The obvious case is where the target has multiple hardware threads. However, I think that interrupts are another source of data races, even on single-core microcontrollers. It may be the case that the compiler produces access instructions that are atomic in some cases, but this is not guaranteed.

I honestly don't know how this can be solved, so I'm mostly opening this issue as a brainstorm. For non-volatile access, you can use atomics with Ordering::Relaxed, safe in the knowledge that it's zero-overhead for most common architectures. But I don't think it's possible to mark an access as both volatile and atomic simultaneously?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions