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