chiark / gitweb /
bus: sync with kdbus-git (ABI break)
authorDavid Herrmann <dh.herrmann@gmail.com>
Tue, 9 Dec 2014 10:12:41 +0000 (11:12 +0100)
committerDavid Herrmann <dh.herrmann@gmail.com>
Tue, 9 Dec 2014 10:14:55 +0000 (11:14 +0100)
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.

src/libsystemd/sd-bus/bus-kernel.c
src/libsystemd/sd-bus/bus-message.c
src/libsystemd/sd-bus/bus-message.h
src/libsystemd/sd-bus/kdbus.h

index 3a809e4aa625aff5f5bdcce5c89315b24046dd3b..98fd4fd3ec60a72841ab70c17fa3bac948eb1524 100644 (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;
 
index ec3a39d051c82629ed3d945c5965204d13d098d3..ad417c0f100bc6d6f209d5018f109f3ec55d2df6 100644 (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
index 571d42255c705192aff29732438aa4483d03e875..db5f90c5de226341e7d5b7ecab1d48099e8f643c 100644 (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;
index 7137fc9989294db37c9a3a3005641271acf4fd11..2bfd0f98e6bf70baba56e8079fcae0674e534962 100644 (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,
 };
 
 /**