(ctx: &VmCtx, ptr: u32)
| 835 | #[ensures(ctx_safe(ctx))] |
| 836 | #[ensures(trace_safe(trace, ctx))] |
| 837 | pub fn read(ctx: &VmCtx, ptr: u32) -> RuntimeResult<Subscription> { |
| 838 | if !ctx.fits_in_lin_mem_usize(ptr as usize, Self::WASI_SIZE as usize) { |
| 839 | return Err(RuntimeError::Eoverflow); |
| 840 | } |
| 841 | |
| 842 | if !is_aligned(Alignment::Eight, ptr) { |
| 843 | return Err(RuntimeError::Einval); |
| 844 | } |
| 845 | |
| 846 | // read the subscription struct fields |
| 847 | let userdata = ctx.read_u64(ptr as usize); |
| 848 | let tag = ctx.read_u64((ptr + 8) as usize); |
| 849 | |
| 850 | match tag { |
| 851 | Self::CLOCK_TAG => { |
| 852 | let v_clock_id = ctx.read_u32((ptr + 16) as usize); |
| 853 | let v_timeout = ctx.read_u64((ptr + 24) as usize); |
| 854 | let v_precision = ctx.read_u64((ptr + 32) as usize); |
| 855 | let v_flags = ctx.read_u64((ptr + 40) as usize); |
| 856 | |
| 857 | let precision = Timestamp::new(v_precision); |
| 858 | let flags = SubClockFlags::try_from(v_flags)?; |
| 859 | |
| 860 | Ok(Subscription { |
| 861 | userdata, |
| 862 | subscription_u: SubscriptionInner::Clock(SubscriptionClock { |
| 863 | id: v_clock_id, |
| 864 | timeout: Timestamp::new(v_timeout), |
| 865 | precision, |
| 866 | flags, |
| 867 | }), |
| 868 | }) |
| 869 | } |
| 870 | Self::FD_READ_TAG => { |
| 871 | let v_fd = ctx.read_u32((ptr + 16) as usize); |
| 872 | |
| 873 | Ok(Subscription { |
| 874 | userdata, |
| 875 | subscription_u: SubscriptionInner::Fd(SubscriptionFdReadWrite { |
| 876 | v_fd, |
| 877 | typ: SubscriptionFdType::Read, |
| 878 | }), |
| 879 | }) |
| 880 | } |
| 881 | Self::FD_WRITE_TAG => { |
| 882 | let v_fd = ctx.read_u32((ptr + 16) as usize); |
| 883 | |
| 884 | Ok(Subscription { |
| 885 | userdata, |
| 886 | subscription_u: SubscriptionInner::Fd(SubscriptionFdReadWrite { |
| 887 | v_fd, |
| 888 | typ: SubscriptionFdType::Write, |
| 889 | }), |
| 890 | }) |
| 891 | } |
| 892 | _ => Err(RuntimeError::Einval), |
| 893 | } |
| 894 | } |
nothing calls this directly
no test coverage detected