Skip to content

Commit c27910b

Browse files
Add safety docs
1 parent 8b10534 commit c27910b

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

cortex-m-rt/src/lib.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,41 +472,81 @@ impl ExceptionFrame {
472472
}
473473

474474
/// Sets the stacked value of (general purpose) register 0.
475+
///
476+
/// # Safety
477+
///
478+
/// This affects the `r0` register of the preempted code, which must not rely on it getting
479+
/// restored to its previous value.
475480
pub unsafe fn set_r0(&mut self, value: u32) {
476481
self.r0 = value;
477482
}
478483

479484
/// Sets the stacked value of (general purpose) register 1.
485+
///
486+
/// # Safety
487+
///
488+
/// This affects the `r1` register of the preempted code, which must not rely on it getting
489+
/// restored to its previous value.
480490
pub unsafe fn set_r1(&mut self, value: u32) {
481491
self.r1 = value;
482492
}
483493

484494
/// Sets the stacked value of (general purpose) register 2.
495+
///
496+
/// # Safety
497+
///
498+
/// This affects the `r2` register of the preempted code, which must not rely on it getting
499+
/// restored to its previous value.
485500
pub unsafe fn set_r2(&mut self, value: u32) {
486501
self.r2 = value;
487502
}
488503

489504
/// Sets the stacked value of (general purpose) register 3.
505+
///
506+
/// # Safety
507+
///
508+
/// This affects the `r3` register of the preempted code, which must not rely on it getting
509+
/// restored to its previous value.
490510
pub unsafe fn set_r3(&mut self, value: u32) {
491511
self.r3 = value;
492512
}
493513

494514
/// Sets the stacked value of (general purpose) register 12.
515+
///
516+
/// # Safety
517+
///
518+
/// This affects the `r12` register of the preempted code, which must not rely on it getting
519+
/// restored to its previous value.
495520
pub unsafe fn set_r12(&mut self, value: u32) {
496521
self.r12 = value;
497522
}
498523

499524
/// Sets the stacked value of the Link Register.
525+
///
526+
/// # Safety
527+
///
528+
/// This affects the `lr` register of the preempted code, which must not rely on it getting
529+
/// restored to its previous value.
500530
pub unsafe fn set_lr(&mut self, value: u32) {
501531
self.lr = value;
502532
}
503533

504534
/// Sets the stacked value of the Program Counter.
535+
///
536+
/// # Safety
537+
///
538+
/// This affects the `pc` register of the preempted code, which must not rely on it getting
539+
/// restored to its previous value.
505540
pub unsafe fn set_pc(&mut self, value: u32) {
506541
self.pc = value;
507542
}
508543

509544
/// Sets the stacked value of the Program Status Register.
545+
///
546+
/// # Safety
547+
///
548+
/// This affects the `xPSR` registers (`IPSR`, `APSR`, and `EPSR`) of the preempted code, which
549+
/// must not rely on them getting restored to their previous value.
510550
pub unsafe fn set_xpsr(&mut self, value: u32) {
511551
self.xpsr = value;
512552
}

0 commit comments

Comments
 (0)