gkdbus: allow payloads larger than 2M in signals 52/131352/5
authorAdrian Szyndela <adrian.s@samsung.com>
Fri, 26 May 2017 12:31:59 +0000 (14:31 +0200)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Thu, 1 Jun 2017 09:18:15 +0000 (09:18 +0000)
In kdbus signals can't use memfd - only vectors. There is
2M size limit for kdbus vectors. We divide message data
into GVariantVectors, but they were matched 1:1 to kdbus vectors
even if their size was larger than 2M.

This patch divides GVariantVectors larger than 2M into multiple
kdbus vectors when sending a message.

Change-Id: Ided2de80535cf039ea53bd1ab9d4d68c71b6c478

gio/gkdbus.c

index aa39359..5b4a909 100755 (executable)
@@ -72,6 +72,7 @@
 #define RECEIVE_POOL_SIZE_MIN_KBYTES      16
 
 #define KDBUS_MEMFD_THRESHOLD      (512 * 1024LU)
+#define KDBUS_MSG_MAX_PAYLOAD_VEC_SIZE  0x00200000      /* maximum size of message header and items */
 
 #define KDBUS_ALIGN8(l)            (((l) + 7) & ~7)
 #define KDBUS_ALIGN8_PTR(p)        ((void*) (uintptr_t)(p))
@@ -3066,12 +3067,17 @@ g_kdbus_msg_append_payload_vec (struct kdbus_msg  *msg,
                                 gconstpointer      data,
                                 gsize              size)
 {
-  struct kdbus_vec vec = {
-    .size = size,
-    .address = (gsize) data
-  };
-
-  return g_kdbus_msg_append_item (msg, KDBUS_ITEM_PAYLOAD_VEC, &vec, sizeof vec);
+  gboolean ok = TRUE;
+  do {
+    struct kdbus_vec vec = {
+      .size = size <= KDBUS_MSG_MAX_PAYLOAD_VEC_SIZE ? size : KDBUS_MSG_MAX_PAYLOAD_VEC_SIZE,
+      .address = (gsize) data
+    };
+    ok = g_kdbus_msg_append_item (msg, KDBUS_ITEM_PAYLOAD_VEC, &vec, sizeof vec);
+    data = (char*)data + vec.size;
+    size -= vec.size;
+  } while (size > 0 && ok);
+  return ok;
 }
 
 static gboolean