summaryrefslogtreecommitdiff
path: root/doc/kdbus.message.xml
blob: 3482961a5dadb08bac7a23bde3b852d42075b5aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
<?xml version='1.0'?> <!--*-nxml-*-->
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
        "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">

<refentry id="kdbus.message">

  <refentryinfo>
    <title>kdbus.message</title>
    <productname>kdbus.message</productname>
  </refentryinfo>

  <refmeta>
    <refentrytitle>kdbus.message</refentrytitle>
    <manvolnum>7</manvolnum>
  </refmeta>

  <refnamediv>
    <refname>kdbus.message</refname>
    <refpurpose>kdbus message</refpurpose>
  </refnamediv>

  <refsect1>
    <title>Description</title>

    <para>
      Messages are passed to the kernel with the <varname>KDBUS_CMD_SEND</varname>
      ioctl. Depending on the destination address of the message, the kernel
      delivers the message to the specific destination connection, or to all
      connections on the same bus.
      Sending messages across buses is not possible. Messages are always queued in
      the memory pool of the destination connection (see below).
    </para>

    <para>
      The <varname>KDBUS_CMD_SEND</varname> ioctl uses a
      <varname>struct kdbus_cmd_send</varname> to describe the message
      transfer.
    </para>
    <programlisting>
struct kdbus_cmd_send {
  __u64 size;
  __u64 flags;
  __u64 kernel_flags;
  __u64 kernel_msg_flags;
  __u64 return_flags;
  __u64 msg_address;
  struct kdbus_msg_info reply;
  struct kdbus_item items[0];
};
    </programlisting>

    <para>The fields in this struct are described below.</para>

    <variablelist>
      <varlistentry>
        <term><varname>size</varname></term>
        <listitem><para>
          The overall size of the struct, including its items.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>flags</varname></term>
        <listitem><para>Flags for message delivery</para>
          <variablelist>
            <varlistentry>
              <term><varname>KDBUS_SEND_SYNC_REPLY</varname></term>
              <listitem>
                <para>
                  By default, all calls to kdbus are considered asynchronous,
                  non-blocking. However, as there are many use cases that need to wait
                  for a remote peer to answer a method call, there's a way to send a
                  message and wait for a reply in a synchronous fashion. This is what
                  the KDBUS_MSG_SYNC_REPLY controls. The KDBUS_CMD_SEND ioctl will block
                  until the reply has arrived, the timeout limit is reached, in case the
                  remote connection was shut down, or if interrupted by a signal before
                  any reply; see signal(7).

                  The offset of the reply message in the sender's pool is stored in in
                  'offset_reply' when the ioctl has returned without error. Hence, there
                  is no need for another KDBUS_CMD_RECV ioctl or anything else to receive
                  the reply.
                </para>
              </listitem>
            </varlistentry>
          </variablelist>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>kernel_flags</varname></term>
        <listitem><para>
          Valid flags for this command, returned by the kernel upon each call.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>return_flags</varname></term>
        <listitem><para>
          Flags returned by the kernel. Currently unused and always set to
          zero by the kernel.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>msg_address</varname></term>
        <listitem><para>
          In this field, userspace has to provide a pointer to a message
          (<varname>struct kdbus_msg</varname>) to send. See below for a
          detailed description.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>reply</varname></term>
        <listitem><para>
          Only used for synchronous replies. See description of
          <varname>struct kdbus_cmd_recv</varname> for more details.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>items</varname></term>
        <listitem>
          <para>
            The following items are currently recognized.
          </para>
          <variablelist>
            <varlistentry>
              <term><varname>KDBUS_ITEM_CANCEL_FD</varname></term>
              <listitem>
                <para>
                  When this optional item is passed in, and the call is
                  executed as SYNC call, the passed in file descriptor can be
                  used as alternative cancellation point. The kernel will call
                  poll()
                  <citerefentry><refentrytitle>poll</refentrytitle><manvolnum>2</manvolnum></citerefentry>
                  on this file descriptor, and if it reports any incoming
                  bytes, the blocking send operation will be canceled, and the
                  call will return <varname>-ECANCELED</varname>. Any type of
                  file descriptor on which
                  <citerefentry><refentrytitle>poll</refentrytitle><manvolnum>2</manvolnum></citerefentry>
                  can be called on can be used as payload to this item.
                  For asynchronous message sending, this item is allowed but
                  ignored.
                </para>
              </listitem>
            </varlistentry>
          </variablelist>
          <para>
            All other items are rejected, and the ioctl will fail with -EINVAL.
          </para>
        </listitem>
      </varlistentry>
    </variablelist>

    <para>
      The fields in this struct are described below.
      The message referenced the <varname>msg_address</varname> above has
      the following layout.
    </para>

    <programlisting>
