Handles an interpreter trap. This will initialize the trap state stored in TLS via the `test_if_trap` helper below by reading the pc/fp of the interpreter and seeing if that's a valid opcode to trap at.
(&mut self, pc: NonNull<u8>, kind: Option<TrapKind>)
| 455 | /// in TLS via the `test_if_trap` helper below by reading the pc/fp of the |
| 456 | /// interpreter and seeing if that's a valid opcode to trap at. |
| 457 | fn trap(&mut self, pc: NonNull<u8>, kind: Option<TrapKind>) -> NonNull<u8> { |
| 458 | let regs = TrapRegisters { |
| 459 | pc: pc.as_ptr() as usize, |
| 460 | fp: self.vm().fp() as usize, |
| 461 | }; |
| 462 | let handler = tls::with(|s| { |
| 463 | let s = s.unwrap(); |
| 464 | match kind { |
| 465 | Some(kind) => { |
| 466 | let trap = match kind { |
| 467 | TrapKind::IntegerOverflow => Trap::IntegerOverflow.into(), |
| 468 | TrapKind::DivideByZero => Trap::IntegerDivisionByZero.into(), |
| 469 | TrapKind::BadConversionToInteger => Trap::BadConversionToInteger.into(), |
| 470 | TrapKind::MemoryOutOfBounds => Trap::MemoryOutOfBounds.into(), |
| 471 | TrapKind::DisabledOpcode => Trap::DisabledOpcode.into(), |
| 472 | TrapKind::StackOverflow => Trap::StackOverflow.into(), |
| 473 | }; |
| 474 | s.set_jit_trap(regs, None, trap); |
| 475 | s.entry_trap_handler() |
| 476 | } |
| 477 | None => { |
| 478 | match s.test_if_trap(regs, None, |_| false) { |
| 479 | // This shouldn't be possible, so this is a fatal error |
| 480 | // if it happens. |
| 481 | TrapTest::NotWasm => { |
| 482 | panic!("pulley trap at {pc:?} without trap code registered") |
| 483 | } |
| 484 | |
| 485 | // Not possible with our closure above returning `false`. |
| 486 | #[cfg(has_native_signals)] |
| 487 | TrapTest::HandledByEmbedder => unreachable!(), |
| 488 | |
| 489 | // Trap was handled, yay! Configure interpreter state |
| 490 | // to resume at the exception handler. |
| 491 | TrapTest::Trap(handler) => handler, |
| 492 | } |
| 493 | } |
| 494 | } |
| 495 | }); |
| 496 | unsafe { |
| 497 | self.resume_to_exception_handler(&handler, 0, 0); |
| 498 | } |
| 499 | self.take_resume_at_pc() |
| 500 | } |
| 501 | |
| 502 | fn take_resume_at_pc(&mut self) -> NonNull<u8> { |
| 503 | let pc = self.vm_state().resume_at_pc.take().unwrap(); |
no test coverage detected