1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-10 01:17:44 +03:00

bus: sync with kdbus-git (ABI break)

kdbus-git gained two new features:
 * memfd offsets: This allows to specify a 'start' offset in kdbus_memfd
                  so you can send partial memfd hunks instead of always
                  the full memfd
 * KDBUS_HELLO_UNPRIVILEGED: If passed during HELLO, the client will be
                             treated as unprivileged.
This commit is contained in:
David Herrmann 2014-12-09 11:12:41 +01:00
parent fbf7dcb588
commit 77adde6382
4 changed files with 18 additions and 10 deletions

View File

@ -78,7 +78,7 @@ static void append_payload_vec(struct kdbus_item **d, const void *p, size_t sz)
*d = (struct kdbus_item *) ((uint8_t*) *d + (*d)->size);
}
static void append_payload_memfd(struct kdbus_item **d, int memfd, size_t sz) {
static void append_payload_memfd(struct kdbus_item **d, int memfd, size_t start, size_t sz) {
assert(d);
assert(memfd >= 0);
assert(sz > 0);
@ -87,6 +87,7 @@ static void append_payload_memfd(struct kdbus_item **d, int memfd, size_t sz) {
(*d)->size = offsetof(struct kdbus_item, memfd) + sizeof(struct kdbus_memfd);
(*d)->type = KDBUS_ITEM_PAYLOAD_MEMFD;
(*d)->memfd.fd = memfd;
(*d)->memfd.start = start;
(*d)->memfd.size = sz;
*d = (struct kdbus_item *) ((uint8_t*) *d + (*d)->size);
@ -263,12 +264,10 @@ static int bus_message_setup_kmsg(sd_bus *b, sd_bus_message *m) {
sz = offsetof(struct kdbus_msg, items);
assert_cc(ALIGN8(offsetof(struct kdbus_item, vec) + sizeof(struct kdbus_vec)) ==
ALIGN8(offsetof(struct kdbus_item, memfd) + sizeof(struct kdbus_memfd)));
/* Add in fixed header, fields header and payload */
sz += (1 + m->n_body_parts) *
ALIGN8(offsetof(struct kdbus_item, vec) + sizeof(struct kdbus_vec));
sz += (1 + m->n_body_parts) * ALIGN8(offsetof(struct kdbus_item, vec) +
MAX(sizeof(struct kdbus_vec),
sizeof(struct kdbus_memfd)));
/* Add space for bloom filter */
sz += ALIGN8(offsetof(struct kdbus_item, bloom_filter) +
@ -343,7 +342,7 @@ static int bus_message_setup_kmsg(sd_bus *b, sd_bus_message *m) {
/* Try to send a memfd, if the part is
* sealed and this is not a broadcast. Since we can only */
append_payload_memfd(&d, part->memfd, part->size);
append_payload_memfd(&d, part->memfd, part->memfd_offset, part->size);
continue;
}
@ -544,6 +543,7 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
}
part->memfd = d->memfd.fd;
part->memfd_offset = d->memfd.start;
part->size = d->memfd.size;
part->sealed = true;

View File

@ -1126,7 +1126,7 @@ static int part_make_space(
psz = PAGE_ALIGN(sz > 0 ? sz : 1);
if (part->mapped <= 0)
n = mmap(NULL, psz, PROT_READ|PROT_WRITE, MAP_SHARED, part->memfd, 0);
n = mmap(NULL, psz, PROT_READ|PROT_WRITE, MAP_SHARED, part->memfd, part->memfd_offset);
else
n = mremap(part->data, part->mapped, psz, MREMAP_MAYMOVE);
@ -2620,6 +2620,7 @@ _public_ int sd_bus_message_append_array_memfd(sd_bus_message *m,
return -ENOMEM;
part->memfd = copy_fd;
part->memfd_offset = 0;
part->sealed = true;
part->size = size;
copy_fd = -1;
@ -2695,6 +2696,7 @@ _public_ int sd_bus_message_append_string_memfd(sd_bus_message *m, int memfd) {
return -ENOMEM;
part->memfd = copy_fd;
part->memfd_offset = 0;
part->sealed = true;
part->size = size;
copy_fd = -1;
@ -2878,7 +2880,7 @@ int bus_body_part_map(struct bus_body_part *part) {
psz = PAGE_ALIGN(part->size);
if (part->memfd >= 0)
p = mmap(NULL, psz, PROT_READ, MAP_PRIVATE, part->memfd, 0);
p = mmap(NULL, psz, PROT_READ, MAP_PRIVATE, part->memfd, part->memfd_offset);
else if (part->is_zero)
p = mmap(NULL, psz, PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
else

View File

@ -58,6 +58,7 @@ struct bus_body_part {
size_t size;
size_t mapped;
size_t allocated;
size_t memfd_offset;
int memfd;
bool free_this:1;
bool munmap_this:1;

View File

@ -183,7 +183,8 @@ struct kdbus_bloom_filter {
/**
* struct kdbus_memfd - a kdbus memfd
* @size: The memfd's size
* @start: The offset into the memfd where the segment starts
* @size: The size of the memfd segment
* @fd: The file descriptor number
* @__pad: Padding to ensure proper alignment and size
*
@ -191,6 +192,7 @@ struct kdbus_bloom_filter {
* KDBUS_ITEM_PAYLOAD_MEMFD
*/
struct kdbus_memfd {
__u64 start;
__u64 size;
int fd;
__u32 __pad;
@ -583,12 +585,15 @@ enum kdbus_policy_type {
* a service
* @KDBUS_HELLO_MONITOR: Special-purpose connection to monitor
* bus traffic
* @KDBUS_HELLO_UNPRIVILEGED: Don't treat this connection as privileged once
* the bus connection was established.
*/
enum kdbus_hello_flags {
KDBUS_HELLO_ACCEPT_FD = 1ULL << 0,
KDBUS_HELLO_ACTIVATOR = 1ULL << 1,
KDBUS_HELLO_POLICY_HOLDER = 1ULL << 2,
KDBUS_HELLO_MONITOR = 1ULL << 3,
KDBUS_HELLO_UNPRIVILEGED = 1ULL << 4,
};
/**