chiark / gitweb /
bus-kernel: move bus_kernel_make_message
[elogind.git] / src / libsystemd / bus-kernel.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #pragma once
4
5 /***
6   This file is part of systemd.
7
8   Copyright 2013 Lennart Poettering
9
10   systemd is free software; you can redistribute it and/or modify it
11   under the terms of the GNU Lesser General Public License as published by
12   the Free Software Foundation; either version 2.1 of the License, or
13   (at your option) any later version.
14
15   systemd is distributed in the hope that it will be useful, but
16   WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18   Lesser General Public License for more details.
19
20   You should have received a copy of the GNU Lesser General Public License
21   along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
24 #include <stdbool.h>
25
26 #include "sd-bus.h"
27
28 #define KDBUS_ITEM_NEXT(item) \
29         (typeof(item))(((uint8_t *)item) + ALIGN8((item)->size))
30
31 #define KDBUS_ITEM_FOREACH(part, head, first)                           \
32         for (part = (head)->first;                                      \
33              (uint8_t *)(part) < (uint8_t *)(head) + (head)->size;      \
34              part = KDBUS_ITEM_NEXT(part))
35
36 #define KDBUS_ITEM_HEADER_SIZE offsetof(struct kdbus_item, data)
37 #define KDBUS_ITEM_SIZE(s) ALIGN8((s) + KDBUS_ITEM_HEADER_SIZE)
38
39 #define MEMFD_CACHE_MAX 32
40
41 /* When we cache a memfd block for reuse, we will truncate blocks
42  * longer than this in order not to keep too much data around. */
43 #define MEMFD_CACHE_ITEM_SIZE_MAX (128*1024)
44
45 /* This determines at which minimum size we prefer sending memfds over
46  * sending vectors */
47 #define MEMFD_MIN_SIZE (128*1024)
48
49 /* The size of the per-connection memory pool that we set up and where
50  * the kernel places our incoming messages */
51 #define KDBUS_POOL_SIZE (16*1024*1024)
52
53 struct memfd_cache {
54         int fd;
55         void *address;
56         size_t mapped;
57         size_t allocated;
58 };
59
60 int bus_kernel_connect(sd_bus *b);
61 int bus_kernel_take_fd(sd_bus *b);
62
63 int bus_kernel_write_message(sd_bus *bus, sd_bus_message *m);
64 int bus_kernel_read_message(sd_bus *bus);
65
66 int bus_kernel_create_bus(const char *name, bool world, char **s);
67 int bus_kernel_create_namespace(const char *name, char **s);
68 int bus_kernel_create_starter(const char *bus, const char *name);
69 int bus_kernel_create_monitor(const char *bus);
70
71 int bus_kernel_pop_memfd(sd_bus *bus, void **address, size_t *mapped, size_t *allocated);
72 void bus_kernel_push_memfd(sd_bus *bus, int fd, void *address, size_t mapped, size_t allocated);
73
74 void bus_kernel_flush_memfd(sd_bus *bus);
75
76 int bus_kernel_parse_unique_name(const char *s, uint64_t *id);
77
78 int kdbus_translate_request_name_flags(uint64_t sd_bus_flags, uint64_t *kdbus_flags);
79 int kdbus_translate_attach_flags(uint64_t sd_bus_flags, uint64_t *kdbus_flags);
80
81 int bus_kernel_try_close(sd_bus *bus);