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
8 * kdbus is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU Lesser General Public License as published by the
10 * Free Software Foundation; either version 2.1 of the License, or (at
11 * your option) any later version.
14 #ifndef __KDBUS_HANDLE_H
15 #define __KDBUS_HANDLE_H
18 #include <uapi/linux/kdbus.h>
20 extern const struct file_operations kdbus_handle_ops;
23 * kdbus_arg - information and state of a single ioctl command item
25 * @item: set by the parser to the first found item of this type
26 * @multiple: whether multiple items of this type are allowed
27 * @mandatory: whether at least one item of this type is required
29 * This structure describes a single item in an ioctl command payload. The
30 * caller has to pre-fill the type and flags, the parser will then use this
31 * information to verify the ioctl payload. @item is set by the parser to point
32 * to the first occurrence of the item.
36 struct kdbus_item *item;
42 * kdbus_args - information and state of ioctl command parser
43 * @allowed_flags: set of flags this command supports
44 * @argc: number of items in @argv
45 * @argv: array of items this command supports
46 * @user: set by parser to user-space location of current command
47 * @cmd: set by parser to kernel copy of command payload
48 * @cmd_buf: inline buf to avoid kmalloc() on small cmds
49 * @items: points to item array in @cmd
50 * @items_size: size of @items in bytes
51 * @is_cmd: whether this is a command-payload or msg-payload
53 * This structure is used to parse ioctl command payloads on each invocation.
54 * The ioctl handler has to pre-fill the flags and allowed items before passing
55 * the object to kdbus_args_parse(). The parser will copy the command payload
56 * into kernel-space and verify the correctness of the data.
58 * We use a 256 bytes buffer for small command payloads, to be allocated on
59 * stack on syscall entrance.
64 struct kdbus_arg *argv;
66 struct kdbus_cmd __user *user;
67 struct kdbus_cmd *cmd;
70 struct kdbus_item *items;
75 int __kdbus_args_parse(struct kdbus_args *args, bool is_cmd, void __user *argp,
76 size_t type_size, size_t items_offset, void **out);
77 int kdbus_args_clear(struct kdbus_args *args, int ret);
79 #define kdbus_args_parse(_args, _argp, _v) \
81 BUILD_BUG_ON(offsetof(typeof(**(_v)), size) != \
82 offsetof(struct kdbus_cmd, size)); \
83 BUILD_BUG_ON(offsetof(typeof(**(_v)), flags) != \
84 offsetof(struct kdbus_cmd, flags)); \
85 BUILD_BUG_ON(offsetof(typeof(**(_v)), return_flags) != \
86 offsetof(struct kdbus_cmd, return_flags)); \
87 __kdbus_args_parse((_args), 1, (_argp), sizeof(**(_v)), \
88 offsetof(typeof(**(_v)), items), \
92 #define kdbus_args_parse_msg(_args, _argp, _v) \
94 BUILD_BUG_ON(offsetof(typeof(**(_v)), size) != \
95 offsetof(struct kdbus_cmd, size)); \
96 BUILD_BUG_ON(offsetof(typeof(**(_v)), flags) != \
97 offsetof(struct kdbus_cmd, flags)); \
98 __kdbus_args_parse((_args), 0, (_argp), sizeof(**(_v)), \
99 offsetof(typeof(**(_v)), items), \