@@ -18,7 +18,6 @@ limitations under the License.
18
18
// === Dependencies ===
19
19
extern crate alloc;
20
20
21
- use core:: ffi:: CStr ;
22
21
use core:: fmt:: Write ;
23
22
24
23
use buddy_system_allocator:: LockedHeap ;
@@ -27,12 +26,11 @@ use exceptions::{gdt::load_gdt, idtr::load_idt};
27
26
use guest_function:: call:: dispatch_function;
28
27
use guest_function:: register:: GuestFunctionRegister ;
29
28
use guest_logger:: init_logger;
30
- use heapless:: String ;
31
29
use hyperlight_common:: flatbuffer_wrappers:: guest_error:: ErrorCode ;
32
30
use hyperlight_common:: mem:: HyperlightPEB ;
33
31
#[ cfg( feature = "mem_profile" ) ]
34
32
use hyperlight_common:: outb:: OutBAction ;
35
- use hyperlight_guest:: exit:: { abort_with_code_and_message , halt } ;
33
+ use hyperlight_guest:: exit:: { halt , write_abort } ;
36
34
use hyperlight_guest:: guest_handle:: handle:: GuestHandle ;
37
35
use hyperlight_guest_tracing:: { trace, trace_function} ;
38
36
use log:: LevelFilter ;
@@ -144,35 +142,42 @@ fn panic(info: &core::panic::PanicInfo) -> ! {
144
142
_panic_handler ( info)
145
143
}
146
144
147
- #[ inline( always) ]
148
- fn _panic_handler ( info : & core:: panic:: PanicInfo ) -> ! {
149
- // stack allocate a 512-byte message buffer.
150
- let mut panic_buf = String :: < 512 > :: new ( ) ;
151
- let write_res = write ! ( panic_buf, "{}\0 " , info) ;
152
- if write_res. is_err ( ) {
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 {
153
152
unsafe {
154
- abort_with_code_and_message (
155
- & [ ErrorCode :: UnknownError as u8 ] ,
156
- c"panic: message format failed (limit: 512 bytes)" . as_ptr ( ) ,
157
- )
153
+ write_abort ( s. as_bytes ( ) ) ;
158
154
}
155
+ Ok ( ( ) )
159
156
}
157
+ }
160
158
161
- let c_str_res = CStr :: from_bytes_with_nul ( panic_buf. as_bytes ( ) ) ;
162
- if c_str_res. is_err ( ) {
159
+ #[ inline( always) ]
160
+ fn _panic_handler ( info : & core:: panic:: PanicInfo ) -> ! {
161
+ let mut w = HyperlightAbortWriter ;
162
+
163
+ // begin abort sequence by writing the error code
164
+ unsafe {
165
+ write_abort (
166
+ & [ ErrorCode :: UnknownError as u8 ] ) ;
167
+ }
168
+
169
+ let write_res = write ! ( w, "{}" , info) ;
170
+ if write_res. is_err ( ) {
163
171
unsafe {
164
- abort_with_code_and_message (
165
- & [ ErrorCode :: UnknownError as u8 ] ,
166
- c"panic: failed to convert to CString" . as_ptr ( ) ,
167
- )
172
+ write_abort ( "panic: message format failed" . as_bytes ( ) ) ;
168
173
}
169
174
}
170
175
176
+ // write abort terminator to finish the abort
177
+ // and signal to the host that the message can now be read
171
178
unsafe {
172
- abort_with_code_and_message (
173
- & [ ErrorCode :: UnknownError as u8 ] ,
174
- c_str_res. unwrap ( ) . as_ptr ( ) ,
175
- )
179
+ write_abort ( & [ 0xFF ] ) ;
180
+ unreachable ! ( ) ;
176
181
}
177
182
}
178
183
0 commit comments