@@ -45,12 +45,10 @@ uint32_t debug_get_version(void)
4545 return 0 ;
4646}
4747
48- uint32_t g_debug_interrupt_sp [UVISOR_MAX_BOXES ];
49-
5048void debug_halt_error (THaltError reason , const THaltInfo * halt_info )
5149{
5250 static int debugged_once_before = 0 ;
53- void * info = NULL ;
51+ THaltInfo * dst_halt_info = NULL ;
5452
5553 /* If the debug box does not exist (or it has not been initialized yet), or
5654 * the debug box was already called once, just loop forever. */
@@ -62,16 +60,20 @@ void debug_halt_error(THaltError reason, const THaltInfo *halt_info)
6260
6361 /* Place the halt info on the interrupt stack. */
6462 if (halt_info ) {
65- g_debug_interrupt_sp [g_debug_box .box_id ] -= sizeof (THaltInfo );
66- info = (void * )g_debug_interrupt_sp [g_debug_box .box_id ];
67- memcpy (info , halt_info , sizeof (THaltInfo ));
63+ dst_halt_info = (THaltInfo * )(g_context_current_states [g_debug_box .box_id ].sp - sizeof (* halt_info ));
64+ if (vmpu_buffer_access_is_ok (g_debug_box .box_id , dst_halt_info , sizeof (* halt_info ))) {
65+ g_context_current_states [g_debug_box .box_id ].sp -= sizeof (* halt_info );
66+ memcpy (dst_halt_info , halt_info , sizeof (* halt_info ));
67+ } else {
68+ while (1 );
69+ }
6870 }
6971
7072 /* The following arguments are passed to the destination function:
7173 * 1. reason
7274 * 2. halt info
7375 * Upon return from the debug handler, the system will die. */
74- debug_deprivilege_and_return (g_debug_box .driver -> halt_error , debug_die , reason , (uint32_t )info , 0 , 0 );
76+ debug_deprivilege_and_return (g_debug_box .driver -> halt_error , debug_die , reason , (uint32_t )dst_halt_info , 0 , 0 );
7577 }
7678}
7779
@@ -107,11 +109,6 @@ void debug_register_driver(const TUvisorDebugDriver * const driver)
107109 }
108110 }
109111
110- for (int ii = 0 ; ii < UVISOR_MAX_BOXES ; ii ++ )
111- {
112- g_debug_interrupt_sp [ii ] = g_context_current_states [ii ].sp ;
113- }
114-
115112 /* Register the debug box.
116113 * The caller of this function is considered the owner of the debug box. */
117114 g_debug_box .driver = driver ;
0 commit comments