2 * Copyright (C) 2013-2015 Kay Sievers
3 * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
4 * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org>
5 * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com>
6 * Copyright (C) 2013-2015 Linux Foundation
7 * Copyright (C) 2014-2015 Djalal Harouni <tixxdz@opendz.org>
9 * kdbus is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU Lesser General Public License as published by the
11 * Free Software Foundation; either version 2.1 of the License, or (at
12 * your option) any later version.
15 #ifndef __KDBUS_ITEM_H
16 #define __KDBUS_ITEM_H
18 #include <linux/kernel.h>
19 #include <uapi/linux/kdbus.h>
23 /* generic access and iterators over a stream of items */
24 #define KDBUS_ITEM_NEXT(_i) (typeof(_i))((u8 *)(_i) + KDBUS_ALIGN8((_i)->size))
25 #define KDBUS_ITEMS_SIZE(_h, _is) ((_h)->size - offsetof(typeof(*(_h)), _is))
26 #define KDBUS_ITEM_HEADER_SIZE offsetof(struct kdbus_item, data)
27 #define KDBUS_ITEM_SIZE(_s) KDBUS_ALIGN8(KDBUS_ITEM_HEADER_SIZE + (_s))
28 #define KDBUS_ITEM_PAYLOAD_SIZE(_i) ((_i)->size - KDBUS_ITEM_HEADER_SIZE)
30 #define KDBUS_ITEMS_FOREACH(_i, _is, _s) \
32 ((u8 *)(_i) < (u8 *)(_is) + (_s)) && \
33 ((u8 *)(_i) >= (u8 *)(_is)); \
34 (_i) = KDBUS_ITEM_NEXT(_i))
36 #define KDBUS_ITEM_VALID(_i, _is, _s) \
37 ((_i)->size >= KDBUS_ITEM_HEADER_SIZE && \
38 (u8 *)(_i) + (_i)->size > (u8 *)(_i) && \
39 (u8 *)(_i) + (_i)->size <= (u8 *)(_is) + (_s) && \
40 (u8 *)(_i) >= (u8 *)(_is))
42 #define KDBUS_ITEMS_END(_i, _is, _s) \
43 ((u8 *)(_i) == ((u8 *)(_is) + KDBUS_ALIGN8(_s)))
46 * struct kdbus_item_header - Describes the fix part of an item
47 * @size: The total size of the item
48 * @type: The item type, one of KDBUS_ITEM_*
50 struct kdbus_item_header {
55 int kdbus_item_validate_name(const struct kdbus_item *item);
56 int kdbus_item_validate(const struct kdbus_item *item);
57 int kdbus_items_validate(const struct kdbus_item *items, size_t items_size);
58 struct kdbus_item *kdbus_item_set(struct kdbus_item *item, u64 type,
59 const void *data, size_t len);