blob: 191ef36dd5439182af8c486cefee015fd8918b5d [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Al Virofced95c2011-08-18 20:08:49 +010012#define __under_task_size(addr, size) \
13 (((unsigned long) (addr) < TASK_SIZE) && \
14 (((unsigned long) (addr) + (size)) < TASK_SIZE))
15
Richard Weinbergerf8d65d22015-05-12 00:17:28 +020016#define __access_ok_vsyscall(addr, size) \
17 (((unsigned long) (addr) >= FIXADDR_USER_START) && \
Al Virofced95c2011-08-18 20:08:49 +010018 ((unsigned long) (addr) + (size) <= FIXADDR_USER_END) && \
19 ((unsigned long) (addr) + (size) >= (unsigned long)(addr)))
20
21#define __addr_range_nowrap(addr, size) \
22 ((unsigned long) (addr) <= ((unsigned long) (addr) + (size)))
23
Al Viroa668ce32017-03-28 01:33:09 -040024extern unsigned long raw_copy_from_user(void *to, const void __user *from, unsigned long n);
25extern unsigned long raw_copy_to_user(void __user *to, const void *from, unsigned long n);
Richard Weinbergerf8d65d22015-05-12 00:17:28 +020026extern unsigned long __clear_user(void __user *mem, unsigned long len);
27static inline int __access_ok(unsigned long addr, unsigned long size);
Al Virofced95c2011-08-18 20:08:49 +010028
Richard Weinbergerf8d65d22015-05-12 00:17:28 +020029/* Teach asm-generic/uaccess.h that we have C functions for these. */
30#define __access_ok __access_ok
31#define __clear_user __clear_user
Arnd Bergmann166ec462020-01-17 17:26:54 +010032
Al Viroa668ce32017-03-28 01:33:09 -040033#define INLINE_COPY_FROM_USER
34#define INLINE_COPY_TO_USER
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Richard Weinbergerf8d65d22015-05-12 00:17:28 +020036#include <asm-generic/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Richard Weinbergerf8d65d22015-05-12 00:17:28 +020038static inline int __access_ok(unsigned long addr, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039{
Richard Weinbergerf8d65d22015-05-12 00:17:28 +020040 return __addr_range_nowrap(addr, size) &&
41 (__under_task_size(addr, size) ||
42 __access_ok_vsyscall(addr, size) ||
Al Virodb68ce12017-03-20 21:08:07 -040043 uaccess_kernel());
Richard Weinbergerf8d65d22015-05-12 00:17:28 +020044}
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46#endif