(&self, writer: &mut Writer)
| 49 | |
| 50 | impl UnwindCode { |
| 51 | fn emit(&self, writer: &mut Writer) { |
| 52 | enum UnwindOperation { |
| 53 | PushNonvolatileRegister = 0, |
| 54 | LargeStackAlloc = 1, |
| 55 | SmallStackAlloc = 2, |
| 56 | SetFPReg = 3, |
| 57 | SaveNonVolatileRegister = 4, |
| 58 | SaveNonVolatileRegisterFar = 5, |
| 59 | SaveXmm128 = 8, |
| 60 | SaveXmm128Far = 9, |
| 61 | } |
| 62 | |
| 63 | match self { |
| 64 | Self::PushRegister { |
| 65 | instruction_offset, |
| 66 | reg, |
| 67 | } => { |
| 68 | writer.write_u8(*instruction_offset); |
| 69 | writer.write_u8((*reg << 4) | (UnwindOperation::PushNonvolatileRegister as u8)); |
| 70 | } |
| 71 | Self::SaveReg { |
| 72 | instruction_offset, |
| 73 | reg, |
| 74 | stack_offset, |
| 75 | } |
| 76 | | Self::SaveXmm { |
| 77 | instruction_offset, |
| 78 | reg, |
| 79 | stack_offset, |
| 80 | } => { |
| 81 | let is_xmm = match self { |
| 82 | Self::SaveXmm { .. } => true, |
| 83 | _ => false, |
| 84 | }; |
| 85 | let (op_small, op_large) = if is_xmm { |
| 86 | (UnwindOperation::SaveXmm128, UnwindOperation::SaveXmm128Far) |
| 87 | } else { |
| 88 | ( |
| 89 | UnwindOperation::SaveNonVolatileRegister, |
| 90 | UnwindOperation::SaveNonVolatileRegisterFar, |
| 91 | ) |
| 92 | }; |
| 93 | writer.write_u8(*instruction_offset); |
| 94 | let scaled_stack_offset = stack_offset / 16; |
| 95 | if scaled_stack_offset <= core::u16::MAX as u32 { |
| 96 | writer.write_u8((*reg << 4) | (op_small as u8)); |
| 97 | writer.write_u16_le(scaled_stack_offset as u16); |
| 98 | } else { |
| 99 | writer.write_u8((*reg << 4) | (op_large as u8)); |
| 100 | writer.write_u16_le(*stack_offset as u16); |
| 101 | writer.write_u16_le((stack_offset >> 16) as u16); |
| 102 | } |
| 103 | } |
| 104 | Self::StackAlloc { |
| 105 | instruction_offset, |
| 106 | size, |
| 107 | } => { |
| 108 | // Stack allocations on Windows must be a multiple of 8 and be at least 1 slot |
nothing calls this directly
no test coverage detected