bus-kernel.h revision 52cfc0379a9d63f99cdb3d9f63c839bbc8889b4c
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering#pragma once
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering/***
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering This file is part of systemd.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Copyright 2013 Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering systemd is free software; you can redistribute it and/or modify it
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering under the terms of the GNU Lesser General Public License as published by
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering (at your option) any later version.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering systemd is distributed in the hope that it will be useful, but
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Lesser General Public License for more details.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering You should have received a copy of the GNU Lesser General Public License
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering***/
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering#include <stdbool.h>
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering#include "busname.h"
9b420b3cfb8b93daf50e4cdbc92b05f2209ef893Lennart Poettering#include "bus-endpoint.h"
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering#include "sd-bus.h"
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering#define KDBUS_ITEM_NEXT(item) \
96aad8d15a324d0e956a4e5653a11a67b209b41aLennart Poettering (typeof(item))(((uint8_t *)item) + ALIGN8((item)->size))
23c80348e656a4e6fd9ba8f17523a65b6fa349a0Kay Sievers
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering#define KDBUS_ITEM_FOREACH(part, head, first) \
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering for (part = (head)->first; \
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering ((uint8_t *)(part) < (uint8_t *)(head) + (head)->size) && \
003dffde2c1b93afbc9aff24b277276f65424406Lennart Poettering ((uint8_t *) part >= (uint8_t *) head); \
4cee5eede280b7fd48c18a1942616c4ac896a554Lennart Poettering part = KDBUS_ITEM_NEXT(part))
003dffde2c1b93afbc9aff24b277276f65424406Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering#define KDBUS_ITEM_HEADER_SIZE offsetof(struct kdbus_item, data)
003dffde2c1b93afbc9aff24b277276f65424406Lennart Poettering#define KDBUS_ITEM_SIZE(s) ALIGN8((s) + KDBUS_ITEM_HEADER_SIZE)
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering#define MEMFD_CACHE_MAX 32
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering/* When we cache a memfd block for reuse, we will truncate blocks
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering * longer than this in order not to keep too much data around. */
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering#define MEMFD_CACHE_ITEM_SIZE_MAX (128*1024)
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering/* This determines at which minimum size we prefer sending memfds over
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering * sending vectors */
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering#define MEMFD_MIN_SIZE (512*1024)
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering/* The size of the per-connection memory pool that we set up and where
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering * the kernel places our incoming messages */
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering#define KDBUS_POOL_SIZE (16*1024*1024)
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poetteringstruct memfd_cache {
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering int fd;
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering void *address;
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering size_t mapped;
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering size_t allocated;
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering};
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poetteringint bus_kernel_connect(sd_bus *b);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poetteringint bus_kernel_take_fd(sd_bus *b);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poetteringint bus_kernel_write_message(sd_bus *bus, sd_bus_message *m, bool hint_sync_call);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poetteringint bus_kernel_read_message(sd_bus *bus, bool hint_priority, int64_t priority);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poetteringint bus_kernel_open_bus_fd(const char *bus, char **path);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poetteringint bus_kernel_make_starter(int fd, const char *name, bool activating, bool accept_fd, BusNamePolicy *policy, BusPolicyAccess world_policy);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poetteringint bus_kernel_create_bus(const char *name, bool world, char **s);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poetteringint bus_kernel_create_endpoint(const char *bus_name, const char *ep_name, char **path);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poetteringint bus_kernel_set_endpoint_policy(int fd, uid_t uid, BusEndpoint *ep);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poetteringint bus_kernel_pop_memfd(sd_bus *bus, void **address, size_t *mapped, size_t *allocated);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poetteringvoid bus_kernel_push_memfd(sd_bus *bus, int fd, void *address, size_t mapped, size_t allocated);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poetteringvoid bus_kernel_flush_memfd(sd_bus *bus);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
cb81cd8073392936882643af0129934bf67e96c4Lennart Poetteringint bus_kernel_parse_unique_name(const char *s, uint64_t *id);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poetteringuint64_t request_name_flags_to_kdbus(uint64_t sd_bus_flags);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poetteringuint64_t attach_flags_to_kdbus(uint64_t sd_bus_flags);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poetteringint bus_kernel_try_close(sd_bus *bus);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poetteringint bus_kernel_drop_one(int fd);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poetteringint bus_kernel_realize_attach_flags(sd_bus *bus);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poetteringint bus_kernel_fix_attach_mask(void);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poetteringint bus_kernel_cmd_free(sd_bus *bus, uint64_t offset);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering