Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame^] | 1 | /* user_fixup.c: Fix up user copy faults. |
| 2 | * |
| 3 | * Copyright (C) 2004 David S. Miller <davem@redhat.com> |
| 4 | */ |
| 5 | |
| 6 | #include <linux/compiler.h> |
| 7 | #include <linux/kernel.h> |
| 8 | #include <linux/string.h> |
| 9 | #include <linux/errno.h> |
| 10 | #include <asm/uaccess.h> |
| 11 | |
| 12 | /* Calculating the exact fault address when using |
| 13 | * block loads and stores can be very complicated. |
| 14 | * Instead of trying to be clever and handling all |
| 15 | * of the cases, just fix things up simply here. |
| 16 | */ |
| 17 | |
| 18 | unsigned long copy_from_user_fixup(void *to, const void __user *from, unsigned long size) |
| 19 | { |
| 20 | char *dst = to; |
| 21 | const char __user *src = from; |
| 22 | |
| 23 | while (size) { |
| 24 | if (__get_user(*dst, src)) |
| 25 | break; |
| 26 | dst++; |
| 27 | src++; |
| 28 | size--; |
| 29 | } |
| 30 | |
| 31 | if (size) |
| 32 | memset(dst, 0, size); |
| 33 | |
| 34 | return size; |
| 35 | } |
| 36 | |
| 37 | unsigned long copy_to_user_fixup(void __user *to, const void *from, unsigned long size) |
| 38 | { |
| 39 | char __user *dst = to; |
| 40 | const char *src = from; |
| 41 | |
| 42 | while (size) { |
| 43 | if (__put_user(*src, dst)) |
| 44 | break; |
| 45 | dst++; |
| 46 | src++; |
| 47 | size--; |
| 48 | } |
| 49 | |
| 50 | return size; |
| 51 | } |
| 52 | |
| 53 | unsigned long copy_in_user_fixup(void __user *to, void __user *from, unsigned long size) |
| 54 | { |
| 55 | char __user *dst = to; |
| 56 | char __user *src = from; |
| 57 | |
| 58 | while (size) { |
| 59 | char tmp; |
| 60 | |
| 61 | if (__get_user(tmp, src)) |
| 62 | break; |
| 63 | if (__put_user(tmp, dst)) |
| 64 | break; |
| 65 | dst++; |
| 66 | src++; |
| 67 | size--; |
| 68 | } |
| 69 | |
| 70 | return size; |
| 71 | } |