struct kdbus_msg {
  __u64 size;
  __u64 flags;
  __s64 priority;
  __u64 dst_id;
  __u64 src_id;
  __u64 payload_type;
  __u64 cookie;
  __u64 timeout_ns;
  __u64 cookie_reply;
  struct kdbus_item items[0];
};
    </programlisting>

    <para>The fields in this struct are described below.</para>

    <variablelist>
      <varlistentry>
        <term><varname>size</varname></term>
        <listitem><para>
          The overall size of the struct, including its items.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>flags</varname></term>
        <listitem><para>Flags to describe message details.</para>
          <variablelist>
            <varlistentry>
              <term><varname>KDBUS_MSG_EXPECT_REPLY</varname></term>
              <listitem>
                <para>
                  Expect a reply to this message from the remote peer. With this bit set,
                  the timeout_ns field must be set to a non-zero number of nanoseconds in
                  which the receiving peer is expected to reply. If such a reply is not
                  received in time, the sender will be notified with a timeout message
                  (see below). The value must be an absolute value, in nanoseconds and
                  based on <varname>CLOCK_MONOTONIC</varname>.
                </para><para>
                  For a message to be accepted as reply, it must be a direct message to
                  the original sender (not a broadcast), and its kdbus_msg.reply_cookie
                  must match the previous message's kdbus_msg.cookie.
                </para><para>
                  Expected replies also temporarily open the policy of the sending
                  connection, so the other peer is allowed to respond within the given
                  time window.
                </para>
              </listitem>
            </varlistentry>

            <varlistentry>
              <term><varname>KDBUS_MSG_NO_AUTO_START</varname></term>
              <listitem>
                <para>
                  By default, when a message is sent to an activator connection, the
                  activator is notified and will start an implementer. This flag inhibits
                  that behavior. With this bit set, and the remote being an activator,
                  <varname>-EADDRNOTAVAIL</varname> is returned from the ioctl.
                </para>
              </listitem>
            </varlistentry>
          </variablelist>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>priority</varname></term>
        <listitem><para>
          The priority of this message. Receiving messages (see below) may
          optionally be constrained to messages of a minimal priority. This
          allows for use cases where timing critical data is interleaved with
          control data on the same connection. If unused, the priority field
          should be set to zero.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>dst_id</varname></term>
        <listitem><para>
          The numeric ID of the destination connection, or
          <varname>KDBUS_DST_ID_BROADCAST</varname>
          (~0ULL) to address every peer on the bus, or
          <varname>KDBUS_DST_ID_NAME</varname> (0) to look
          it up dynamically from the bus' name registry.
          In the latter case, an item of type
          <varname>KDBUS_ITEM_DST_NAME</varname> is mandatory.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>src_id</varname></term>
        <listitem><para>
          Upon return of the ioctl, this member will contain the sending
          connection's numerical ID. Should be 0 at send time.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>payload_type</varname></term>
        <listitem><para>
          Type of the payload in the actual data records. Currently, only
          <varname>KDBUS_PAYLOAD_DBUS</varname> is accepted as input value
          of this field. When receiving messages that are generated by the
          kernel (notifications), this field will contain
          <varname>KDBUS_PAYLOAD_KERNEL</varname>.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>cookie</varname></term>
        <listitem><para>
          Cookie of this message, for later recognition. Also, when replying
          to a message (see above), the <varname>cookie_reply</varname>
          field must match this value.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>timeout_ns</varname></term>
        <listitem><para>
          If the message sent requires a reply from the remote peer (see above),
          this field contains the timeout in absolute nanoseconds based on
          <varname>CLOCK_MONOTONIC</varname>. Also see
          <citerefentry><refentrytitle>clock_gettime</refentrytitle><manvolnum>2</manvolnum></citerefentry>.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>cookie_reply</varname></term>
        <listitem><para>
          If the message sent is a reply to another message, this field must
          match the cookie of the formerly received message.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>items</varname></term>
        <listitem>
          <para>
            A dynamically sized list of items to contain additional information.
            The following items are expected/valid:
          </para>
          <variablelist>
            <varlistentry>
              <term><varname>KDBUS_ITEM_PAYLOAD_VEC</varname></term>
              <term><varname>KDBUS_ITEM_PAYLOAD_MEMFD</varname></term>
              <term><varname>KDBUS_ITEM_FDS</varname></term>
              <listitem>
                <para>
                  Actual data records containing the payload. See section
                  "Passing of Payload Data".
                </para>
              </listitem>
            </varlistentry>

            <varlistentry>
              <term><varname>KDBUS_ITEM_BLOOM_FILTER</varname></term>
              <listitem>
                <para>
                  Bloom filter for matches (see below).
                </para>
              </listitem>
            </varlistentry>

            <varlistentry>
              <term><varname>KDBUS_ITEM_DST_NAME</varname></term>
              <listitem>
                <para>
                  Well-known name to send this message to. Required if
                  <varname>dst_id</varname> is set to
                  <varname>KDBUS_DST_ID_NAME</varname>.
                  If a connection holding the given name can't be found,
                  <varname>-ESRCH</varname> is returned.
                </para>
                <para>
                  For messages to a unique name (ID), this item is optional. If present,
                  the kernel will make sure the name owner matches the given unique name.
                  This allows userspace tie the message sending to the condition that a
                  name is currently owned by a certain unique name.
                </para>
              </listitem>
            </varlistentry>
          </variablelist>
        </listitem>
      </varlistentry>
    </variablelist>

    <para>
      The message will be augmented by the requested metadata items when
      queued into the receiver's pool. See
      <citerefentry><refentrytitle>kdbus.connection</refentrytitle><manvolnum>7</manvolnum></citerefentry> and
      <citerefentry><refentrytitle>kdbus.item</refentrytitle><manvolnum>7</manvolnum></citerefentry>
      for more information on metadata.
    </para>
  </refsect1>

  <refsect1>
    <title>Message layout</title>

    <para>The layout of a message is shown below.</para>

    <programlisting>
  +-------------------------------------------------------------------------+
  | Message                                                                 |
  | +---------------------------------------------------------------------+ |
  | | Header                                                              | |
  | | size:          overall message size, including the data records     | |
  | | destination:   connection ID of the receiver                        | |
  | | source:        connection ID of the sender (set by kernel)          | |
  | | payload_type:  "DBusDBus" textual identifier stored as uint64_t     | |
  | +---------------------------------------------------------------------+ |
  | +---------------------------------------------------------------------+ |
  | | Data Record                                                         | |
  | | size:  overall record size (without padding)                        | |
  | | type:  type of data                                                 | |
  | | data:  reference to data (address or file descriptor)               | |
  | +---------------------------------------------------------------------+ |
  | +---------------------------------------------------------------------+ |
  | | padding bytes to the next 8 byte alignment                          | |
  | +---------------------------------------------------------------------+ |
  | +---------------------------------------------------------------------+ |
  | | Data Record                                                         | |
  | | size:  overall record size (without padding)                        | |
  | | ...                                                                 | |
  | +---------------------------------------------------------------------+ |
  | +---------------------------------------------------------------------+ |
  | | padding bytes to the next 8 byte alignment                          | |
  | +---------------------------------------------------------------------+ |
  | +---------------------------------------------------------------------+ |
  | | Data Record                                                         | |
  | | size:  overall record size                                          | |
  | | ...                                                                 | |
  | +---------------------------------------------------------------------+ |
  |   ... further data records ...                                          |
  +-------------------------------------------------------------------------+
    </programlisting>
  </refsect1>

  <refsect1>
    <title>Passing of Payload Data</title>

    <para>
      When connecting to the bus, receivers request a memory pool of a given size,
      large enough to carry all backlog of data enqueued for the connection. The
      pool is internally backed by a shared memory file which can be mmap()ed by
      the receiver.
    </para>
    <para>
      See
      <citerefentry><refentrytitle>kdbus.pool</refentrytitle><manvolnum>7</manvolnum></citerefentry>
      for more information.
    </para>

    <para>
      The following items are used to carry the actual data payload of a message.
    </para>

    <variablelist>
      <varlistentry>
        <term><varname>KDBUS_MSG_PAYLOAD_VEC</varname></term>
        <listitem>
          <para>
            Messages are directly copied by the sending process into the receiver's pool.
            This way, two peers can exchange data by effectively doing a single-copy from
            one process to another; the kernel will not buffer the data anywhere else.
          </para>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>KDBUS_MSG_PAYLOAD_MEMFD</varname></term>
        <listitem>
          <para>
            Messages can reference <emphasis>memfd</emphasis> files which contain the data.
            memfd files are tmpfs-backed files that allow sealing of the content of the
            file, which prevents all writable access to the file content.
          </para>
          <para>
            Only memfds that have
            <varname>(F_SEAL_SHRINK|F_SEAL_GROW|F_SEAL_WRITE|F_SEAL_SEAL)</varname>
            set are accepted as payload data, which enforces reliable passing of data.
            The receiver can assume that neither the sender nor anyone else can alter the
            content after the message is sent.
          </para>
          <para>
            Apart from the sender filling-in the content into memfd files, the data will
            be passed as zero-copy from one process to another, read-only, shared between
            the peers.
          </para>
        </listitem>
      </varlistentry>
    </variablelist>

    <para>
      The sender must not make any assumptions on the type in which data is received
      by the remote peer. The kernel is free to re-pack multiple VEC and MEMFD
      payloads. For instance, the kernel may decide to merge multiple VECs into a
      single VEC, inline MEMFD payloads into memory or merge all passed VECs into a
      single MEMFD. However, the kernel preserves the order of passed data. This
      means that the order of all VEC and MEMFD items is not changed in respect to
      each other.
    </para>
    <para>
      In other words: All passed VEC and MEMFD data payloads are treated as a single
      stream of data that may be received by the remote peer in a different set of
      hunks than it was sent as.
    </para>
  </refsect1>

  <refsect1>
    <title>Receiving messages</title>

    <para>
      Messages are received by the client with the KDBUS_CMD_RECV ioctl.
      The endpoint file of the bus supports <emphasis>poll/epoll/select</emphasis>
      to wake up the receiving process when new messages are queued up to be received.
    </para>

    <para>
      With the KDBUS_CMD_RECV ioctl, a <varname>struct kdbus_cmd_recv</varname> is used.
    </para>

    <programlisting>
