fidl_fuchsia_memory_sampler/
fidl_fuchsia_memory_sampler.rs

1// WARNING: This file is machine generated by fidlgen.
2
3#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fidl::client::QueryResponseFut;
8use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
9use fidl::endpoints::{ControlHandle as _, Responder as _};
10pub use fidl_fuchsia_memory_sampler_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct SamplerMarker;
16
17impl fidl::endpoints::ProtocolMarker for SamplerMarker {
18    type Proxy = SamplerProxy;
19    type RequestStream = SamplerRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = SamplerSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "fuchsia.memory.sampler.Sampler";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for SamplerMarker {}
26
27pub trait SamplerProxyInterface: Send + Sync {
28    fn r#record_allocation(
29        &self,
30        address: u64,
31        stack_trace: &StackTrace,
32        size: u64,
33    ) -> Result<(), fidl::Error>;
34    fn r#record_deallocation(
35        &self,
36        address: u64,
37        stack_trace: &StackTrace,
38    ) -> Result<(), fidl::Error>;
39    fn r#set_process_info(&self, payload: &SamplerSetProcessInfoRequest)
40        -> Result<(), fidl::Error>;
41}
42#[derive(Debug)]
43#[cfg(target_os = "fuchsia")]
44pub struct SamplerSynchronousProxy {
45    client: fidl::client::sync::Client,
46}
47
48#[cfg(target_os = "fuchsia")]
49impl fidl::endpoints::SynchronousProxy for SamplerSynchronousProxy {
50    type Proxy = SamplerProxy;
51    type Protocol = SamplerMarker;
52
53    fn from_channel(inner: fidl::Channel) -> Self {
54        Self::new(inner)
55    }
56
57    fn into_channel(self) -> fidl::Channel {
58        self.client.into_channel()
59    }
60
61    fn as_channel(&self) -> &fidl::Channel {
62        self.client.as_channel()
63    }
64}
65
66#[cfg(target_os = "fuchsia")]
67impl SamplerSynchronousProxy {
68    pub fn new(channel: fidl::Channel) -> Self {
69        let protocol_name = <SamplerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
70        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
71    }
72
73    pub fn into_channel(self) -> fidl::Channel {
74        self.client.into_channel()
75    }
76
77    /// Waits until an event arrives and returns it. It is safe for other
78    /// threads to make concurrent requests while waiting for an event.
79    pub fn wait_for_event(
80        &self,
81        deadline: zx::MonotonicInstant,
82    ) -> Result<SamplerEvent, fidl::Error> {
83        SamplerEvent::decode(self.client.wait_for_event(deadline)?)
84    }
85
86    /// Record an allocation.
87    pub fn r#record_allocation(
88        &self,
89        mut address: u64,
90        mut stack_trace: &StackTrace,
91        mut size: u64,
92    ) -> Result<(), fidl::Error> {
93        self.client.send::<SamplerRecordAllocationRequest>(
94            (address, stack_trace, size),
95            0x6b0add9f7769824d,
96            fidl::encoding::DynamicFlags::empty(),
97        )
98    }
99
100    /// Record a deallocation.
101    pub fn r#record_deallocation(
102        &self,
103        mut address: u64,
104        mut stack_trace: &StackTrace,
105    ) -> Result<(), fidl::Error> {
106        self.client.send::<SamplerRecordDeallocationRequest>(
107            (address, stack_trace),
108            0x503bff5ec34dbeeb,
109            fidl::encoding::DynamicFlags::empty(),
110        )
111    }
112
113    /// Communicate relevant process information to facilitate symbolization.
114    ///
115    /// If called several times, the last `process_name` prevails, but the
116    /// `module_map` is added to the existing map for the process. If a client
117    /// needs to send a `module_map` that does not fit in a single message, they
118    /// can split it and send it across several messages.
119    pub fn r#set_process_info(
120        &self,
121        mut payload: &SamplerSetProcessInfoRequest,
122    ) -> Result<(), fidl::Error> {
123        self.client.send::<SamplerSetProcessInfoRequest>(
124            payload,
125            0x68a0557106e51783,
126            fidl::encoding::DynamicFlags::empty(),
127        )
128    }
129}
130
131#[derive(Debug, Clone)]
132pub struct SamplerProxy {
133    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
134}
135
136impl fidl::endpoints::Proxy for SamplerProxy {
137    type Protocol = SamplerMarker;
138
139    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
140        Self::new(inner)
141    }
142
143    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
144        self.client.into_channel().map_err(|client| Self { client })
145    }
146
147    fn as_channel(&self) -> &::fidl::AsyncChannel {
148        self.client.as_channel()
149    }
150}
151
152impl SamplerProxy {
153    /// Create a new Proxy for fuchsia.memory.sampler/Sampler.
154    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
155        let protocol_name = <SamplerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
156        Self { client: fidl::client::Client::new(channel, protocol_name) }
157    }
158
159    /// Get a Stream of events from the remote end of the protocol.
160    ///
161    /// # Panics
162    ///
163    /// Panics if the event stream was already taken.
164    pub fn take_event_stream(&self) -> SamplerEventStream {
165        SamplerEventStream { event_receiver: self.client.take_event_receiver() }
166    }
167
168    /// Record an allocation.
169    pub fn r#record_allocation(
170        &self,
171        mut address: u64,
172        mut stack_trace: &StackTrace,
173        mut size: u64,
174    ) -> Result<(), fidl::Error> {
175        SamplerProxyInterface::r#record_allocation(self, address, stack_trace, size)
176    }
177
178    /// Record a deallocation.
179    pub fn r#record_deallocation(
180        &self,
181        mut address: u64,
182        mut stack_trace: &StackTrace,
183    ) -> Result<(), fidl::Error> {
184        SamplerProxyInterface::r#record_deallocation(self, address, stack_trace)
185    }
186
187    /// Communicate relevant process information to facilitate symbolization.
188    ///
189    /// If called several times, the last `process_name` prevails, but the
190    /// `module_map` is added to the existing map for the process. If a client
191    /// needs to send a `module_map` that does not fit in a single message, they
192    /// can split it and send it across several messages.
193    pub fn r#set_process_info(
194        &self,
195        mut payload: &SamplerSetProcessInfoRequest,
196    ) -> Result<(), fidl::Error> {
197        SamplerProxyInterface::r#set_process_info(self, payload)
198    }
199}
200
201impl SamplerProxyInterface for SamplerProxy {
202    fn r#record_allocation(
203        &self,
204        mut address: u64,
205        mut stack_trace: &StackTrace,
206        mut size: u64,
207    ) -> Result<(), fidl::Error> {
208        self.client.send::<SamplerRecordAllocationRequest>(
209            (address, stack_trace, size),
210            0x6b0add9f7769824d,
211            fidl::encoding::DynamicFlags::empty(),
212        )
213    }
214
215    fn r#record_deallocation(
216        &self,
217        mut address: u64,
218        mut stack_trace: &StackTrace,
219    ) -> Result<(), fidl::Error> {
220        self.client.send::<SamplerRecordDeallocationRequest>(
221            (address, stack_trace),
222            0x503bff5ec34dbeeb,
223            fidl::encoding::DynamicFlags::empty(),
224        )
225    }
226
227    fn r#set_process_info(
228        &self,
229        mut payload: &SamplerSetProcessInfoRequest,
230    ) -> Result<(), fidl::Error> {
231        self.client.send::<SamplerSetProcessInfoRequest>(
232            payload,
233            0x68a0557106e51783,
234            fidl::encoding::DynamicFlags::empty(),
235        )
236    }
237}
238
239pub struct SamplerEventStream {
240    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
241}
242
243impl std::marker::Unpin for SamplerEventStream {}
244
245impl futures::stream::FusedStream for SamplerEventStream {
246    fn is_terminated(&self) -> bool {
247        self.event_receiver.is_terminated()
248    }
249}
250
251impl futures::Stream for SamplerEventStream {
252    type Item = Result<SamplerEvent, fidl::Error>;
253
254    fn poll_next(
255        mut self: std::pin::Pin<&mut Self>,
256        cx: &mut std::task::Context<'_>,
257    ) -> std::task::Poll<Option<Self::Item>> {
258        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
259            &mut self.event_receiver,
260            cx
261        )?) {
262            Some(buf) => std::task::Poll::Ready(Some(SamplerEvent::decode(buf))),
263            None => std::task::Poll::Ready(None),
264        }
265    }
266}
267
268#[derive(Debug)]
269pub enum SamplerEvent {}
270
271impl SamplerEvent {
272    /// Decodes a message buffer as a [`SamplerEvent`].
273    fn decode(
274        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
275    ) -> Result<SamplerEvent, fidl::Error> {
276        let (bytes, _handles) = buf.split_mut();
277        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
278        debug_assert_eq!(tx_header.tx_id, 0);
279        match tx_header.ordinal {
280            _ => Err(fidl::Error::UnknownOrdinal {
281                ordinal: tx_header.ordinal,
282                protocol_name: <SamplerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
283            }),
284        }
285    }
286}
287
288/// A Stream of incoming requests for fuchsia.memory.sampler/Sampler.
289pub struct SamplerRequestStream {
290    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
291    is_terminated: bool,
292}
293
294impl std::marker::Unpin for SamplerRequestStream {}
295
296impl futures::stream::FusedStream for SamplerRequestStream {
297    fn is_terminated(&self) -> bool {
298        self.is_terminated
299    }
300}
301
302impl fidl::endpoints::RequestStream for SamplerRequestStream {
303    type Protocol = SamplerMarker;
304    type ControlHandle = SamplerControlHandle;
305
306    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
307        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
308    }
309
310    fn control_handle(&self) -> Self::ControlHandle {
311        SamplerControlHandle { inner: self.inner.clone() }
312    }
313
314    fn into_inner(
315        self,
316    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
317    {
318        (self.inner, self.is_terminated)
319    }
320
321    fn from_inner(
322        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
323        is_terminated: bool,
324    ) -> Self {
325        Self { inner, is_terminated }
326    }
327}
328
329impl futures::Stream for SamplerRequestStream {
330    type Item = Result<SamplerRequest, fidl::Error>;
331
332    fn poll_next(
333        mut self: std::pin::Pin<&mut Self>,
334        cx: &mut std::task::Context<'_>,
335    ) -> std::task::Poll<Option<Self::Item>> {
336        let this = &mut *self;
337        if this.inner.check_shutdown(cx) {
338            this.is_terminated = true;
339            return std::task::Poll::Ready(None);
340        }
341        if this.is_terminated {
342            panic!("polled SamplerRequestStream after completion");
343        }
344        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
345            |bytes, handles| {
346                match this.inner.channel().read_etc(cx, bytes, handles) {
347                    std::task::Poll::Ready(Ok(())) => {}
348                    std::task::Poll::Pending => return std::task::Poll::Pending,
349                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
350                        this.is_terminated = true;
351                        return std::task::Poll::Ready(None);
352                    }
353                    std::task::Poll::Ready(Err(e)) => {
354                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
355                            e.into(),
356                        ))))
357                    }
358                }
359
360                // A message has been received from the channel
361                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
362
363                std::task::Poll::Ready(Some(match header.ordinal {
364                    0x6b0add9f7769824d => {
365                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
366                        let mut req = fidl::new_empty!(
367                            SamplerRecordAllocationRequest,
368                            fidl::encoding::DefaultFuchsiaResourceDialect
369                        );
370                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<SamplerRecordAllocationRequest>(&header, _body_bytes, handles, &mut req)?;
371                        let control_handle = SamplerControlHandle { inner: this.inner.clone() };
372                        Ok(SamplerRequest::RecordAllocation {
373                            address: req.address,
374                            stack_trace: req.stack_trace,
375                            size: req.size,
376
377                            control_handle,
378                        })
379                    }
380                    0x503bff5ec34dbeeb => {
381                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
382                        let mut req = fidl::new_empty!(
383                            SamplerRecordDeallocationRequest,
384                            fidl::encoding::DefaultFuchsiaResourceDialect
385                        );
386                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<SamplerRecordDeallocationRequest>(&header, _body_bytes, handles, &mut req)?;
387                        let control_handle = SamplerControlHandle { inner: this.inner.clone() };
388                        Ok(SamplerRequest::RecordDeallocation {
389                            address: req.address,
390                            stack_trace: req.stack_trace,
391
392                            control_handle,
393                        })
394                    }
395                    0x68a0557106e51783 => {
396                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
397                        let mut req = fidl::new_empty!(
398                            SamplerSetProcessInfoRequest,
399                            fidl::encoding::DefaultFuchsiaResourceDialect
400                        );
401                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<SamplerSetProcessInfoRequest>(&header, _body_bytes, handles, &mut req)?;
402                        let control_handle = SamplerControlHandle { inner: this.inner.clone() };
403                        Ok(SamplerRequest::SetProcessInfo { payload: req, control_handle })
404                    }
405                    _ => Err(fidl::Error::UnknownOrdinal {
406                        ordinal: header.ordinal,
407                        protocol_name:
408                            <SamplerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
409                    }),
410                }))
411            },
412        )
413    }
414}
415
416/// Interface used to exfiltrate process allocation information.
417#[derive(Debug)]
418pub enum SamplerRequest {
419    /// Record an allocation.
420    RecordAllocation {
421        address: u64,
422        stack_trace: StackTrace,
423        size: u64,
424        control_handle: SamplerControlHandle,
425    },
426    /// Record a deallocation.
427    RecordDeallocation {
428        address: u64,
429        stack_trace: StackTrace,
430        control_handle: SamplerControlHandle,
431    },
432    /// Communicate relevant process information to facilitate symbolization.
433    ///
434    /// If called several times, the last `process_name` prevails, but the
435    /// `module_map` is added to the existing map for the process. If a client
436    /// needs to send a `module_map` that does not fit in a single message, they
437    /// can split it and send it across several messages.
438    SetProcessInfo { payload: SamplerSetProcessInfoRequest, control_handle: SamplerControlHandle },
439}
440
441impl SamplerRequest {
442    #[allow(irrefutable_let_patterns)]
443    pub fn into_record_allocation(self) -> Option<(u64, StackTrace, u64, SamplerControlHandle)> {
444        if let SamplerRequest::RecordAllocation { address, stack_trace, size, control_handle } =
445            self
446        {
447            Some((address, stack_trace, size, control_handle))
448        } else {
449            None
450        }
451    }
452
453    #[allow(irrefutable_let_patterns)]
454    pub fn into_record_deallocation(self) -> Option<(u64, StackTrace, SamplerControlHandle)> {
455        if let SamplerRequest::RecordDeallocation { address, stack_trace, control_handle } = self {
456            Some((address, stack_trace, control_handle))
457        } else {
458            None
459        }
460    }
461
462    #[allow(irrefutable_let_patterns)]
463    pub fn into_set_process_info(
464        self,
465    ) -> Option<(SamplerSetProcessInfoRequest, SamplerControlHandle)> {
466        if let SamplerRequest::SetProcessInfo { payload, control_handle } = self {
467            Some((payload, control_handle))
468        } else {
469            None
470        }
471    }
472
473    /// Name of the method defined in FIDL
474    pub fn method_name(&self) -> &'static str {
475        match *self {
476            SamplerRequest::RecordAllocation { .. } => "record_allocation",
477            SamplerRequest::RecordDeallocation { .. } => "record_deallocation",
478            SamplerRequest::SetProcessInfo { .. } => "set_process_info",
479        }
480    }
481}
482
483#[derive(Debug, Clone)]
484pub struct SamplerControlHandle {
485    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
486}
487
488impl fidl::endpoints::ControlHandle for SamplerControlHandle {
489    fn shutdown(&self) {
490        self.inner.shutdown()
491    }
492    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
493        self.inner.shutdown_with_epitaph(status)
494    }
495
496    fn is_closed(&self) -> bool {
497        self.inner.channel().is_closed()
498    }
499    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
500        self.inner.channel().on_closed()
501    }
502
503    #[cfg(target_os = "fuchsia")]
504    fn signal_peer(
505        &self,
506        clear_mask: zx::Signals,
507        set_mask: zx::Signals,
508    ) -> Result<(), zx_status::Status> {
509        use fidl::Peered;
510        self.inner.channel().signal_peer(clear_mask, set_mask)
511    }
512}
513
514impl SamplerControlHandle {}
515
516mod internal {
517    use super::*;
518}