@@ -261,39 +261,36 @@ pub(crate) fn enable_main_stack_guard_monitoring() {
261261
262262#[ cfg( all( riscv, write_vec_table_monitoring) ) ]
263263pub ( crate ) fn setup_trap_section_protection ( ) {
264- #[ cfg( not( flip_link) ) ]
264+ if !cfg ! ( stack_guard_monitoring_with_debugger_connected)
265+ && crate :: debugger:: debugger_connected ( )
265266 {
266- if !cfg ! ( stack_guard_monitoring_with_debugger_connected)
267- && crate :: debugger:: debugger_connected ( )
268- {
269- return ;
270- }
267+ return ;
268+ }
271269
272- unsafe extern "C" {
273- static _rwtext_len: u32 ;
274- static _trap_section_origin: u32 ;
275- }
270+ unsafe extern "C" {
271+ static _rwtext_len: u32 ;
272+ static _trap_section_origin: u32 ;
273+ }
276274
277- let rwtext_len = core:: ptr:: addr_of!( _rwtext_len) as usize ;
275+ let rwtext_len = core:: ptr:: addr_of!( _rwtext_len) as usize ;
278276
279- // protect as much as possible via NAPOT
280- let len = 1 << ( usize:: BITS - rwtext_len. leading_zeros ( ) - 1 ) as usize ;
281- if len == 0 {
282- warn ! ( "No trap vector protection available" ) ;
283- return ;
284- }
277+ // protect as much as possible via NAPOT
278+ let len = 1 << ( usize:: BITS - rwtext_len. leading_zeros ( ) - 1 ) as usize ;
279+ if len == 0 {
280+ warn ! ( "No trap vector protection available" ) ;
281+ return ;
282+ }
285283
286- // protect MTVEC and trap handlers
287- // (probably plus some more bytes because of NAPOT)
288- // via watchpoint 1.
289- //
290- // Why not use PMP? On C2/C3 the bootloader locks all available PMP entries.
291- // And additionally we write to MTVEC for direct-vectoring and we write
292- // to __EXTERNAL_INTERRUPTS when setting an interrupt handler.
293- let addr = core:: ptr:: addr_of!( _trap_section_origin) as usize ;
284+ // protect MTVEC and trap handlers
285+ // (probably plus some more bytes because of NAPOT)
286+ // via watchpoint 1.
287+ //
288+ // Why not use PMP? On C2/C3 the bootloader locks all available PMP entries.
289+ // And additionally we write to MTVEC for direct-vectoring and we write
290+ // to __EXTERNAL_INTERRUPTS when setting an interrupt handler.
291+ let addr = core:: ptr:: addr_of!( _trap_section_origin) as usize ;
294292
295- unsafe {
296- crate :: debugger:: set_watchpoint ( 1 , addr, len) ;
297- }
293+ unsafe {
294+ crate :: debugger:: set_watchpoint ( 1 , addr, len) ;
298295 }
299296}
0 commit comments