summaryrefslogtreecommitdiff
path: root/buffer.h
diff options
context:
space:
mode:
authorKay Sievers <kay@vrfy.org>2013-05-02 21:48:04 +0200
committerKay Sievers <kay@vrfy.org>2013-05-08 00:00:17 +0200
commit111fb9ed7d88e76942fe0f5c146333b1b1e6cbe2 (patch)
treeb879202f0c4110991d26c1cd0e83b9ab7bb83043 /buffer.h
parent1c1a20cd7f3f610762934dbbc602b0e8edf47da7 (diff)
downloadkdbus-bus-111fb9ed7d88e76942fe0f5c146333b1b1e6cbe2.tar.gz
kdbus-bus-111fb9ed7d88e76942fe0f5c146333b1b1e6cbe2.tar.bz2
kdbus-bus-111fb9ed7d88e76942fe0f5c146333b1b1e6cbe2.zip
copy messages directly from sender into a receiver-supplied buffer
Require the receiver to pre-allocate a buffer and register it with HELLO. The sender will copy its data directly into the revceiver's buffer. The RECV call will now only return a pointer to the next message in the buffer. The buffer needs to be free()d with the FREE ioctl. FIXME: currently missing is a proper allocator to manage the receiver's buffer, in the current state the allocator will only clear the buffer if all messages are free()d. This is obviously only useful for testing.
Diffstat (limited to 'buffer.h')
-rw-r--r--buffer.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/buffer.h b/buffer.h
new file mode 100644
index 00000000000..0cdb065d870
--- /dev/null
+++ b/buffer.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2013 Kay Sievers
+ * Copyright (C) 2013 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+ * Copyright (C) 2013 Linux Foundation
+ * Copyright (C) 2013 Daniel Mack <daniel@zonque.org>
+ *
+ * kdbus is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ */
+
+#ifndef __KDBUS_BUFFER_H
+#define __KDBUS_BUFFER_H
+
+/*
+ * At KDBUS_CMD_MSG_SEND, messages are placed direcly into the buffer the
+ * receiver has registered with KDBUS_HELLO_BUFFER.
+ *
+ * To receive a message, KDBUS_CMD_MSG_RECV is called, which returns a pointer
+ * into the buffer.
+ *
+ * The internally allocated memory needs to be freed by the receiver with
+ * KDBUS_CMD_MSG_FREE.
+ */
+struct kdbus_buffer {
+ void __user *buf; /* receiver-supplied buffer */
+ size_t size; /* size of buffer */
+ size_t pos; /* current write position */
+ unsigned int users;
+};
+
+/*
+ * Structure to keep the state of a mapped range on the buffer while
+ * writing chunks of data to it from the sender.
+ */
+struct kdbus_buffer_map {
+ struct page **pages; /* array of pages representign the buffer */
+ unsigned int n; /* number pf pages in the array */
+ unsigned long cur; /* current page we write to */
+ unsigned long pos; /* position in current page we write to */
+};
+
+struct kdbus_msg __user *kdbus_buffer_alloc(struct kdbus_buffer *buf, size_t len);
+void kdbus_buffer_free(struct kdbus_buffer *buf, struct kdbus_msg __user *msg);
+void kdbus_buffer_map_close(struct kdbus_buffer *buf);
+int kdbus_buffer_map_open(struct kdbus_buffer *buf,
+ struct task_struct *task,
+ void __user *to, size_t len);
+int kdbus_buffer_map_write(struct kdbus_buffer *buf,
+ void __user *from, size_t len);
+#endif