rust-embedded / rust-embedded/cortex-m

cortex-m-rt: consider enabling divide by zero trap by default

Open
#612 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
1k
Forks
202
Avg merge
6d 2h
Merged PRs (30d)
2

Description

In Cortex-M processors, (integer) divide by zero is not elevated to an exception/trap unless CCB->DIV_0_TRP is enabled, which is not the default setting. See https://developer.arm.com/documentation/100235/0004/the-cortex-m33-peripherals/system-control-block/configuration-and-control-register.

Instead, the result is undefined behavior/implementation defined. This is definitely surprising, if not unsound, under some expected behavior by Rust.

I'm not totally sure what happens on Cortex-M0/M0+ devices, or other devices without a hardware division unit.

We should probably set this bit in the cortex-m-rt init process (maybe toggled-off with an unsafe feature).

We might want to enable this to handle FFI or asm, but this is explicitly caught by Rust itself, rather than relying on the host to trap.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by investigating the cortex-m-rt init process and the Cortex-M differences mentioned in the issue, including devices without a hardware division unit. Determine whether DIV_0_TRP should be enabled by default and whether an unsafe opt-out is needed. Done means the supported-device behavior and default policy are established and verified.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
embedded-iot
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.