(msg: core::fmt::Arguments<'_>)
| 531 | |
| 532 | #[cfg(all(unix, feature = "threading"))] |
| 533 | pub(super) fn stw_trace(msg: core::fmt::Arguments<'_>) { |
| 534 | if stw_trace_enabled() { |
| 535 | use core::fmt::Write as _; |
| 536 | |
| 537 | // Avoid stdio locking here: this path runs around fork where a child |
| 538 | // may inherit a borrowed stderr lock and panic on eprintln!/stderr. |
| 539 | struct FixedBuf { |
| 540 | buf: [u8; 512], |
| 541 | len: usize, |
| 542 | } |
| 543 | |
| 544 | impl core::fmt::Write for FixedBuf { |
| 545 | fn write_str(&mut self, s: &str) -> core::fmt::Result { |
| 546 | if self.len >= self.buf.len() { |
| 547 | return Ok(()); |
| 548 | } |
| 549 | let remain = self.buf.len() - self.len; |
| 550 | let src = s.as_bytes(); |
| 551 | let n = src.len().min(remain); |
| 552 | self.buf[self.len..self.len + n].copy_from_slice(&src[..n]); |
| 553 | self.len += n; |
| 554 | Ok(()) |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | let mut out = FixedBuf { |
| 559 | buf: [0u8; 512], |
| 560 | len: 0, |
| 561 | }; |
| 562 | let _ = writeln!( |
| 563 | &mut out, |
| 564 | "[rp-stw tid={}] {}", |
| 565 | crate::stdlib::_thread::get_ident(), |
| 566 | msg |
| 567 | ); |
| 568 | unsafe { |
| 569 | let _ = libc::write(libc::STDERR_FILENO, out.buf.as_ptr().cast(), out.len); |
| 570 | } |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | #[derive(Clone, Debug, Default)] |
| 575 | pub(crate) struct CallableCache { |
no test coverage detected