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