@@ -14,12 +14,13 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
1616
17- use alloc:: format;
18- use core:: ffi:: c_char;
17+ use core:: fmt:: Write ;
1918
2019use hyperlight_common:: flatbuffer_wrappers:: guest_error:: ErrorCode ;
2120use hyperlight_common:: outb:: Exception ;
22- use hyperlight_guest:: exit:: abort_with_code_and_message;
21+ use hyperlight_guest:: exit:: write_abort;
22+
23+ use crate :: HyperlightAbortWriter ;
2324
2425/// Exception information pushed onto the stack by the CPU during an excpection.
2526///
@@ -125,15 +126,6 @@ pub(crate) extern "C" fn hl_exception_handler(
125126 let saved_rip = unsafe { ( & raw const ( * exn_info) . rip ) . read_volatile ( ) } ;
126127 let error_code = unsafe { ( & raw const ( * exn_info) . error_code ) . read_volatile ( ) } ;
127128
128- let msg = format ! (
129- "Exception vector: {:#}\n \
130- Faulting Instruction: {:#x}\n \
131- Page Fault Address: {:#x}\n \
132- Error code: {:#x}\n \
133- Stack Pointer: {:#x}",
134- exception_number, saved_rip, page_fault_address, error_code, stack_pointer
135- ) ;
136-
137129 // Check for registered user handlers (only for architecture-defined vectors 0-30)
138130 if exception_number < 31 {
139131 let handler =
@@ -149,10 +141,24 @@ pub(crate) extern "C" fn hl_exception_handler(
149141 }
150142 }
151143
152- unsafe {
153- abort_with_code_and_message (
154- & [ ErrorCode :: GuestError as u8 , exception as u8 ] ,
155- msg. as_ptr ( ) as * const c_char ,
156- ) ;
144+ // begin abort sequence by writing the error code
145+ let mut w = HyperlightAbortWriter ;
146+ write_abort ( & [ ErrorCode :: GuestError as u8 , exception as u8 ] ) ;
147+ let write_res = write ! (
148+ w,
149+ "Exception vector: {}\n \
150+ Faulting Instruction: {:#x}\n \
151+ Page Fault Address: {:#x}\n \
152+ Error code: {:#x}\n \
153+ Stack Pointer: {:#x}",
154+ exception_number, saved_rip, page_fault_address, error_code, stack_pointer
155+ ) ;
156+ if write_res. is_err ( ) {
157+ write_abort ( "exception message format failed" . as_bytes ( ) ) ;
157158 }
159+
160+ write_abort ( & [ 0xFF ] ) ;
161+ // At this point, write_abort with the 0xFF terminator is expected to terminate guest execution,
162+ // so control should never reach beyond this call.
163+ unreachable ! ( ) ;
158164}
0 commit comments