···66#ifndef __UM_UACCESS_H77#define __UM_UACCESS_H8899-#include <asm/errno.h>1010-#include <asm/processor.h>1111-129/* thread_info has a mm_segment_t in it, so put the definition up here */1310typedef struct {1411 unsigned long seg;1512} mm_segment_t;16131717-#include "linux/thread_info.h"1414+#include <linux/thread_info.h>1515+#include <linux/errno.h>1616+#include <asm/processor.h>1717+#include <asm/elf.h>18181919#define VERIFY_READ 02020#define VERIFY_WRITE 1···38383939#define segment_eq(a, b) ((a).seg == (b).seg)40404141-#include "um_uaccess.h"4141+#define __under_task_size(addr, size) \4242+ (((unsigned long) (addr) < TASK_SIZE) && \4343+ (((unsigned long) (addr) + (size)) < TASK_SIZE))4444+4545+#define __access_ok_vsyscall(type, addr, size) \4646+ ((type == VERIFY_READ) && \4747+ ((unsigned long) (addr) >= FIXADDR_USER_START) && \4848+ ((unsigned long) (addr) + (size) <= FIXADDR_USER_END) && \4949+ ((unsigned long) (addr) + (size) >= (unsigned long)(addr)))5050+5151+#define __addr_range_nowrap(addr, size) \5252+ ((unsigned long) (addr) <= ((unsigned long) (addr) + (size)))5353+5454+#define access_ok(type, addr, size) \5555+ (__addr_range_nowrap(addr, size) && \5656+ (__under_task_size(addr, size) || \5757+ __access_ok_vsyscall(type, addr, size) || \5858+ segment_eq(get_fs(), KERNEL_DS)))5959+6060+extern int copy_from_user(void *to, const void __user *from, int n);6161+extern int copy_to_user(void __user *to, const void *from, int n);6262+6363+/*6464+ * strncpy_from_user: - Copy a NUL terminated string from userspace.6565+ * @dst: Destination address, in kernel space. This buffer must be at6666+ * least @count bytes long.6767+ * @src: Source address, in user space.6868+ * @count: Maximum number of bytes to copy, including the trailing NUL.6969+ *7070+ * Copies a NUL-terminated string from userspace to kernel space.7171+ *7272+ * On success, returns the length of the string (not including the trailing7373+ * NUL).7474+ *7575+ * If access to userspace fails, returns -EFAULT (some data may have been7676+ * copied).7777+ *7878+ * If @count is smaller than the length of the string, copies @count bytes7979+ * and returns @count.8080+ */8181+8282+extern int strncpy_from_user(char *dst, const char __user *src, int count);8383+8484+/*8585+ * __clear_user: - Zero a block of memory in user space, with less checking.8686+ * @to: Destination address, in user space.8787+ * @n: Number of bytes to zero.8888+ *8989+ * Zero a block of memory in user space. Caller must check9090+ * the specified block with access_ok() before calling this function.9191+ *9292+ * Returns number of bytes that could not be cleared.9393+ * On success, this will be zero.9494+ */9595+extern int __clear_user(void __user *mem, int len);9696+9797+/*9898+ * clear_user: - Zero a block of memory in user space.9999+ * @to: Destination address, in user space.100100+ * @n: Number of bytes to zero.101101+ *102102+ * Zero a block of memory in user space.103103+ *104104+ * Returns number of bytes that could not be cleared.105105+ * On success, this will be zero.106106+ */107107+extern int clear_user(void __user *mem, int len);108108+109109+/*110110+ * strlen_user: - Get the size of a string in user space.111111+ * @str: The string to measure.112112+ * @n: The maximum valid length113113+ *114114+ * Get the size of a NUL-terminated string in user space.115115+ *116116+ * Returns the size of the string INCLUDING the terminating NUL.117117+ * On exception, returns 0.118118+ * If the string is too long, returns a value greater than @n.119119+ */120120+extern int strnlen_user(const void __user *str, int len);4212143122#define __copy_from_user(to, from, n) copy_from_user(to, from, n)44123
-94
arch/um/include/shared/um_uaccess.h
···11-/* 22- * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)33- * Licensed under the GPL44- */55-66-#ifndef __ARCH_UM_UACCESS_H77-#define __ARCH_UM_UACCESS_H88-99-#include <asm/elf.h>1010-#include <asm/fixmap.h>1111-#include "sysdep/archsetjmp.h"1212-1313-#define __under_task_size(addr, size) \1414- (((unsigned long) (addr) < TASK_SIZE) && \1515- (((unsigned long) (addr) + (size)) < TASK_SIZE))1616-1717-#define __access_ok_vsyscall(type, addr, size) \1818- ((type == VERIFY_READ) && \1919- ((unsigned long) (addr) >= FIXADDR_USER_START) && \2020- ((unsigned long) (addr) + (size) <= FIXADDR_USER_END) && \2121- ((unsigned long) (addr) + (size) >= (unsigned long)(addr)))2222-2323-#define __addr_range_nowrap(addr, size) \2424- ((unsigned long) (addr) <= ((unsigned long) (addr) + (size)))2525-2626-#define access_ok(type, addr, size) \2727- (__addr_range_nowrap(addr, size) && \2828- (__under_task_size(addr, size) || \2929- __access_ok_vsyscall(type, addr, size) || \3030- segment_eq(get_fs(), KERNEL_DS)))3131-3232-extern int copy_from_user(void *to, const void __user *from, int n);3333-extern int copy_to_user(void __user *to, const void *from, int n);3434-3535-/*3636- * strncpy_from_user: - Copy a NUL terminated string from userspace.3737- * @dst: Destination address, in kernel space. This buffer must be at3838- * least @count bytes long.3939- * @src: Source address, in user space.4040- * @count: Maximum number of bytes to copy, including the trailing NUL.4141- *4242- * Copies a NUL-terminated string from userspace to kernel space.4343- *4444- * On success, returns the length of the string (not including the trailing4545- * NUL).4646- *4747- * If access to userspace fails, returns -EFAULT (some data may have been4848- * copied).4949- *5050- * If @count is smaller than the length of the string, copies @count bytes5151- * and returns @count.5252- */5353-5454-extern int strncpy_from_user(char *dst, const char __user *src, int count);5555-5656-/*5757- * __clear_user: - Zero a block of memory in user space, with less checking.5858- * @to: Destination address, in user space.5959- * @n: Number of bytes to zero.6060- *6161- * Zero a block of memory in user space. Caller must check6262- * the specified block with access_ok() before calling this function.6363- *6464- * Returns number of bytes that could not be cleared.6565- * On success, this will be zero.6666- */6767-extern int __clear_user(void __user *mem, int len);6868-6969-/*7070- * clear_user: - Zero a block of memory in user space.7171- * @to: Destination address, in user space.7272- * @n: Number of bytes to zero.7373- *7474- * Zero a block of memory in user space.7575- *7676- * Returns number of bytes that could not be cleared.7777- * On success, this will be zero.7878- */7979-extern int clear_user(void __user *mem, int len);8080-8181-/*8282- * strlen_user: - Get the size of a string in user space.8383- * @str: The string to measure.8484- * @n: The maximum valid length8585- *8686- * Get the size of a NUL-terminated string in user space.8787- *8888- * Returns the size of the string INCLUDING the terminating NUL.8989- * On exception, returns 0.9090- * If the string is too long, returns a value greater than @n.9191- */9292-extern int strnlen_user(const void __user *str, int len);9393-9494-#endif