struct kdbus_cmd_recv {
  __u64 size;
  __u64 flags;
  __u64 kernel_flags;
  __u64 return_flags;
  __s64 priority;
  __u64 dropped_msgs;
  struct kdbus_msg_info msg;
  struct kdbus_item items[0];
};
    </programlisting>

    <para>The fields in this struct are described below.</para>

    <variablelist>
      <varlistentry>
        <term><varname>size</varname></term>
        <listitem><para>
          The overall size of the struct, including its items.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>flags</varname></term>
        <listitem><para>Flags to control the receive command.</para>
          <variablelist>
            <varlistentry>
              <term><varname>KDBUS_RECV_PEEK</varname></term>
              <listitem>
                <para>
                  Just return the location of the next message. Do not install 
                  file descriptors or anything else. This is usually used to
                  determine the sender of the next queued message.
                </para>
              </listitem>
            </varlistentry>

            <varlistentry>
              <term><varname>KDBUS_RECV_DROP</varname></term>
              <listitem>
                <para>
                  Drop the next message without doing anything else with it,
                  and free the pool slice. This a short-cut for
                  <varname>KDBUS_RECV_PEEK</varname> and
                  <varname>KDBUS_CMD_FREE</varname>.
                </para>
              </listitem>
            </varlistentry>

            <varlistentry>
              <term><varname>KDBUS_RECV_USE_PRIORITY</varname></term>
              <listitem>
                <para>
                  Dequeue the messages ordered by their priority, and filtering
                  them with the priority field (see below).
                </para>
              </listitem>
            </varlistentry>
          </variablelist>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>kernel_flags</varname></term>
        <listitem><para>
          Valid flags for this command, returned by the kernel upon each call.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>return_flags</varname></term>
        <listitem><para>
          Flags returned by the kernel. Currently unused and always set to
          zero by the kernel.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>priority</varname></term>
        <listitem><para>
          With <varname>KDBUS_RECV_USE_PRIORITY</varname> set in
          <varname>flags</varname>, messages will be dequeued ordered by their
          priority, starting with the highest value. Also, messages will be
          filtered by the value given in this field, so the returned message
          will at least have the requested priority. If no such message is
          waiting in the queue, <varname>-ENOMSG</varname> is returned.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>dropped_msgs</varname></term>
        <listitem><para>
          If the <varname>CMD_RECV</varname> ioctl fails with 
          <varname>-EOVERFLOW</varname>, this field is filled by
          the kernel with the number of messages that couldn't be transmitted
          to this receiving connection. In that case, the
          <varname>offset</varname> member must not be accessed.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>msg</varname></term>
        <listitem><para>
          Embedded struct containing information on the received message when
          this command succeeded (see below).
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>items</varname></term>
        <listitem><para>
          Items to specify further details for the receive command.
          Currently unused, and all items will be rejected with
          <varname>-EINVAL</varname>,
        </para></listitem>
      </varlistentry>
    </variablelist>

    <para>
      Both <varname>struct kdbus_cmd_recv</varname> and 
      <varname>struct kdbus_cmd_send</varname> embed 
      <varname>struct kdbus_msg_info</varname>.
      For the <varname>KDBUS_CMD_SEND</varname> ioctl, it is used to catch
      synchronous replies, if one was requested, and is unused otherwise.
    </para>

    <programlisting>
