@@ -18,7 +18,7 @@ limitations under the License.
18
18
// === Dependencies ===
19
19
extern crate alloc;
20
20
21
- use alloc :: string :: ToString ;
21
+ use core :: fmt :: Write ;
22
22
23
23
use buddy_system_allocator:: LockedHeap ;
24
24
#[ cfg( target_arch = "x86_64" ) ]
@@ -30,7 +30,7 @@ use hyperlight_common::flatbuffer_wrappers::guest_error::ErrorCode;
30
30
use hyperlight_common:: mem:: HyperlightPEB ;
31
31
#[ cfg( feature = "mem_profile" ) ]
32
32
use hyperlight_common:: outb:: OutBAction ;
33
- use hyperlight_guest:: exit:: { abort_with_code_and_message , halt } ;
33
+ use hyperlight_guest:: exit:: { halt , write_abort } ;
34
34
use hyperlight_guest:: guest_handle:: handle:: GuestHandle ;
35
35
use hyperlight_guest_tracing:: { trace, trace_function} ;
36
36
use log:: LevelFilter ;
@@ -139,11 +139,37 @@ pub static mut OS_PAGE_SIZE: u32 = 0;
139
139
// to satisfy the clippy when cfg == test
140
140
#[ allow( dead_code) ]
141
141
fn panic ( info : & core:: panic:: PanicInfo ) -> ! {
142
- let msg = info. to_string ( ) ;
143
- let c_string = alloc:: ffi:: CString :: new ( msg)
144
- . unwrap_or_else ( |_| alloc:: ffi:: CString :: new ( "panic (invalid utf8)" ) . unwrap ( ) ) ;
142
+ _panic_handler ( info)
143
+ }
144
+
145
+ /// A writer that sends all output to the hyperlight host
146
+ /// using output ports. This allows us to not impose a
147
+ /// buffering limit on error message size on the guest end,
148
+ /// though one exists for the host.
149
+ struct HyperlightAbortWriter ;
150
+ impl core:: fmt:: Write for HyperlightAbortWriter {
151
+ fn write_str ( & mut self , s : & str ) -> core:: fmt:: Result {
152
+ write_abort ( s. as_bytes ( ) ) ;
153
+ Ok ( ( ) )
154
+ }
155
+ }
156
+
157
+ #[ inline( always) ]
158
+ fn _panic_handler ( info : & core:: panic:: PanicInfo ) -> ! {
159
+ let mut w = HyperlightAbortWriter ;
160
+
161
+ // begin abort sequence by writing the error code
162
+ write_abort ( & [ ErrorCode :: UnknownError as u8 ] ) ;
163
+
164
+ let write_res = write ! ( w, "{}" , info) ;
165
+ if write_res. is_err ( ) {
166
+ write_abort ( "panic: message format failed" . as_bytes ( ) ) ;
167
+ }
145
168
146
- unsafe { abort_with_code_and_message ( & [ ErrorCode :: UnknownError as u8 ] , c_string. as_ptr ( ) ) }
169
+ // write abort terminator to finish the abort
170
+ // and signal to the host that the message can now be read
171
+ write_abort ( & [ 0xFF ] ) ;
172
+ unreachable ! ( ) ;
147
173
}
148
174
149
175
// === Entrypoint ===
0 commit comments