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_UTIL_H
16 #define __KDBUS_UTIL_H
18 #include <linux/dcache.h>
19 #include <linux/ioctl.h>
20 #include <linux/stddef.h>
22 #include <uapi/linux/kdbus.h>
24 /* all exported addresses are 64 bit */
25 #define KDBUS_PTR(addr) ((void __user *)(uintptr_t)(addr))
27 /* all exported sizes are 64 bit and data aligned to 64 bit */
28 #define KDBUS_ALIGN8(s) ALIGN((s), 8)
29 #define KDBUS_IS_ALIGNED8(s) (IS_ALIGNED(s, 8))
32 * kdbus_member_set_user - write a structure member to user memory
33 * @_s: Variable to copy from
34 * @_b: Buffer to write to
36 * @_m: Member name in the passed structure
38 * Return: the result of copy_to_user()
40 #define kdbus_member_set_user(_s, _b, _t, _m) \
43 (void __user *)((u8 __user *)(_b) + offsetof(_t, _m)); \
44 copy_to_user(_sz, _s, sizeof_field(_t, _m)); \
48 * kdbus_strhash - calculate a hash
53 static inline unsigned int kdbus_strhash(const char *str)
55 unsigned long hash = init_name_hash(0);
58 hash = partial_name_hash(*str++, hash);
60 return end_name_hash(hash);
63 int kdbus_verify_uid_prefix(const char *name, struct user_namespace *user_ns,
65 int kdbus_sanitize_attach_flags(u64 flags, u64 *attach_flags);
67 int kdbus_copy_from_user(void *dest, void __user *user_ptr, size_t size);
71 void kdbus_kvec_set(struct kvec *kvec, void *src, size_t len, u64 *total_len);
72 size_t kdbus_kvec_pad(struct kvec *kvec, u64 *len);