struct kdbus_msg_info {
  __u64 offset;
  __u64 msg_size;
  __u64 return_flags;
};
    </programlisting>

    <para>The fields in this struct are described below.</para>

    <variablelist>
      <varlistentry>
        <term><varname>offset</varname></term>
        <listitem><para>
          Upon return of the ioctl, this field contains the offset in the receiver's
          memory pool. The memory must be freed with
          <varname>KDBUS_CMD_FREE</varname>. See
          <citerefentry><refentrytitle>kdbus.pool</refentrytitle><manvolnum>7</manvolnum></citerefentry>
          for further details.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>msg_size</varname></term>
        <listitem><para>
          Upon successful return of the ioctl, this field contains the size of the
          allocated slice at offset <varname>offset</varname>.
          It is the combination of the size of the stored
          <varname>struct kdbus_msg</varname> object plus all appended VECs.
          You can use it in combination with <varname>offset</varname> to map
          a single message, instead of mapping the entire pool. See
          <citerefentry><refentrytitle>kdbus.pool</refentrytitle><manvolnum>7</manvolnum></citerefentry>
          for further details.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>return_flags</varname></term>
        <listitem>
          <para>
            Kernel-provided return flags. Currently, the following flags are defined.
          </para>
          <variablelist>
            <varlistentry>
              <term><varname>KDBUS_RECV_RETURN_INCOMPLETE_FDS</varname></term>
              <listitem>
                <para>
                  The message contained file descriptors which couldn't be installed
                  into the receiver's task. Most probably that happened because the
                  maximum number of file descriptors for that task were exceeded.
                  The message is still delivered, so this is not a fatal condition.
                  File descriptors inside the <varname>KDBUS_ITEM_FDS</varname>
                  item that could not be installed will be set to -1.
                </para>
              </listitem>
            </varlistentry>
          </variablelist>
        </listitem>
      </varlistentry>
    </variablelist>

    <para>
      Unless <varname>KDBUS_RECV_DROP</varname> was passed after a successful+
      <varname>KDBUS_CMD_RECV</varname> ioctl, the <varname>offset</varname>
      field contains the location of the new message inside the receiver's
      pool. The message is stored as <varname>struct kdbus_msg</varname> at
      this offset, and can be interpreted with the semantics described above.
    </para>
    <para>
      Also, if the connection allowed for file descriptor to be passed
      (<varname>KDBUS_HELLO_ACCEPT_FD</varname>), and if the message contained
      any, they will be installed into the receiving process when the
      <varname>KDBUS_CMD_RECV</varname> ioctl is called.
      The receiving task is obliged to close all of them appropriately. If
      <varname>KDBUS_RECV_PEEK</varname> is set, no file descriptors are
      installed. This allows for peeking at a message and dropping it via
      <varname>KDBUS_RECV_DROP</varname>, without installing the passed file
      descriptors into the receiving process.
    </para>
    <para>
      The caller is obliged to call the <varname>KDBUS_CMD_FREE</varname>
      ioctl with the returned offset when the memory is no longer needed.
    </para>
  </refsect1>

  <refsect1>
    <title>Notifications</title>
    <para>
      A kernel notification is a regular kdbus message with the following
      details.
    </para>

    <itemizedlist mark='opencircle'>
      <listitem><para>kdbus_msg.src_id == <varname>KDBUS_SRC_ID_KERNEL</varname></para></listitem>
      <listitem><para>kdbus_msg.dst_id == <varname>KDBUS_DST_ID_BROADCAST</varname></para></listitem>
      <listitem><para>kdbus_msg.payload_type == <varname>KDBUS_PAYLOAD_KERNEL</varname></para></listitem>
      <listitem><para>Has exactly one of the aforementioned items attached</para></listitem>
    </itemizedlist>

    <para>
      Kernel notifications have an item of type KDBUS_ITEM_TIMESTAMP attached.
    </para>

    <para>
      The kernel will notify its users of the following events.
    </para>

    <itemizedlist mark='opencircle'>
      <listitem><para>
        When connection A is terminated while connection B is waiting for a
        reply from it, connection B is notified with a message with an item of
        type <varname>KDBUS_ITEM_REPLY_DEAD</varname>.
      </para></listitem>

      <listitem><para>
        When connection A does not receive a reply from connection B within the
        specified timeout window, connection A will receive a message with an
        item of type <varname>KDBUS_ITEM_REPLY_TIMEOUT</varname>.
      </para></listitem>

      <listitem><para>
        When an ordinary connection (not a monitor) is created on or removed
        from a bus, messages with an item of type
        <varname>KDBUS_ITEM_ID_ADD</varname> or
        <varname>KDBUS_ITEM_ID_REMOVE</varname>, respectively, are delivered
        to all bus members that match these messages through their match
        database. Eavesdroppers (monitor connections) do not cause such
        notifications to be sent. They are invisible on the bus.
      </para></listitem>

      <listitem><para>
        When a connection gains or loses ownership of a name, messages with an
        item of type <varname>KDBUS_ITEM_NAME_ADD</varname>,
        <varname>KDBUS_ITEM_NAME_REMOVE</varname> or
        <varname>KDBUS_ITEM_NAME_CHANGE</varname> are delivered to all bus
        members that match these messages through their match database.
      </para></listitem>
    </itemizedlist>
  </refsect1>

  <refsect1>
    <title>Return value</title>
    <para>
      On success, all metioned ioctl commands return 0.
    </para>

    <refsect2>
      <title><varname>KDBUS_CMD_SEND</varname> may return the following errors</title>

      <variablelist>
        <varlistentry>
          <term><varname>-EOPNOTSUPP</varname></term>
          <listitem><para>
            The connection is not an ordinary connection, or the passed
            file descriptors are either kdbus handles or unix domain
            sockets. Both are currently unsupported.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><varname>-EINVAL</varname></term>
          <listitem><para>
            The submitted payload type is <varname>KDBUS_PAYLOAD_KERNEL</varname>,
            <varname>KDBUS_MSG_EXPECT_REPLY</varname> was set without timeout or
            cookie values, <varname>KDBUS_SEND_SYNC_REPLY</varname> was set
            without <varname>KDBUS_MSG_EXPECT_REPLY</varname>, an invalid item
            was supplied, <varname>src_id</varname> was non-zero and was
            different from the current connection's ID, a supplied memfd had a
            size of 0, or a string was not properly null-terminated.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><varname>-ENOTUNIQ</varname></term>
          <listitem><para>
            The supplied destination is <varname>KDBUS_DST_ID_BROADCAST</varname>,
            a file descriptor was passed, <varname>KDBUS_MSG_EXPECT_REPLY</varname>
            was set, or a timeout was given for a broadcast message.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><varname>-E2BIG</varname></term>
          <listitem><para>
            Too many items
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><varname>-EMSGSIZE</varname></term>
          <listitem><para>
            The size of the message header and items or the payload vector
            is excessive.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><varname>-EEXIST</varname></term>
          <listitem><para>
            Multiple <varname>KDBUS_ITEM_FDS</varname>,
            <varname>KDBUS_ITEM_BLOOM_FILTER</varname> or
            <varname>KDBUS_ITEM_DST_NAME</varname> items were supplied.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><varname>-EBADF</varname></term>
          <listitem><para>
            The supplied <varname>KDBUS_ITEM_FDS</varname> or
            <varname>KDBUS_ITEM_PAYLOAD_MEMFD</varname> items
            contained an illegal file descriptor.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><varname>-EMEDIUMTYPE</varname></term>
          <listitem><para>
            The supplied memfd is not a sealed kdbus memfd.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><varname>-EMFILE</varname></term>
          <listitem><para>
            Too many file descriptors inside a <varname>KDBUS_ITEM_FDS</varname>.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><varname>-EBADMSG</varname></term>
          <listitem><para>
            An item had illegal size, both a <varname>dst_id</varname> and a
            <varname>KDBUS_ITEM_DST_NAME</varname> was given, or both a name
            and a bloom filter was given.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><varname>-ETXTBSY</varname></term>
          <listitem><para>
            The supplied kdbus memfd file cannot be sealed or the seal
            was removed, because it is shared with other processes or
            still mapped with
            <citerefentry><refentrytitle>mmap</refentrytitle><manvolnum>2</manvolnum></citerefentry>.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><varname>-ECOMM</varname></term>
          <listitem><para>
            A peer does not accept the file descriptors addressed to it.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><varname>-EFAULT</varname></term>
          <listitem><para>
            The supplied bloom filter size was not 64-bit aligned or memory
            supplied by userspace could not be accessed by the kernel.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><varname>-EDOM</varname></term>
          <listitem><para>
            The supplied bloom filter size did not match the bloom filter
            size of the bus.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><varname>-EDESTADDRREQ</varname></term>
          <listitem><para>
            <varname>dst_id</varname> was set to
            <varname>KDBUS_DST_ID_NAME</varname>, but no
            <varname>KDBUS_ITEM_DST_NAME</varname> was attached.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><varname>-ESRCH</varname></term>
          <listitem><para>
            The name to look up was not found in the name registry.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><varname>-EADDRNOTAVAIL</varname></term>
          <listitem><para>
            <varname>KDBUS_MSG_NO_AUTO_START</varname> was given but the
            destination connection is an activator.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><varname>-ENXIO</varname></term>
          <listitem><para>
            The passed numeric destination connection ID couldn't be found,
            or is not connected.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><varname>-ECONNRESET</varname></term>
          <listitem><para>
            The destination connection is no longer active.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><varname>-ETIMEDOUT</varname></term>
          <listitem><para>
            Timeout while synchronously waiting for a reply.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><varname>-EINTR</varname></term>
          <listitem><para>
            Interrupted system call  while synchronously waiting for a reply.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><varname>-EPIPE</varname></term>
          <listitem><para>
            When sending a message, a synchronous reply from the receiving
            connection was expected but the connection died before answering.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><varname>-ENOBUFS</varname></term>
          <listitem><para>
            Too many pending messages on the receiver side.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><varname>-EREMCHG</varname></term>
          <listitem><para>
            Both a well-known name and a unique name (ID) was given, but
            the name is not currently owned by that connection.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><varname>-EXFULL</varname></term>
          <listitem><para>
            The memory pool of the receiver is full.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><varname>-EREMOTEIO</varname></term>
          <listitem><para>
            While synchronously waiting for a reply, the remote peer
            failed with an I/O error.
          </para></listitem>
        </varlistentry>
      </variablelist>
    </refsect2>

    <refsect2>
      <title><varname>KDBUS_CMD_RECV</varname> may return the following errors</title>

      <variablelist>
        <varlistentry>
          <term><varname>-EOPNOTSUPP</varname></term>
          <listitem><para>
            The connection is not an ordinary connection, or the passed
            file descriptors are either kdbus handles or unix domain
            sockets. Both are currently unsupported.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><varname>-EINVAL</varname></term>
          <listitem><para>
            Invalid flags or offset.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><varname>-EAGAIN</varname></term>
          <listitem><para>
            No message found in the queue
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><varname>-ENOMSG</varname></term>
          <listitem><para>
            No message of the requested priority found.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><varname>-EOVERFLOW</varname></term>
          <listitem><para>
            Some messages have been lost.
          </para></listitem>
        </varlistentry>
      </variablelist>
    </refsect2>
  </refsect1>

  <refsect1>
    <title>See Also</title>
    <simplelist type="inline">
      <member><citerefentry><refentrytitle>kdbus</refentrytitle><manvolnum>7</manvolnum></citerefentry></member>
      <member><citerefentry><refentrytitle>kdbus.bus</refentrytitle><manvolnum>7</manvolnum></citerefentry></member>
      <member><citerefentry><refentrytitle>kdbus.connection</refentrytitle><manvolnum>7</manvolnum></citerefentry></member>
      <member><citerefentry><refentrytitle>kdbus.endpoint</refentrytitle><manvolnum>7</manvolnum></citerefentry></member>
      <member><citerefentry><refentrytitle>kdbus.fs</refentrytitle><manvolnum>7</manvolnum></citerefentry></member>
      <member><citerefentry><refentrytitle>kdbus.items</refentrytitle><manvolnum>7</manvolnum></citerefentry></member>
      <member><citerefentry><refentrytitle>kdbus.message</refentrytitle><manvolnum>7</manvolnum></citerefentry></member>
      <member><citerefentry><refentrytitle>kdbus.names</refentrytitle><manvolnum>7</manvolnum></citerefentry></member>
      <member><citerefentry><refentrytitle>kdbus.pool</refentrytitle><manvolnum>7</manvolnum></citerefentry></member>
      <member><citerefentry><refentrytitle>clock_gettime</refentrytitle><manvolnum>2</manvolnum></citerefentry></member>
      <member><citerefentry><refentrytitle>ioctl</refentrytitle><manvolnum>2</manvolnum></citerefentry></member>
      <member><citerefentry><refentrytitle>poll</refentrytitle><manvolnum>2</manvolnum></citerefentry></member>
      <member><citerefentry><refentrytitle>select</refentrytitle><manvolnum>2</manvolnum></citerefentry></member>
      <member><citerefentry><refentrytitle>epoll</refentrytitle><manvolnum>7</manvolnum></citerefentry></member>
    </simplelist>
  </refsect1>
</refentry>