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