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>
21 #include <uapi/linux/kdbus.h>
23 /* all exported addresses are 64 bit */
24 #define KDBUS_PTR(addr) ((void __user *)(uintptr_t)(addr))
26 /* all exported sizes are 64 bit and data aligned to 64 bit */
27 #define KDBUS_ALIGN8(s) ALIGN((s), 8)
28 #define KDBUS_IS_ALIGNED8(s) (IS_ALIGNED(s, 8))
31 * kdbus_member_set_user - write a structure member to user memory
32 * @_s: Variable to copy from
33 * @_b: Buffer to write to
35 * @_m: Member name in the passed structure
37 * Return: the result of copy_to_user()
39 #define kdbus_member_set_user(_s, _b, _t, _m) \
42 (void __user *)((u8 __user *)(_b) + offsetof(_t, _m)); \
43 copy_to_user(_sz, _s, FIELD_SIZEOF(_t, _m)); \
47 * kdbus_strhash - calculate a hash
52 static inline unsigned int kdbus_strhash(const char *str)
54 unsigned long hash = init_name_hash();
57 hash = partial_name_hash(*str++, hash);
59 return end_name_hash(hash);
62 int kdbus_verify_uid_prefix(const char *name, struct user_namespace *user_ns,
64 int kdbus_sanitize_attach_flags(u64 flags, u64 *attach_flags);
66 int kdbus_copy_from_user(void *dest, void __user *user_ptr, size_t size);
70 void kdbus_kvec_set(struct kvec *kvec, void *src, size_t len, u64 *total_len);
71 size_t kdbus_kvec_pad(struct kvec *kvec, u64 *len);