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#[cfg(target_os = "fuchsia")]
132impl From<SamplerSynchronousProxy> for zx::Handle {
133    fn from(value: SamplerSynchronousProxy) -> Self {
134        value.into_channel().into()
135    }
136}
137
138#[cfg(target_os = "fuchsia")]
139impl From<fidl::Channel> for SamplerSynchronousProxy {
140    fn from(value: fidl::Channel) -> Self {
141        Self::new(value)
142    }
143}
144
145#[cfg(target_os = "fuchsia")]
146impl fidl::endpoints::FromClient for SamplerSynchronousProxy {
147    type Protocol = SamplerMarker;
148
149    fn from_client(value: fidl::endpoints::ClientEnd<SamplerMarker>) -> Self {
150        Self::new(value.into_channel())
151    }
152}
153
154#[derive(Debug, Clone)]
155pub struct SamplerProxy {
156    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
157}
158
159impl fidl::endpoints::Proxy for SamplerProxy {
160    type Protocol = SamplerMarker;
161
162    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
163        Self::new(inner)
164    }
165
166    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
167        self.client.into_channel().map_err(|client| Self { client })
168    }
169
170    fn as_channel(&self) -> &::fidl::AsyncChannel {
171        self.client.as_channel()
172    }
173}
174
175impl SamplerProxy {
176    /// Create a new Proxy for fuchsia.memory.sampler/Sampler.
177    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
178        let protocol_name = <SamplerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
179        Self { client: fidl::client::Client::new(channel, protocol_name) }
180    }
181
182    /// Get a Stream of events from the remote end of the protocol.
183    ///
184    /// # Panics
185    ///
186    /// Panics if the event stream was already taken.
187    pub fn take_event_stream(&self) -> SamplerEventStream {
188        SamplerEventStream { event_receiver: self.client.take_event_receiver() }
189    }
190
191    /// Record an allocation.
192    pub fn r#record_allocation(
193        &self,
194        mut address: u64,
195        mut stack_trace: &StackTrace,
196        mut size: u64,
197    ) -> Result<(), fidl::Error> {
198        SamplerProxyInterface::r#record_allocation(self, address, stack_trace, size)
199    }
200
201    /// Record a deallocation.
202    pub fn r#record_deallocation(
203        &self,
204        mut address: u64,
205        mut stack_trace: &StackTrace,
206    ) -> Result<(), fidl::Error> {
207        SamplerProxyInterface::r#record_deallocation(self, address, stack_trace)
208    }
209
210    /// Communicate relevant process information to facilitate symbolization.
211    ///
212    /// If called several times, the last `process_name` prevails, but the
213    /// `module_map` is added to the existing map for the process. If a client
214    /// needs to send a `module_map` that does not fit in a single message, they
215    /// can split it and send it across several messages.
216    pub fn r#set_process_info(
217        &self,
218        mut payload: &SamplerSetProcessInfoRequest,
219    ) -> Result<(), fidl::Error> {
220        SamplerProxyInterface::r#set_process_info(self, payload)
221    }
222}
223
224impl SamplerProxyInterface for SamplerProxy {
225    fn r#record_allocation(
226        &self,
227        mut address: u64,
228        mut stack_trace: &StackTrace,
229        mut size: u64,
230    ) -> Result<(), fidl::Error> {
231        self.client.send::<SamplerRecordAllocationRequest>(
232            (address, stack_trace, size),
233            0x6b0add9f7769824d,
234            fidl::encoding::DynamicFlags::empty(),
235        )
236    }
237
238    fn r#record_deallocation(
239        &self,
240        mut address: u64,
241        mut stack_trace: &StackTrace,
242    ) -> Result<(), fidl::Error> {
243        self.client.send::<SamplerRecordDeallocationRequest>(
244            (address, stack_trace),
245            0x503bff5ec34dbeeb,
246            fidl::encoding::DynamicFlags::empty(),
247        )
248    }
249
250    fn r#set_process_info(
251        &self,
252        mut payload: &SamplerSetProcessInfoRequest,
253    ) -> Result<(), fidl::Error> {
254        self.client.send::<SamplerSetProcessInfoRequest>(
255            payload,
256            0x68a0557106e51783,
257            fidl::encoding::DynamicFlags::empty(),
258        )
259    }
260}
261
262pub struct SamplerEventStream {
263    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
264}
265
266impl std::marker::Unpin for SamplerEventStream {}
267
268impl futures::stream::FusedStream for SamplerEventStream {
269    fn is_terminated(&self) -> bool {
270        self.event_receiver.is_terminated()
271    }
272}
273
274impl futures::Stream for SamplerEventStream {
275    type Item = Result<SamplerEvent, fidl::Error>;
276
277    fn poll_next(
278        mut self: std::pin::Pin<&mut Self>,
279        cx: &mut std::task::Context<'_>,
280    ) -> std::task::Poll<Option<Self::Item>> {
281        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
282            &mut self.event_receiver,
283            cx
284        )?) {
285            Some(buf) => std::task::Poll::Ready(Some(SamplerEvent::decode(buf))),
286            None => std::task::Poll::Ready(None),
287        }
288    }
289}
290
291#[derive(Debug)]
292pub enum SamplerEvent {}
293
294impl SamplerEvent {
295    /// Decodes a message buffer as a [`SamplerEvent`].
296    fn decode(
297        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
298    ) -> Result<SamplerEvent, fidl::Error> {
299        let (bytes, _handles) = buf.split_mut();
300        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
301        debug_assert_eq!(tx_header.tx_id, 0);
302        match tx_header.ordinal {
303            _ => Err(fidl::Error::UnknownOrdinal {
304                ordinal: tx_header.ordinal,
305                protocol_name: <SamplerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
306            }),
307        }
308    }
309}
310
311/// A Stream of incoming requests for fuchsia.memory.sampler/Sampler.
312pub struct SamplerRequestStream {
313    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
314    is_terminated: bool,
315}
316
317impl std::marker::Unpin for SamplerRequestStream {}
318
319impl futures::stream::FusedStream for SamplerRequestStream {
320    fn is_terminated(&self) -> bool {
321        self.is_terminated
322    }
323}
324
325impl fidl::endpoints::RequestStream for SamplerRequestStream {
326    type Protocol = SamplerMarker;
327    type ControlHandle = SamplerControlHandle;
328
329    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
330        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
331    }
332
333    fn control_handle(&self) -> Self::ControlHandle {
334        SamplerControlHandle { inner: self.inner.clone() }
335    }
336
337    fn into_inner(
338        self,
339    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
340    {
341        (self.inner, self.is_terminated)
342    }
343
344    fn from_inner(
345        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
346        is_terminated: bool,
347    ) -> Self {
348        Self { inner, is_terminated }
349    }
350}
351
352impl futures::Stream for SamplerRequestStream {
353    type Item = Result<SamplerRequest, fidl::Error>;
354
355    fn poll_next(
356        mut self: std::pin::Pin<&mut Self>,
357        cx: &mut std::task::Context<'_>,
358    ) -> std::task::Poll<Option<Self::Item>> {
359        let this = &mut *self;
360        if this.inner.check_shutdown(cx) {
361            this.is_terminated = true;
362            return std::task::Poll::Ready(None);
363        }
364        if this.is_terminated {
365            panic!("polled SamplerRequestStream after completion");
366        }
367        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
368            |bytes, handles| {
369                match this.inner.channel().read_etc(cx, bytes, handles) {
370                    std::task::Poll::Ready(Ok(())) => {}
371                    std::task::Poll::Pending => return std::task::Poll::Pending,
372                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
373                        this.is_terminated = true;
374                        return std::task::Poll::Ready(None);
375                    }
376                    std::task::Poll::Ready(Err(e)) => {
377                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
378                            e.into(),
379                        ))))
380                    }
381                }
382
383                // A message has been received from the channel
384                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
385
386                std::task::Poll::Ready(Some(match header.ordinal {
387                    0x6b0add9f7769824d => {
388                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
389                        let mut req = fidl::new_empty!(
390                            SamplerRecordAllocationRequest,
391                            fidl::encoding::DefaultFuchsiaResourceDialect
392                        );
393                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<SamplerRecordAllocationRequest>(&header, _body_bytes, handles, &mut req)?;
394                        let control_handle = SamplerControlHandle { inner: this.inner.clone() };
395                        Ok(SamplerRequest::RecordAllocation {
396                            address: req.address,
397                            stack_trace: req.stack_trace,
398                            size: req.size,
399
400                            control_handle,
401                        })
402                    }
403                    0x503bff5ec34dbeeb => {
404                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
405                        let mut req = fidl::new_empty!(
406                            SamplerRecordDeallocationRequest,
407                            fidl::encoding::DefaultFuchsiaResourceDialect
408                        );
409                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<SamplerRecordDeallocationRequest>(&header, _body_bytes, handles, &mut req)?;
410                        let control_handle = SamplerControlHandle { inner: this.inner.clone() };
411                        Ok(SamplerRequest::RecordDeallocation {
412                            address: req.address,
413                            stack_trace: req.stack_trace,
414
415                            control_handle,
416                        })
417                    }
418                    0x68a0557106e51783 => {
419                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
420                        let mut req = fidl::new_empty!(
421                            SamplerSetProcessInfoRequest,
422                            fidl::encoding::DefaultFuchsiaResourceDialect
423                        );
424                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<SamplerSetProcessInfoRequest>(&header, _body_bytes, handles, &mut req)?;
425                        let control_handle = SamplerControlHandle { inner: this.inner.clone() };
426                        Ok(SamplerRequest::SetProcessInfo { payload: req, control_handle })
427                    }
428                    _ => Err(fidl::Error::UnknownOrdinal {
429                        ordinal: header.ordinal,
430                        protocol_name:
431                            <SamplerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
432                    }),
433                }))
434            },
435        )
436    }
437}
438
439/// Interface used to exfiltrate process allocation information.
440#[derive(Debug)]
441pub enum SamplerRequest {
442    /// Record an allocation.
443    RecordAllocation {
444        address: u64,
445        stack_trace: StackTrace,
446        size: u64,
447        control_handle: SamplerControlHandle,
448    },
449    /// Record a deallocation.
450    RecordDeallocation {
451        address: u64,
452        stack_trace: StackTrace,
453        control_handle: SamplerControlHandle,
454    },
455    /// Communicate relevant process information to facilitate symbolization.
456    ///
457    /// If called several times, the last `process_name` prevails, but the
458    /// `module_map` is added to the existing map for the process. If a client
459    /// needs to send a `module_map` that does not fit in a single message, they
460    /// can split it and send it across several messages.
461    SetProcessInfo { payload: SamplerSetProcessInfoRequest, control_handle: SamplerControlHandle },
462}
463
464impl SamplerRequest {
465    #[allow(irrefutable_let_patterns)]
466    pub fn into_record_allocation(self) -> Option<(u64, StackTrace, u64, SamplerControlHandle)> {
467        if let SamplerRequest::RecordAllocation { address, stack_trace, size, control_handle } =
468            self
469        {
470            Some((address, stack_trace, size, control_handle))
471        } else {
472            None
473        }
474    }
475
476    #[allow(irrefutable_let_patterns)]
477    pub fn into_record_deallocation(self) -> Option<(u64, StackTrace, SamplerControlHandle)> {
478        if let SamplerRequest::RecordDeallocation { address, stack_trace, control_handle } = self {
479            Some((address, stack_trace, control_handle))
480        } else {
481            None
482        }
483    }
484
485    #[allow(irrefutable_let_patterns)]
486    pub fn into_set_process_info(
487        self,
488    ) -> Option<(SamplerSetProcessInfoRequest, SamplerControlHandle)> {
489        if let SamplerRequest::SetProcessInfo { payload, control_handle } = self {
490            Some((payload, control_handle))
491        } else {
492            None
493        }
494    }
495
496    /// Name of the method defined in FIDL
497    pub fn method_name(&self) -> &'static str {
498        match *self {
499            SamplerRequest::RecordAllocation { .. } => "record_allocation",
500            SamplerRequest::RecordDeallocation { .. } => "record_deallocation",
501            SamplerRequest::SetProcessInfo { .. } => "set_process_info",
502        }
503    }
504}
505
506#[derive(Debug, Clone)]
507pub struct SamplerControlHandle {
508    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
509}
510
511impl fidl::endpoints::ControlHandle for SamplerControlHandle {
512    fn shutdown(&self) {
513        self.inner.shutdown()
514    }
515    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
516        self.inner.shutdown_with_epitaph(status)
517    }
518
519    fn is_closed(&self) -> bool {
520        self.inner.channel().is_closed()
521    }
522    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
523        self.inner.channel().on_closed()
524    }
525
526    #[cfg(target_os = "fuchsia")]
527    fn signal_peer(
528        &self,
529        clear_mask: zx::Signals,
530        set_mask: zx::Signals,
531    ) -> Result<(), zx_status::Status> {
532        use fidl::Peered;
533        self.inner.channel().signal_peer(clear_mask, set_mask)
534    }
535}
536
537impl SamplerControlHandle {}
538
539mod internal {
540    use super::*;
541}