Skip to content

Commit 9848f84

Browse files
committed
Write core 1 arguments directly to RAM without casting to usize
1 parent 0e5fdcf commit 9848f84

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

rp2040-hal/src/multicore.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,19 @@ impl<'p> Core<'p> {
180180
// Set up the stack
181181
let mut stack_ptr = unsafe { stack.as_mut_ptr().add(stack.len()) };
182182

183-
let mut push = |v: usize| unsafe {
184-
stack_ptr = stack_ptr.sub(1);
185-
stack_ptr.write(v);
186-
};
187-
188183
// We don't want to drop this, since it's getting moved to the other core.
189184
let mut entry = ManuallyDrop::new(entry);
190185

191186
// Push the arguments to `core1_startup` onto the stack.
192-
push(stack.as_mut_ptr() as usize);
193-
push(&mut entry as *mut _ as usize);
187+
unsafe {
188+
// Push `stack_bottom`.
189+
stack_ptr = stack_ptr.sub(1);
190+
stack_ptr.cast::<*mut usize>().write(stack.as_mut_ptr());
191+
192+
// Push `entry`.
193+
stack_ptr = stack_ptr.sub(1);
194+
stack_ptr.cast::<&mut ManuallyDrop<F>>().write(&mut entry);
195+
}
194196

195197
let vector_table = ppb.vtor.read().bits();
196198

0 commit comments

Comments
 (0)