blob: 17d18cfd82a51fb46b7a6864c244d077a4ccfe21 [file] [log] [blame]
Alex Dewarf2f4bf52019-08-25 10:49:19 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
Richard Weinbergerf8d65d22015-05-12 00:17:28 +02004 * Copyright (C) 2015 Richard Weinberger (richard@nod.at)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
6
7#ifndef __UM_UACCESS_H
8#define __UM_UACCESS_H
9
Al Virofced95c2011-08-18 20:08:49 +010010#include <asm/elf.h>
Christoph Hellwig8bb227a2021-12-15 17:56:12 +010011#include <asm/unaligned.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
Al Virofced95c2011-08-18 20:08:49 +010013#define __under_task_size(addr, size) \
14 (((unsigned long) (addr) < TASK_SIZE) && \
15 (((unsigned long) (addr) + (size)) < TASK_SIZE))
16
Richard Weinbergerf8d65d22015-05-12 00:17:28 +020017#define __access_ok_vsyscall(addr, size) \
18 (((unsigned long) (addr) >= FIXADDR_USER_START) && \
Al Virofced95c2011-08-18 20:08:49 +010019 ((unsigned long) (addr) + (size) <= FIXADDR_USER_END) && \
20 ((unsigned long) (addr) + (size) >= (unsigned long)(addr)))
21
22#define __addr_range_nowrap(addr, size) \
23 ((unsigned long) (addr) <= ((unsigned long) (addr) + (size)))
24
Al Viroa668ce32017-03-28 01:33:09 -040025extern unsigned long raw_copy_from_user(void *to, const void __user *from, unsigned long n);
26extern unsigned long raw_copy_to_user(void __user *to, const void *from, unsigned long n);
Richard Weinbergerf8d65d22015-05-12 00:17:28 +020027extern unsigned long __clear_user(void __user *mem, unsigned long len);
28static inline int __access_ok(unsigned long addr, unsigned long size);
Al Virofced95c2011-08-18 20:08:49 +010029
Richard Weinbergerf8d65d22015-05-12 00:17:28 +020030/* Teach asm-generic/uaccess.h that we have C functions for these. */
31#define __access_ok __access_ok
32#define __clear_user __clear_user
Arnd Bergmann166ec462020-01-17 17:26:54 +010033
Al Viroa668ce32017-03-28 01:33:09 -040034#define INLINE_COPY_FROM_USER
35#define INLINE_COPY_TO_USER
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Richard Weinbergerf8d65d22015-05-12 00:17:28 +020037#include <asm-generic/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Richard Weinbergerf8d65d22015-05-12 00:17:28 +020039static inline int __access_ok(unsigned long addr, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070040{
Richard Weinbergerf8d65d22015-05-12 00:17:28 +020041 return __addr_range_nowrap(addr, size) &&
42 (__under_task_size(addr, size) ||
Christoph Hellwig8bb227a2021-12-15 17:56:12 +010043 __access_ok_vsyscall(addr, size));
Richard Weinbergerf8d65d22015-05-12 00:17:28 +020044}
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Christoph Hellwig8bb227a2021-12-15 17:56:12 +010046/* no pagefaults for kernel addresses in um */
47#define HAVE_GET_KERNEL_NOFAULT 1
48
49#define __get_kernel_nofault(dst, src, type, err_label) \
50do { \
51 *((type *)dst) = get_unaligned((type *)(src)); \
52 if (0) /* make sure the label looks used to the compiler */ \
53 goto err_label; \
54} while (0)
55
56#define __put_kernel_nofault(dst, src, type, err_label) \
57do { \
58 put_unaligned(*((type *)src), (type *)(dst)); \
59 if (0) /* make sure the label looks used to the compiler */ \
60 goto err_label; \
61} while (0)
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#endif