/src/systemd/src/libsystemd/sd-bus/bus-message.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* SPDX-License-Identifier: LGPL-2.1+ */ |
2 | | #pragma once |
3 | | |
4 | | #include <byteswap.h> |
5 | | #include <stdbool.h> |
6 | | #include <sys/socket.h> |
7 | | |
8 | | #include "sd-bus.h" |
9 | | |
10 | | #include "bus-creds.h" |
11 | | #include "bus-protocol.h" |
12 | | #include "macro.h" |
13 | | #include "time-util.h" |
14 | | |
15 | | struct bus_container { |
16 | | char enclosing; |
17 | | bool need_offsets:1; |
18 | | |
19 | | /* Indexes into the signature string */ |
20 | | unsigned index, saved_index; |
21 | | char *signature; |
22 | | |
23 | | size_t before, begin, end; |
24 | | |
25 | | /* dbus1: pointer to the array size value, if this is a value */ |
26 | | uint32_t *array_size; |
27 | | |
28 | | /* gvariant: list of offsets to end of children if this is struct/dict entry/array */ |
29 | | size_t *offsets, n_offsets, offsets_allocated, offset_index; |
30 | | size_t item_size; |
31 | | |
32 | | char *peeked_signature; |
33 | | }; |
34 | | |
35 | | struct bus_body_part { |
36 | | struct bus_body_part *next; |
37 | | void *data; |
38 | | void *mmap_begin; |
39 | | size_t size; |
40 | | size_t mapped; |
41 | | size_t allocated; |
42 | | uint64_t memfd_offset; |
43 | | int memfd; |
44 | | bool free_this:1; |
45 | | bool munmap_this:1; |
46 | | bool sealed:1; |
47 | | bool is_zero:1; |
48 | | }; |
49 | | |
50 | | struct sd_bus_message { |
51 | | /* Caveat: a message can be referenced in two different ways: the main (user-facing) way will also |
52 | | * pin the bus connection object the message is associated with. The secondary way ("queued") is used |
53 | | * when a message is in the read or write queues of the bus connection object, which will not pin the |
54 | | * bus connection object. This is necessary so that we don't have to have a pair of cyclic references |
55 | | * between a message that is queued and its connection: as soon as a message is only referenced by |
56 | | * the connection (by means of being queued) and the connection itself has no other references it |
57 | | * will be freed. */ |
58 | | |
59 | | unsigned n_ref; /* Counter of references that pin the connection */ |
60 | | unsigned n_queued; /* Counter of references that do not pin the connection */ |
61 | | |
62 | | sd_bus *bus; |
63 | | |
64 | | uint64_t reply_cookie; |
65 | | |
66 | | const char *path; |
67 | | const char *interface; |
68 | | const char *member; |
69 | | const char *destination; |
70 | | const char *sender; |
71 | | |
72 | | sd_bus_error error; |
73 | | |
74 | | sd_bus_creds creds; |
75 | | |
76 | | usec_t monotonic; |
77 | | usec_t realtime; |
78 | | uint64_t seqnum; |
79 | | int64_t priority; |
80 | | uint64_t verify_destination_id; |
81 | | |
82 | | bool sealed:1; |
83 | | bool dont_send:1; |
84 | | bool allow_fds:1; |
85 | | bool free_header:1; |
86 | | bool free_fds:1; |
87 | | bool poisoned:1; |
88 | | |
89 | | /* The first and last bytes of the message */ |
90 | | struct bus_header *header; |
91 | | void *footer; |
92 | | |
93 | | /* How many bytes are accessible in the above pointers */ |
94 | | size_t header_accessible; |
95 | | size_t footer_accessible; |
96 | | |
97 | | size_t fields_size; |
98 | | size_t body_size; |
99 | | size_t user_body_size; |
100 | | |
101 | | struct bus_body_part body; |
102 | | struct bus_body_part *body_end; |
103 | | unsigned n_body_parts; |
104 | | |
105 | | size_t rindex; |
106 | | struct bus_body_part *cached_rindex_part; |
107 | | size_t cached_rindex_part_begin; |
108 | | |
109 | | uint32_t n_fds; |
110 | | int *fds; |
111 | | |
112 | | struct bus_container root_container, *containers; |
113 | | size_t n_containers; |
114 | | size_t containers_allocated; |
115 | | |
116 | | struct iovec *iovec; |
117 | | struct iovec iovec_fixed[2]; |
118 | | unsigned n_iovec; |
119 | | |
120 | | char *peeked_signature; |
121 | | |
122 | | /* If set replies to this message must carry the signature |
123 | | * specified here to successfully seal. This is initialized |
124 | | * from the vtable data */ |
125 | | const char *enforced_reply_signature; |
126 | | |
127 | | usec_t timeout; |
128 | | |
129 | | size_t header_offsets[_BUS_MESSAGE_HEADER_MAX]; |
130 | | unsigned n_header_offsets; |
131 | | }; |
132 | | |
133 | 61.8k | static inline bool BUS_MESSAGE_NEED_BSWAP(sd_bus_message *m) { |
134 | 61.8k | return m->header->endian != BUS_NATIVE_ENDIAN; |
135 | 61.8k | } Unexecuted instantiation: fuzz-bus-message.c:BUS_MESSAGE_NEED_BSWAP Unexecuted instantiation: bus-util.c:BUS_MESSAGE_NEED_BSWAP Unexecuted instantiation: bus-control.c:BUS_MESSAGE_NEED_BSWAP Unexecuted instantiation: bus-convenience.c:BUS_MESSAGE_NEED_BSWAP Unexecuted instantiation: bus-creds.c:BUS_MESSAGE_NEED_BSWAP bus-dump.c:BUS_MESSAGE_NEED_BSWAP Line | Count | Source | 133 | 4.76k | static inline bool BUS_MESSAGE_NEED_BSWAP(sd_bus_message *m) { | 134 | 4.76k | return m->header->endian != BUS_NATIVE_ENDIAN; | 135 | 4.76k | } |
Unexecuted instantiation: bus-internal.c:BUS_MESSAGE_NEED_BSWAP Unexecuted instantiation: bus-kernel.c:BUS_MESSAGE_NEED_BSWAP Unexecuted instantiation: bus-match.c:BUS_MESSAGE_NEED_BSWAP bus-message.c:BUS_MESSAGE_NEED_BSWAP Line | Count | Source | 133 | 57.0k | static inline bool BUS_MESSAGE_NEED_BSWAP(sd_bus_message *m) { | 134 | 57.0k | return m->header->endian != BUS_NATIVE_ENDIAN; | 135 | 57.0k | } |
Unexecuted instantiation: bus-objects.c:BUS_MESSAGE_NEED_BSWAP Unexecuted instantiation: bus-socket.c:BUS_MESSAGE_NEED_BSWAP Unexecuted instantiation: sd-bus.c:BUS_MESSAGE_NEED_BSWAP |
136 | | |
137 | 3.88k | static inline uint16_t BUS_MESSAGE_BSWAP16(sd_bus_message *m, uint16_t u) { |
138 | 3.88k | return BUS_MESSAGE_NEED_BSWAP(m) ? bswap_16(u) : u; |
139 | 3.88k | } Unexecuted instantiation: fuzz-bus-message.c:BUS_MESSAGE_BSWAP16 Unexecuted instantiation: bus-util.c:BUS_MESSAGE_BSWAP16 Unexecuted instantiation: bus-control.c:BUS_MESSAGE_BSWAP16 Unexecuted instantiation: bus-convenience.c:BUS_MESSAGE_BSWAP16 Unexecuted instantiation: bus-creds.c:BUS_MESSAGE_BSWAP16 Unexecuted instantiation: bus-dump.c:BUS_MESSAGE_BSWAP16 Unexecuted instantiation: bus-internal.c:BUS_MESSAGE_BSWAP16 Unexecuted instantiation: bus-kernel.c:BUS_MESSAGE_BSWAP16 Unexecuted instantiation: bus-match.c:BUS_MESSAGE_BSWAP16 bus-message.c:BUS_MESSAGE_BSWAP16 Line | Count | Source | 137 | 3.88k | static inline uint16_t BUS_MESSAGE_BSWAP16(sd_bus_message *m, uint16_t u) { | 138 | 3.88k | return BUS_MESSAGE_NEED_BSWAP(m) ? bswap_16(u) : u; | 139 | 3.88k | } |
Unexecuted instantiation: bus-objects.c:BUS_MESSAGE_BSWAP16 Unexecuted instantiation: bus-socket.c:BUS_MESSAGE_BSWAP16 Unexecuted instantiation: sd-bus.c:BUS_MESSAGE_BSWAP16 |
140 | | |
141 | 33.4k | static inline uint32_t BUS_MESSAGE_BSWAP32(sd_bus_message *m, uint32_t u) { |
142 | 33.4k | return BUS_MESSAGE_NEED_BSWAP(m) ? bswap_32(u) : u; |
143 | 33.4k | } Unexecuted instantiation: fuzz-bus-message.c:BUS_MESSAGE_BSWAP32 Unexecuted instantiation: bus-util.c:BUS_MESSAGE_BSWAP32 Unexecuted instantiation: bus-control.c:BUS_MESSAGE_BSWAP32 Unexecuted instantiation: bus-convenience.c:BUS_MESSAGE_BSWAP32 Unexecuted instantiation: bus-creds.c:BUS_MESSAGE_BSWAP32 bus-dump.c:BUS_MESSAGE_BSWAP32 Line | Count | Source | 141 | 1.32k | static inline uint32_t BUS_MESSAGE_BSWAP32(sd_bus_message *m, uint32_t u) { | 142 | 1.32k | return BUS_MESSAGE_NEED_BSWAP(m) ? bswap_32(u) : u; | 143 | 1.32k | } |
Unexecuted instantiation: bus-internal.c:BUS_MESSAGE_BSWAP32 Unexecuted instantiation: bus-kernel.c:BUS_MESSAGE_BSWAP32 Unexecuted instantiation: bus-match.c:BUS_MESSAGE_BSWAP32 bus-message.c:BUS_MESSAGE_BSWAP32 Line | Count | Source | 141 | 32.0k | static inline uint32_t BUS_MESSAGE_BSWAP32(sd_bus_message *m, uint32_t u) { | 142 | 32.0k | return BUS_MESSAGE_NEED_BSWAP(m) ? bswap_32(u) : u; | 143 | 32.0k | } |
Unexecuted instantiation: bus-objects.c:BUS_MESSAGE_BSWAP32 Unexecuted instantiation: bus-socket.c:BUS_MESSAGE_BSWAP32 Unexecuted instantiation: sd-bus.c:BUS_MESSAGE_BSWAP32 |
144 | | |
145 | 24.5k | static inline uint64_t BUS_MESSAGE_BSWAP64(sd_bus_message *m, uint64_t u) { |
146 | 24.5k | return BUS_MESSAGE_NEED_BSWAP(m) ? bswap_64(u) : u; |
147 | 24.5k | } Unexecuted instantiation: fuzz-bus-message.c:BUS_MESSAGE_BSWAP64 Unexecuted instantiation: bus-util.c:BUS_MESSAGE_BSWAP64 Unexecuted instantiation: bus-control.c:BUS_MESSAGE_BSWAP64 Unexecuted instantiation: bus-convenience.c:BUS_MESSAGE_BSWAP64 Unexecuted instantiation: bus-creds.c:BUS_MESSAGE_BSWAP64 bus-dump.c:BUS_MESSAGE_BSWAP64 Line | Count | Source | 145 | 3.44k | static inline uint64_t BUS_MESSAGE_BSWAP64(sd_bus_message *m, uint64_t u) { | 146 | 3.44k | return BUS_MESSAGE_NEED_BSWAP(m) ? bswap_64(u) : u; | 147 | 3.44k | } |
Unexecuted instantiation: bus-internal.c:BUS_MESSAGE_BSWAP64 Unexecuted instantiation: bus-kernel.c:BUS_MESSAGE_BSWAP64 Unexecuted instantiation: bus-match.c:BUS_MESSAGE_BSWAP64 bus-message.c:BUS_MESSAGE_BSWAP64 Line | Count | Source | 145 | 21.0k | static inline uint64_t BUS_MESSAGE_BSWAP64(sd_bus_message *m, uint64_t u) { | 146 | 21.0k | return BUS_MESSAGE_NEED_BSWAP(m) ? bswap_64(u) : u; | 147 | 21.0k | } |
Unexecuted instantiation: bus-objects.c:BUS_MESSAGE_BSWAP64 Unexecuted instantiation: bus-socket.c:BUS_MESSAGE_BSWAP64 Unexecuted instantiation: sd-bus.c:BUS_MESSAGE_BSWAP64 |
148 | | |
149 | 4.76k | static inline uint64_t BUS_MESSAGE_COOKIE(sd_bus_message *m) { |
150 | 4.76k | if (m->header->version == 2) |
151 | 3.44k | return BUS_MESSAGE_BSWAP64(m, m->header->dbus2.cookie); |
152 | 1.32k | |
153 | 1.32k | return BUS_MESSAGE_BSWAP32(m, m->header->dbus1.serial); |
154 | 1.32k | } Unexecuted instantiation: fuzz-bus-message.c:BUS_MESSAGE_COOKIE Unexecuted instantiation: bus-util.c:BUS_MESSAGE_COOKIE Unexecuted instantiation: bus-control.c:BUS_MESSAGE_COOKIE Unexecuted instantiation: bus-convenience.c:BUS_MESSAGE_COOKIE Unexecuted instantiation: bus-creds.c:BUS_MESSAGE_COOKIE bus-dump.c:BUS_MESSAGE_COOKIE Line | Count | Source | 149 | 4.76k | static inline uint64_t BUS_MESSAGE_COOKIE(sd_bus_message *m) { | 150 | 4.76k | if (m->header->version == 2) | 151 | 3.44k | return BUS_MESSAGE_BSWAP64(m, m->header->dbus2.cookie); | 152 | 1.32k | | 153 | 1.32k | return BUS_MESSAGE_BSWAP32(m, m->header->dbus1.serial); | 154 | 1.32k | } |
Unexecuted instantiation: bus-internal.c:BUS_MESSAGE_COOKIE Unexecuted instantiation: bus-kernel.c:BUS_MESSAGE_COOKIE Unexecuted instantiation: bus-match.c:BUS_MESSAGE_COOKIE Unexecuted instantiation: bus-message.c:BUS_MESSAGE_COOKIE Unexecuted instantiation: bus-objects.c:BUS_MESSAGE_COOKIE Unexecuted instantiation: bus-socket.c:BUS_MESSAGE_COOKIE Unexecuted instantiation: sd-bus.c:BUS_MESSAGE_COOKIE |
155 | | |
156 | 2.67k | static inline size_t BUS_MESSAGE_SIZE(sd_bus_message *m) { |
157 | 2.67k | return |
158 | 2.67k | sizeof(struct bus_header) + |
159 | 2.67k | ALIGN8(m->fields_size) + |
160 | 2.67k | m->body_size; |
161 | 2.67k | } Unexecuted instantiation: fuzz-bus-message.c:BUS_MESSAGE_SIZE Unexecuted instantiation: bus-util.c:BUS_MESSAGE_SIZE Unexecuted instantiation: bus-control.c:BUS_MESSAGE_SIZE Unexecuted instantiation: bus-convenience.c:BUS_MESSAGE_SIZE Unexecuted instantiation: bus-creds.c:BUS_MESSAGE_SIZE Unexecuted instantiation: bus-dump.c:BUS_MESSAGE_SIZE Unexecuted instantiation: bus-internal.c:BUS_MESSAGE_SIZE Unexecuted instantiation: bus-kernel.c:BUS_MESSAGE_SIZE Unexecuted instantiation: bus-match.c:BUS_MESSAGE_SIZE bus-message.c:BUS_MESSAGE_SIZE Line | Count | Source | 156 | 2.67k | static inline size_t BUS_MESSAGE_SIZE(sd_bus_message *m) { | 157 | 2.67k | return | 158 | 2.67k | sizeof(struct bus_header) + | 159 | 2.67k | ALIGN8(m->fields_size) + | 160 | 2.67k | m->body_size; | 161 | 2.67k | } |
Unexecuted instantiation: bus-objects.c:BUS_MESSAGE_SIZE Unexecuted instantiation: bus-socket.c:BUS_MESSAGE_SIZE Unexecuted instantiation: sd-bus.c:BUS_MESSAGE_SIZE |
162 | | |
163 | 0 | static inline size_t BUS_MESSAGE_BODY_BEGIN(sd_bus_message *m) { |
164 | 0 | return |
165 | 0 | sizeof(struct bus_header) + |
166 | 0 | ALIGN8(m->fields_size); |
167 | 0 | } Unexecuted instantiation: fuzz-bus-message.c:BUS_MESSAGE_BODY_BEGIN Unexecuted instantiation: bus-util.c:BUS_MESSAGE_BODY_BEGIN Unexecuted instantiation: bus-control.c:BUS_MESSAGE_BODY_BEGIN Unexecuted instantiation: bus-convenience.c:BUS_MESSAGE_BODY_BEGIN Unexecuted instantiation: bus-creds.c:BUS_MESSAGE_BODY_BEGIN Unexecuted instantiation: bus-dump.c:BUS_MESSAGE_BODY_BEGIN Unexecuted instantiation: bus-internal.c:BUS_MESSAGE_BODY_BEGIN Unexecuted instantiation: bus-kernel.c:BUS_MESSAGE_BODY_BEGIN Unexecuted instantiation: bus-match.c:BUS_MESSAGE_BODY_BEGIN Unexecuted instantiation: bus-message.c:BUS_MESSAGE_BODY_BEGIN Unexecuted instantiation: bus-objects.c:BUS_MESSAGE_BODY_BEGIN Unexecuted instantiation: bus-socket.c:BUS_MESSAGE_BODY_BEGIN Unexecuted instantiation: sd-bus.c:BUS_MESSAGE_BODY_BEGIN |
168 | | |
169 | 23.1k | static inline void* BUS_MESSAGE_FIELDS(sd_bus_message *m) { |
170 | 23.1k | return (uint8_t*) m->header + sizeof(struct bus_header); |
171 | 23.1k | } Unexecuted instantiation: fuzz-bus-message.c:BUS_MESSAGE_FIELDS Unexecuted instantiation: bus-util.c:BUS_MESSAGE_FIELDS Unexecuted instantiation: bus-control.c:BUS_MESSAGE_FIELDS Unexecuted instantiation: bus-convenience.c:BUS_MESSAGE_FIELDS Unexecuted instantiation: bus-creds.c:BUS_MESSAGE_FIELDS Unexecuted instantiation: bus-dump.c:BUS_MESSAGE_FIELDS Unexecuted instantiation: bus-internal.c:BUS_MESSAGE_FIELDS Unexecuted instantiation: bus-kernel.c:BUS_MESSAGE_FIELDS Unexecuted instantiation: bus-match.c:BUS_MESSAGE_FIELDS bus-message.c:BUS_MESSAGE_FIELDS Line | Count | Source | 169 | 23.1k | static inline void* BUS_MESSAGE_FIELDS(sd_bus_message *m) { | 170 | 23.1k | return (uint8_t*) m->header + sizeof(struct bus_header); | 171 | 23.1k | } |
Unexecuted instantiation: bus-objects.c:BUS_MESSAGE_FIELDS Unexecuted instantiation: bus-socket.c:BUS_MESSAGE_FIELDS Unexecuted instantiation: sd-bus.c:BUS_MESSAGE_FIELDS |
172 | | |
173 | 9.64M | static inline bool BUS_MESSAGE_IS_GVARIANT(sd_bus_message *m) { |
174 | 9.64M | return m->header->version == 2; |
175 | 9.64M | } Unexecuted instantiation: fuzz-bus-message.c:BUS_MESSAGE_IS_GVARIANT Unexecuted instantiation: bus-util.c:BUS_MESSAGE_IS_GVARIANT Unexecuted instantiation: bus-control.c:BUS_MESSAGE_IS_GVARIANT Unexecuted instantiation: bus-convenience.c:BUS_MESSAGE_IS_GVARIANT Unexecuted instantiation: bus-creds.c:BUS_MESSAGE_IS_GVARIANT Unexecuted instantiation: bus-dump.c:BUS_MESSAGE_IS_GVARIANT Unexecuted instantiation: bus-internal.c:BUS_MESSAGE_IS_GVARIANT Unexecuted instantiation: bus-kernel.c:BUS_MESSAGE_IS_GVARIANT Unexecuted instantiation: bus-match.c:BUS_MESSAGE_IS_GVARIANT bus-message.c:BUS_MESSAGE_IS_GVARIANT Line | Count | Source | 173 | 9.64M | static inline bool BUS_MESSAGE_IS_GVARIANT(sd_bus_message *m) { | 174 | 9.64M | return m->header->version == 2; | 175 | 9.64M | } |
Unexecuted instantiation: bus-objects.c:BUS_MESSAGE_IS_GVARIANT Unexecuted instantiation: bus-socket.c:BUS_MESSAGE_IS_GVARIANT Unexecuted instantiation: sd-bus.c:BUS_MESSAGE_IS_GVARIANT |
176 | | |
177 | | int bus_message_get_blob(sd_bus_message *m, void **buffer, size_t *sz); |
178 | | int bus_message_read_strv_extend(sd_bus_message *m, char ***l); |
179 | | |
180 | | int bus_message_from_header( |
181 | | sd_bus *bus, |
182 | | void *header, |
183 | | size_t header_accessible, |
184 | | void *footer, |
185 | | size_t footer_accessible, |
186 | | size_t message_size, |
187 | | int *fds, |
188 | | size_t n_fds, |
189 | | const char *label, |
190 | | size_t extra, |
191 | | sd_bus_message **ret); |
192 | | |
193 | | int bus_message_from_malloc( |
194 | | sd_bus *bus, |
195 | | void *buffer, |
196 | | size_t length, |
197 | | int *fds, |
198 | | size_t n_fds, |
199 | | const char *label, |
200 | | sd_bus_message **ret); |
201 | | |
202 | | int bus_message_get_arg(sd_bus_message *m, unsigned i, const char **str); |
203 | | int bus_message_get_arg_strv(sd_bus_message *m, unsigned i, char ***strv); |
204 | | |
205 | | int bus_message_parse_fields(sd_bus_message *m); |
206 | | |
207 | | struct bus_body_part *message_append_part(sd_bus_message *m); |
208 | | |
209 | | #define MESSAGE_FOREACH_PART(part, i, m) \ |
210 | 0 | for ((i) = 0, (part) = &(m)->body; (i) < (m)->n_body_parts; (i)++, (part) = (part)->next) |
211 | | |
212 | | int bus_body_part_map(struct bus_body_part *part); |
213 | | void bus_body_part_unmap(struct bus_body_part *part); |
214 | | |
215 | | int bus_message_to_errno(sd_bus_message *m); |
216 | | |
217 | | int bus_message_new_synthetic_error(sd_bus *bus, uint64_t serial, const sd_bus_error *e, sd_bus_message **m); |
218 | | |
219 | | int bus_message_remarshal(sd_bus *bus, sd_bus_message **m); |
220 | | |
221 | | void bus_message_set_sender_driver(sd_bus *bus, sd_bus_message *m); |
222 | | void bus_message_set_sender_local(sd_bus *bus, sd_bus_message *m); |
223 | | |
224 | | sd_bus_message* bus_message_ref_queued(sd_bus_message *m, sd_bus *bus); |
225 | | sd_bus_message* bus_message_unref_queued(sd_bus_message *m, sd_bus *bus); |