kdbus: the driver, original and non-working
[platform/kernel/linux-exynos.git] / ipc / kdbus / util.h
1 /*
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>
8  *
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.
13  */
14
15 #ifndef __KDBUS_UTIL_H
16 #define __KDBUS_UTIL_H
17
18 #include <linux/dcache.h>
19 #include <linux/ioctl.h>
20
21 #include <uapi/linux/kdbus.h>
22
23 /* all exported addresses are 64 bit */
24 #define KDBUS_PTR(addr) ((void __user *)(uintptr_t)(addr))
25
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))
29
30 /**
31  * kdbus_member_set_user - write a structure member to user memory
32  * @_s:         Variable to copy from
33  * @_b:         Buffer to write to
34  * @_t:         Structure type
35  * @_m:         Member name in the passed structure
36  *
37  * Return: the result of copy_to_user()
38  */
39 #define kdbus_member_set_user(_s, _b, _t, _m)                           \
40 ({                                                                      \
41         u64 __user *_sz =                                               \
42                 (void __user *)((u8 __user *)(_b) + offsetof(_t, _m));  \
43         copy_to_user(_sz, _s, FIELD_SIZEOF(_t, _m));                    \
44 })
45
46 /**
47  * kdbus_strhash - calculate a hash
48  * @str:        String
49  *
50  * Return: hash value
51  */
52 static inline unsigned int kdbus_strhash(const char *str)
53 {
54         unsigned long hash = init_name_hash();
55
56         while (*str)
57                 hash = partial_name_hash(*str++, hash);
58
59         return end_name_hash(hash);
60 }
61
62 int kdbus_verify_uid_prefix(const char *name, struct user_namespace *user_ns,
63                             kuid_t kuid);
64 int kdbus_sanitize_attach_flags(u64 flags, u64 *attach_flags);
65
66 int kdbus_copy_from_user(void *dest, void __user *user_ptr, size_t size);
67
68 struct kvec;
69
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);
72
73 #endif